将 rke2 集群证书延长至 10 年

发表: 2026-06-05|更新: 2026-06-05|分类: rke2

|字数总计: 845|阅读时长: 4分钟|阅读量:128492

本文永久链接: https://www.xtplayer.cn/rke2/extend-the-rke2-certificate-to-a-period-of-10-years/

在使用 RKE2 搭建生产环境时,大家或许遇到过证书有效期过短的问题。默认情况下,RKE2 中的系统证书有效期为 12 个月,临近过期后在服务重启时会自动轮换。然而,在实际部署中,我们常常希望将证书有效期设置得更长,避免频繁运维。

开发工具

本文将介绍如何在 RKE2 初始安装阶段已有集群中 ,通过配置环境变量 CATTLE_NEW_SIGNED_CERT_EXPIRATION_DAYS,将证书有效期延长至 5 年、甚至 10 年,让你的集群更"省心"。

注意:CATTLE_NEW_SIGNED_CERT_EXPIRATION_DAYS 的最大值为 3650(即 10 年),因为 RKE2 内部 CA 的最大有效期也是 10 年。

初始安装集群设置证书有效期

Step 1:配置环境变量

在安装 每个 RKE2 Server(Control-plane/etcd)节点 时,添加如下环境变量:

bash 复制代码
cat << EOF > /etc/default/rke2-server
CATTLE_NEW_SIGNED_CERT_EXPIRATION_DAYS=3650
EOF

该配置会将 RKE2 所有关键组件(如 kube-apiserver、etcd、kubelet 等)的证书有效期设置为 10 年。

Step 2:安装并启动 RKE2

bash 复制代码
curl -sfL https://get.rke2.io | sh -
systemctl start rke2-server.service

Step 3:验证证书有效期

bash 复制代码
rke2 certificate check

执行结果:

软件

bash 复制代码
INFO[0000] Server detected, checking agent and server certificates
INFO[0000] client-rke2-controller.crt: certificate system:rke2-controller (ClientAuth) is ok, expires at 2035-07-01T07:07:52Z
INFO[0000] client-rke2-controller.crt: certificate rke2-client-ca@1751526470 (CertSign) is ok, expires at 2035-07-01T07:07:50Z
INFO[0000] client-admin.crt: certificate system:admin (ClientAuth) is ok, expires at 2035-07-01T07:07:50Z
INFO[0000] client-admin.crt: certificate rke2-client-ca@1751526470 (CertSign) is ok, expires at 2035-07-01T07:07:50Z
INFO[0000] client-auth-proxy.crt: certificate system:auth-proxy (ClientAuth) is ok, expires at
...
...
...
INFO[0000] client-supervisor.crt: certificate system:rke2-supervisor (ClientAuth) is ok, expires at 2035-07-01T07:07:50Z
INFO[0000] client-supervisor.crt: certificate rke2-client-ca@1751526470 (CertSign) is ok, expires at 2035-07-01T07:07:50Z
INFO[0000] client-kube-proxy.crt: certificate system:kube-proxy (ClientAuth) is ok, expires at 2035-07-01T07:07:52Z
INFO[0000] client-kube-proxy.crt: certificate rke2-client-ca@1751526470 (CertSign) is ok, expires at 2035-07-01T07:07:50Z

你将看到所有证书的过期时间已延长至 2035 年。

已部署集群中修改证书有效期

Step 1:停止服务

bash 复制代码
systemctl stop rke2-server.service

Step 2:配置环境变量

bash 复制代码
cat << EOF > /etc/default/rke2-server
CATTLE_NEW_SIGNED_CERT_EXPIRATION_DAYS=3650
EOF

Step 3:执行证书轮换

bash 复制代码
rke2 certificate rotate

Step 4:重启服务

bash 复制代码
systemctl start rke2-server.service

Step 5:验证证书有效期

bash 复制代码
rke2 certificate check

执行结果:

计算机服务器

bash 复制代码
root@ip-172-31-16-225:~# rke2 certificate check
INFO[0000] Server detected, checking agent and server certificates
INFO[0000] client-kube-apiserver.crt: certificate system:apiserver (ClientAuth) is ok, expires at 2035-07-01T07:33:54Z
INFO[0000] client-kube-apiserver.crt: certificate rke2-client-ca@1751527477 (CertSign) is ok, expires at 2035-07-01T07:24:37Z
INFO[0000] serving-kube-apiserver.crt: certificate kube-apiserver (ServerAuth) is ok, expires at 2035-07-01T07:33:54Z
INFO[0000] serving-kube-apiserver.crt: certificate rke2-server-ca@1751527477 (CertSign) is ok, expires at 2035-07-01T07:24:37Z
INFO[0000] client-auth-proxy.crt: certificate system:auth-proxy (ClientAuth) is ok, expires at 2035-07-01T07:33:54Z
...
...
...
INFO[0000] client-kube-proxy.crt: certificate rke2-client-ca@1751527477 (CertSign) is ok, expires at 2035-07-01T07:24:37Z
INFO[0000] client-kubelet.crt: certificate system:node:ip-172-31-16-225 (ClientAuth) is ok, expires at 2035-07-01T07:33:56Z
INFO[0000] client-kubelet.crt: certificate rke2-client-ca@1751527477 (CertSign) is ok, expires at 2035-07-01T07:24:37Z
INFO[0000] serving-kubelet.crt: certificate ip-172-31-16-225 (ServerAuth) is ok, expires at 2035-07-01T07:33:55Z
INFO[0000] serving-kubelet.crt: certificate rke2-server-ca@1751527477 (CertSign) is ok, expires at 2035-07-01T07:24:37Z

确认所有证书的有效期已更新。

Step 6:在其他 Control-plane/etcd 节点重复 Step 1 ~ 5 的操作

确保整个集群的证书一致更新。

相关推荐
虎头金猫1 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
这个DBA有点耶1 天前
MVCC深入:Read View、版本链与快照读——InnoDB并发控制的内核
数据库·mysql·架构
DBA_G1 天前
从地面到云霄:GBase数据库在民航三大场景的落地实践
数据库
自由能燃气设备1 天前
商用全预混低氮冷凝锅炉免费方案vs付费方案对比+选型避坑指南
大数据·数据库·人工智能
科创致远1 天前
科创致远 ESOP 系统核心效能与实战价值展示
大数据·数据库·人工智能·精益工程
AI职业加油站1 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
此冬歌咏1 天前
K8s 节点故障实战:优雅驱逐 31 秒,硬故障 331 秒,以及那个永远 Pending 的 Pod
运维·k8s
2601_962218611 天前
万象生鲜系统称重自动多退少补算法解决生鲜非标品痛点
大数据·数据库·人工智能·python·算法
-梅1 天前
linux(8) 软硬链接
linux·运维·服务器
Wang's Blog1 天前
Java 项目实战: 外卖平台-文件下载与ServletOutputStream回写浏览器
服务器·项目开发