kubernetes集群证书一年后过期,如何续期

新版本续期过程请见下面的文章

kubernetes(1.23)证书过期如何续期

模拟证书过期

由kubeadm部署的集群,所生成的证书证书有效期为一年,过期之后集群就不能再次使用了,我们可以对证书进行续期,这样集群就可以继续使用。可以通过如下命令查看具体过期时间:

kubeadm alpha certs check-expiration

file
这里显示证书在2021年7月5日过期,然后把所有节点的系统时间调整到 2022年10月1日:
file
file
所有节点的时间都要调整。
然后在master(vms71上)执行kubectl命令:

[root@vms71 ~]# kubectl get nodes
Unable to connect to the server: x509: certificate has expired or is not yet valid
[root@vms71 ~]#

此时提醒证书已经过期。

对证书进行续期

用如下命令申请续期一年:
kubeadm alpha certs renew all

[root@vms71 ~]# kubeadm alpha  certs renew all
    ...输出...
certificate for the front proxy client renewed
certificate embedded in the kubeconfig file for the scheduler manager to use renewed
[root@vms71 ~]# 

现在查看证书过期时间:
file
更新kubeconfig文件:
file

验证

验证集群是否可用:
file
已经可以继续使用了。查看集群过期时间:
file
过期时间已经到了2023年10月1日了。

再练习一次

再次把系统时间改成2025年10月1日(所有节点都改):
file
因为证书有效期是2023-10-01,现在是2025-10-01,所以证书是过期的:
file
跟前面的做法一样:再次用kubeadm alpha certs renew all对证书进行续期,然后重启kubelet,更新kubeconfig文件。
然后查看证书过期时间:
file
已经显示为2026年10月1日(当前是2025年10月1日),验证集群是否可用:
file

相关新闻

发表回复

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

                                                                                                                                    RHCE9学习指南连载,点击阅读