重要
生成自签发证书
- 生成CA根证书以及根证书私钥.
output: ca.crt
和 ca.key
, pem格式. input ''
1
2
3
4
5
| # Generate a CA private key
openssl genrsa -out ca.key 4096
# Create a self signed Certificate, valid for 10yrs with the 'signing' option set
openssl req -x509 -new -nodes -key ca.key -subj "/CN=company.COM" -days 3650 -reqexts v3_req -extensions v3_ca -out ca.crt
|
- 生成
*.example.domain
通配符证书私钥
output: example.domain.key
, pem格式. input: ''
1
| openssl genrsa -out example.domain.key 4096
|
- 根据
*.example.domain
通配符证书私钥,生成证书请求文件(csr)example.domain.csr
output: example.domain.csr
, pem格式. input: example.domain.key
.
1
| openssl req -new -sha256 -key example.domain.key -out example.domain.csr -subj "/CN=svc.example.domain"
|
- 根据证书请求文件通过根证书、根证书私钥签发证书。
output: example.domain.crt
, pem格式. input: example.domain.csr
和ca.crt
和ca.key
以及配置文件example.domain.ini
.
其中,配置文件example.domain.ini
的内容如下:
1
2
3
4
5
| [ ext ]
subjectAltName = @dns
[ dns ]
DNS.1 = *.example.domain
|
执行下面命令:
1
| openssl x509 -req -in example.domain.csr -CA ca.crt -CAkey ca.key -CAcreateserial -days 3560 -out example.domain.crt -extfile example.domain.ini -extensions ext
|
- 生成k8s中的secret.
output: k8s-secret example-certs
, pem格式. input: example.domain.crt
和 example.domain.key
pem格式.
1
| kubectl create secret tls example-certs --cert=example.domain.crt --key=example.domain.key
|
Reference
概念说明
生成证书