介绍
安装k8s集群时,kubelet组件默认是1年,如果到期,需要手动更新该证书,1.8版本之后也可配置自动更新。
手动更新
删除原证书
1 2
| rm -f kubelet-client-current.pem kubelet-client-2019-05-10-09-57-21.pem kubelet.key kubelet.crt
|
重启kubelet
1
| systemctl restart kubelet && systemctl status kubelet
|
查看csr证书请求
手动签发
1
| kubectl certificate approve node-csr--k3G2G1EoM4h9w1FuJRjJjfbIPNxa551A8TZfW9dG-g
|
验证
1 2
| kubectl get csr kubectl get nodes
|
自动更新
添加kubelet组件参数,也就是启动时的参数:
重启服务
1 2
| systemctl restart kubelet systemctl status kubelet
|
添加kube-controller-manager组件参数,也就是启动时的参数:
1 2
| --feature-gates=RotateKubeletServerCertificate=true
|
重启服务
1 2
| systemctl restart kube-controller-manager systemctl status kube-controller-manager
|
创建自动批准相关 CSR 请求的 ClusterRole
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| cat >> tls-instructs-csr.yaml << EOF kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: name: system:certificates.k8s.io:certificatesigningrequests:selfnodeserver rules: - apiGroups: ["certificates.k8s.io"] resources: ["certificatesigningrequests/selfnodeserver"] verbs: ["create"] EOF
kubectl apply -f tls-instructs-csr.yaml
kubectl create clusterrolebinding node-client-auto-approve-csr --clusterrole=system:certificates.k8s.io:certificatesigningrequests:nodeclient --user=kubelet-bootstrap
kubectl create clusterrolebinding node-client-auto-renew-crt --clusterrole=system:certificates.k8s.io:certificatesigningrequests:selfnodeclient --group=system:nodes
kubectl create clusterrolebinding node-server-auto-renew-crt --clusterrole=system:certificates.k8s.io:certificatesigningrequests:selfnodeserver --group=system:nodes
|
重启docker
1 2
| systemctl daemon-reload systemctl status kube-controller-manager
|
测试
1 2 3 4 5 6 7 8
| rm -f kubelet-client-current.pem kubelet-client-2019-05-10-09-57-21.pem kubelet.key kubelet.crt
systemctl restart kubelet
openssl x509 -in kubelet-client-current.pem -noout -text | grep "Not"
|
kubeadm证书续签
1 2 3 4 5 6
| kubeadm alpha certs check-expiration
kubeadm alpha certs renew all
docker ps |grep -E 'k8s_kube-apiserver|k8s_kube-controller-manager|k8s_kube-scheduler|k8s_etcd_etcd' | awk -F ' ' '{print $1}' |xargs docker restart
|