报错:
[root@k8s-master01 ~]# kubectl get cs
Unable to connect to the server: x509: certificate has expired or is not yet valid: current time 2024-10-06T01:05:49-07:00 is after 2024-05-19T11:11:43Z
查看证书过期情况:
[root@k8s-master01 ~]# kubeadm certs check-expiration
[check-expiration] Reading configuration from the cluster...
[check-expiration] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[check-expiration] Error reading configuration from the Cluster. Falling back to default configuration
CERTIFICATE EXPIRES RESIDUAL TIME CERTIFICATE AUTHORITY EXTERNALLY MANAGED
admin.conf May 19, 2024 11:11 UTC <invalid> ca no
apiserver May 19, 2024 11:11 UTC <invalid> ca no
apiserver-etcd-client May 19, 2024 11:11 UTC <invalid> etcd-ca no
apiserver-kubelet-client May 19, 2024 11:11 UTC <invalid> ca no
controller-manager.conf May 19, 2024 11:11 UTC <invalid> ca no
etcd-healthcheck-client May 19, 2024 11:11 UTC <invalid> etcd-ca no
etcd-peer May 19, 2024 11:11 UTC <invalid> etcd-ca no
etcd-server May 19, 2024 11:11 UTC <invalid> etcd-ca no
front-proxy-client May 19, 2024 11:11 UTC <invalid> front-proxy-ca no
scheduler.conf May 19, 2024 11:11 UTC <invalid> ca no
CERTIFICATE AUTHORITY EXPIRES RESIDUAL TIME EXTERNALLY MANAGED
ca May 17, 2033 11:11 UTC 8y no
etcd-ca May 17, 2033 11:11 UTC 8y no
front-proxy-ca May 17, 2033 11:11 UTC 8y no
[root@k8s-master01 ~]#
更新证书:
[root@k8s-master01 ~]# kubeadm certs renew all
[renew] Reading configuration from the cluster...
[renew] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[renew] Error reading configuration from the Cluster. Falling back to default configuration
certificate embedded in the kubeconfig file for the admin to use and for kubeadm itself renewed
certificate for serving the Kubernetes API renewed
certificate the apiserver uses to access etcd renewed
certificate for the API server to connect to kubelet renewed
certificate embedded in the kubeconfig file for the controller manager to use renewed
certificate for liveness probes to healthcheck etcd renewed
certificate for etcd nodes to communicate with each other renewed
certificate for serving etcd renewed
certificate for the front proxy client renewed
certificate embedded in the kubeconfig file for the scheduler manager to use renewed
Done renewing certificates. You must restart the kube-apiserver, kube-controller-manager, kube-scheduler and etcd, so that they can use the new certificates.
重启容器kube-apiserver, kube-controller-manager, kube-scheduler and etcd:
docker restart f069c1419b49 9ca49995c51d 42ef470df27b 5eaeb63ac3a3
更新集群认证配置:
[root@k8s-master01 ~]# kubeadm certs renew admin.conf
[renew] Reading configuration from the cluster...
[renew] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
certificate embedded in the kubeconfig file for the admin to use and for kubeadm itself renewed
\cp /etc/kubernetes/admin.conf ~/.kube/config
更新各节点kubelet连接集群配置:
\cp /etc/kubernetes/admin.conf /etc/kubernetes/kubelet.conf
再次检查证书过期情况,证书更新成功:
kubeadm certs check-expiration
[root@k8s-master01 ~]# kubeadm certs check-expiration
[check-expiration] Reading configuration from the cluster…
[check-expiration] FYI: You can look at this config file with ‘kubectl -n kube-system get cm kubeadm-config -o yaml’
CERTIFICATE EXPIRES RESIDUAL TIME CERTIFICATE AUTHORITY EXTERNALLY MANAGED
admin.conf Oct 06, 2025 08:12 UTC 364d ca no
apiserver Oct 06, 2025 08:09 UTC 364d ca no
apiserver-etcd-client Oct 06, 2025 08:09 UTC 364d etcd-ca no
apiserver-kubelet-client Oct 06, 2025 08:09 UTC 364d ca no
controller-manager.conf Oct 06, 2025 08:09 UTC 364d ca no
etcd-healthcheck-client Oct 06, 2025 08:09 UTC 364d etcd-ca no
etcd-peer Oct 06, 2025 08:09 UTC 364d etcd-ca no
etcd-server Oct 06, 2025 08:09 UTC 364d etcd-ca no
front-proxy-client Oct 06, 2025 08:09 UTC 364d front-proxy-ca no
scheduler.conf Oct 06, 2025 08:09 UTC 364d ca no
CERTIFICATE AUTHORITY EXPIRES RESIDUAL TIME EXTERNALLY MANAGED
ca May 17, 2033 11:11 UTC 8y no
etcd-ca May 17, 2033 11:11 UTC 8y no
front-proxy-ca May 17, 2033 11:11 UTC 8y no
[root@k8s-master01 ~]#