Cert-Manager 证书申请

目前腾讯云 EKS 安装 cert-manager 和 alidns webhook 过程中会报错,只能使用 TKE

0. 准备工作

  • 创建集群

1. 安装 cert-manager

1
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.3.0/cert-manager.yaml

如果不能访问 github,则可以先下载文件到本地

2. 安装 alidns-webhook

1
kubectl apply -f https://raw.githubusercontent.com/pragkent/alidns-webhook/master/deploy/bundle.yaml

如果不能访问 github,则可以先下载文件到本地,此步不能太快,需确保第1步安装 cert-manager 时,所有的 pod 都已经正常运行后,再安装 webhook,不然无法成功;当出现失败时,可删除整个 webhook deployment,再重新创建

3. 创建访问 AliDNS 解析用的账号密码

1
2
3
4
5
6
7
8
apiVersion: v1
kind: Secret
metadata:
name: alidns-secret
namespace: cert-manager
data: # 如果用 stringData,则下面两个属性就不需要编码
access-key: YOUR_ID # 需 base64 转码
secret-key: YOUR_KEY # 需 base64 转码

注:此处的 ID 和 KEY 需要先进行 base64 转码,除非将 data 字段改成 stringData

4. 创建 ClusterIssuer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
apiVersion: cert-manager.io/v1alpha2
kind: ClusterIssuer
metadata:
name: letsencrypt
spec:
acme:
email: YOUR_EMAIL # Change to your letsencrypt email
server: https://acme-v02.api.letsencrypt.org/directory
privateKeySecretRef:
name: letsencrypt-account-key
solvers:
- dns01:
webhook:
groupName: acme.yourcompany.com
solverName: alidns
config:
region: ""
accessKeySecretRef:
name: alidns-secret
key: access-key
secretKeySecretRef:
name: alidns-secret
key: secret-key

5. 创建证书

1
2
3
4
5
6
7
8
9
10
11
apiVersion: cert-manager.io/v1alpha2
kind: Certificate
metadata:
name: YOUR_CERT_NAME # 证书名,供 pod 引用
spec:
secretName: www-example-com-tls # 最终签发出来的证书会保存在这个 Secret 里面
dnsNames:
- www.example.com # 待签发证书的域名
issuerRef:
name: letsencrypt
kind: ClusterIssuer

如果创建过程中出现错误,可以使用 kubectl describe <资源类型> < 资源名称> ,根据显示的消息,进行错误排查,例如:

kubectl desribe certificate example

kubectl describe ClusterIssuer example

详细排查办法查看以下链接:https://cert-manager.io/docs/faq/acme/


Cert-Manager 证书申请
https://ccw1078.github.io/2021/07/20/Cert-Manager 证书申请/
作者
ccw
发布于
2021年7月20日
许可协议