当前位置: 首页 > news >正文

K8s集群证书续签100年有效期

基于Docker搭建多主多从K8s高可用集群 - 在线方式 - 永久证书

主机名IP地址角色操作系统硬件配置
ansible10.62.158.200同步工具节点CentOS 72 Core/4G Memory
master0110.62.158.201管理节点01CentOS 72 Core/4G Memory
master0210.62.158.202管理节点02CentOS 72 Core/4G Memory
master0310.62.158.203管理节点03CentOS 72 Core/4G Memory
node0110.62.158.204工作节点01CentOS 71 Core/2G Memory
node0210.62.158.205工作节点02CentOS 71 Core/2G Memory
k8s-ha0110.62.158.206主代理节点CentOS 71 Core/2G Memory
k8s-ha0210.62.158.207备用代理节点CentOS 71 Core/2G Memory

查看当前集群状态

[root@master01 ~]# kubectl get nodeNAME STATUS ROLES AGE VERSION master01 Ready control-plane,master 22d v1.23.0 master02 Ready control-plane,master 22d v1.23.0 master03 Ready control-plane,master 22d v1.23.0 node01 Ready <none> 22d v1.23.0 node02 Ready <none> 22d v1.23.0

查看证书过期时间

[root@master01 ~]# kubeadm certs check-expiration[check-expiration]Reading configurationfromthe 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 Apr 17,2025 04:39 UTC 342d no apiserver Apr 17,2025 04:39 UTC 342d ca no apiserver-etcd-client Apr 17,2025 04:39 UTC 342d etcd-ca no apiserver-kubelet-client Apr 17,2025 04:39 UTC 342d ca no controller-manager.conf Apr 17,2025 04:39 UTC 342d no etcd-healthcheck-client Apr 17,2025 04:39 UTC 342d etcd-ca no etcd-peer Apr 17,2025 04:39 UTC 342d etcd-ca no etcd-server Apr 17,2025 04:39 UTC 342d etcd-ca no front-proxy-client Apr 17,2025 04:39 UTC 342d front-proxy-ca no scheduler.conf Apr 17,2025 04:39 UTC 342d no CERTIFICATE AUTHORITY EXPIRES RESIDUAL TIME EXTERNALLY MANAGED ca Apr 15,2034 04:39 UTC 9y no etcd-ca Apr 15,2034 04:39 UTC 9y no front-proxy-ca Apr 15,2034 04:39 UTC 9y no

GoLang环境安装 - go1.22.0.linux-amd64.tar.gz

# 下载环境文件[root@master01 ~]# wget https://studygolang.com/dl/golang/go1.17.6.linux-amd64.tar.gz[root@master01 ~]# lsanaconda-ks.cfg calico.yaml docker docker-20.10.tar.gz go1.17.6.linux-amd64.tar.gz kubeadm-config.yml nginx.yml sysconfigure.sh# 文件解压[root@master01 ~]# tar -xvf go1.17.6.linux-amd64.tar.gz -C /usr/local/# 配置环境变量[root@master01 ~]# echo "export PATH=$PATH:/usr/local/go/bin" >>/etc/profile[root@master01 ~]# source /etc/profile# 验证go环境[root@master01 ~]# go versiongo version go1.17.6 linux/amd64

下载kubernetes源码 - kubernetes-1.23.0.tar.gz

# 查看下当前已安装的k8s版本[root@master01 ~]# kubectl versionClient Version: version.Info{Major:"1",Minor:"23",GitVersion:"v1.23.0",GitCommit:"ab69524f795c42094a6630298ff53f3c3ebab7f4",GitTreeState:"clean",BuildDate:"2021-12-07T18:16:20Z",GoVersion:"go1.17.3",Compiler:"gc",Platform:"linux/amd64"}Server Version: version.Info{Major:"1",Minor:"23",GitVersion:"v1.23.0",GitCommit:"ab69524f795c42094a6630298ff53f3c3ebab7f4",GitTreeState:"clean",BuildDate:"2021-12-07T18:09:57Z",GoVersion:"go1.17.3",Compiler:"gc",Platform:"linux/amd64"}# 下载对应的源码[root@master01 ~]# wget https://github.com/kubernetes/kubernetes/archive/v1.23.0.tar.gz[root@master01 ~]# lsanaconda-ks.cfg calico.yaml docker docker-20.10.tar.gz go1.17.6.linux-amd64.tar.gz kubeadm-config.yml kubernetes-1.23.0.tar.gz nginx.yml sysconfigure.sh# 源码解压[root@master01 ~]# tar -zxvf kubernetes-1.23.0.tar.gz[root@master01 ~]# lsanaconda-ks.cfg calico.yaml docker docker-20.10.tar.gz go1.17.6.linux-amd64.tar.gz kubeadm-config.yml kubernetes-1.23.0 kubernetes-1.23.0.tar.gz nginx.yml sysconfigure.sh

修改证书有效期

[root@master01 ~]# cd kubernetes-1.23.0[root@master01 kubernetes-1.23.0]# vim ./cmd/kubeadm/app/constants/constants.goCertificateValidity = time.Hour*24*365*100[root@master kubernetes-1.23.0]# vim staging/src/k8s.io/client-go/util/cert/cert.goNotAfter: now.Add(duration365d*100).UTC(),

编译源代码文件

[root@master01 kubernetes-1.23.0]# make WHAT=cmd/kubeadm GOFLAGS=-v

注意:若出现 ./hack/run-in-gopath.sh:行34: _output/bin/prerelease-lifecycle-gen: 权限不够 问题时,需要添加权限后再编译源码文件

[root@master01 kubernetes-1.23.0]# yum install rsync jq -y[root@master01 bin]# chmod +x _output/bin/prerelease-lifecycle-gen[root@master01 bin]# chmod +x _output/bin/deepcopy-gen

查看编译后kubeadm二进制文件 - kubeadm

[root@master01 kubernetes-1.23.0]# ls -l _output/bin/总用量 79012-rwxr-xr-x 1 root root 6275072 5月 9 18:19 conversion-gen-rwxr-xr-x 1 root root 5996544 5月 9 18:19 deepcopy-gen-rwxr-xr-x 1 root root 6000640 5月 9 18:19 defaulter-gen-rwxr-xr-x 1 root root 3376695 5月 9 18:19 go2make-rwxr-xr-x 1 root root 45170688 5月 9 18:43 kubeadm-rwxr-xr-x 1 root root 8114176 5月 9 18:19 openapi-gen-rwxr-xr-x 1 root root 5971968 5月 9 18:19 prerelease-lifecycle-gen

备份原有的kubeadm文件

[root@master01 kubernetes-1.23.0]# cp /usr/bin/kubeadm /usr/bin/kubeadm_bak20240509

替换新编译的kubeadm文件覆盖旧的kubeadm文件

# 集群初始化时仅使用kubeadm二进制文件即可,需要赋予可执行权限[root@master01 kubernetes-1.23.0]# cp /root/kubernetes-1.23.0/_output/bin/kubeadm /usr/bin/

备份pki证书文件

[root@master01 kubernetes-1.23.0]# cd /etc/kubernetes[root@master01 kubernetes]# cp -R pki/ pki_bak20240509 -- 未初始化不需要这个

证书更新

# CA根证书不生效,需要集群初始化时才生效[root@master01 kubernetes]# kubeadm certs renew all[renew]Reading configurationfromthe 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 fileforthe admin to use andforkubeadm itself renewed certificateforserving the Kubernetes API renewed certificate the apiserver uses to access etcd renewed certificateforthe API server to connect to kubelet renewed certificate embedded in the kubeconfig fileforthe controller manager to use renewed certificateforliveness probes to healthcheck etcd renewed certificateforetcd nodes to communicate with each other renewed certificateforserving etcd renewed certificateforthe front proxy client renewed certificate embedded in the kubeconfig fileforthe 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.

查看证书是否为100年

[root@master01 kubernetes]# kubeadm certs check-expiration[check-expiration]Reading configurationfromthe 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 Apr 15,2124 11:45 UTC 99y no apiserver Apr 15,2124 11:45 UTC 99y ca no apiserver-etcd-client Apr 15,2124 11:45 UTC 99y etcd-ca no apiserver-kubelet-client Apr 15,2124 11:45 UTC 99y ca no controller-manager.conf Apr 15,2124 11:45 UTC 99y no etcd-healthcheck-client Apr 15,2124 11:45 UTC 99y etcd-ca no etcd-peer Apr 15,2124 11:45 UTC 99y etcd-ca no etcd-server Apr 15,2124 11:45 UTC 99y etcd-ca no front-proxy-client Apr 15,2124 11:45 UTC 99y front-proxy-ca no scheduler.conf Apr 15,2124 11:45 UTC 99y no CERTIFICATE AUTHORITY EXPIRES RESIDUAL TIME EXTERNALLY MANAGED ca Apr 15,2034 04:39 UTC 9y no etcd-ca Apr 15,2034 04:39 UTC 9y no front-proxy-ca Apr 15,2034 04:39 UTC 9y no
上传01管理节点中编译后的kubeadm二进制文件到02管理节点和03管理节点,02管理节点与03管理节点证书有效期调整,操作步骤一致,以下为02管理节点操作过程

上传kubeadm二进制文件

[root@master02 ~]# lsanaconda-ks.cfg docker docker-20.10.tar.gz kubeadm sysconfigure.sh

添加执行权限

[root@master02 ~]# chmod +x kubeadm

备份原有的kubeadm文件

[root@master02 ~]# cp /usr/bin/kubeadm /usr/bin/kubeadm_bak20240509

替换新编译的kubeadm文件覆盖旧的kubeadm文件

[root@master kubernetes-1.23.0]# cp /root/kubeadm /usr/bin/

备份pki证书文件

[root@master02 ~]# cd /etc/kubernetes[root@master02 kubernetes]# cp -R pki/ pki_bak20240509

证书更新

[root@master02 kubernetes]# kubeadm certs renew all[renew]Reading configurationfromthe 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 fileforthe admin to use andforkubeadm itself renewed certificateforserving the Kubernetes API renewed certificate the apiserver uses to access etcd renewed certificateforthe API server to connect to kubelet renewed certificate embedded in the kubeconfig fileforthe controller manager to use renewed certificateforliveness probes to healthcheck etcd renewed certificateforetcd nodes to communicate with each other renewed certificateforserving etcd renewed certificateforthe front proxy client renewed certificate embedded in the kubeconfig fileforthe 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.

查看证书是否为100年

[root@master02 kubernetes]# kubeadm certs check-expiration[check-expiration]Reading configurationfromthe 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 Apr 15,2124 11:56 UTC 99y no apiserver Apr 15,2124 11:56 UTC 99y ca no apiserver-etcd-client Apr 15,2124 11:56 UTC 99y etcd-ca no apiserver-kubelet-client Apr 15,2124 11:56 UTC 99y ca no controller-manager.conf Apr 15,2124 11:56 UTC 99y no etcd-healthcheck-client Apr 15,2124 11:56 UTC 99y etcd-ca no etcd-peer Apr 15,2124 11:56 UTC 99y etcd-ca no etcd-server Apr 15,2124 11:56 UTC 99y etcd-ca no front-proxy-client Apr 15,2124 11:56 UTC 99y front-proxy-ca no scheduler.conf Apr 15,2124 11:56 UTC 99y no CERTIFICATE AUTHORITY EXPIRES RESIDUAL TIME EXTERNALLY MANAGED ca Apr 15,2034 04:39 UTC 9y no etcd-ca Apr 15,2034 04:39 UTC 9y no front-proxy-ca Apr 15,2034 04:39 UTC 9y no
http://www.jsqmd.com/news/1166952/

相关文章:

  • 亨得利中国区官方售后服务中心|最新维修地址及电话权威收录(2026年7月最新) - 亨得利腕表服务中心
  • Claude Sonnet 5智能体任务实战:成本优化与执行连续性提升
  • (8-5)
  • 面向 AI 抓取的内容页面结构方法
  • 金融级数据底座自主可控落地:批量迁移、分级架构与零丢失容灾实战
  • Emacs-wgrep安装配置完全指南:从零开始到高级定制
  • 9款AI写作辅助软件:一键生成毕业论文、期刊论文、开题报告与文献综述
  • Infisical:把密钥管理这件事做透了
  • 国内免费AI服务实测指南:从环境配置到质量评估
  • 魔方财务idc对接 Cloudflare 二级域名分发插件 (v1.9.7 开源版)
  • Feather框架插件系统开发:如何扩展框架功能的完整指南
  • 终极指南:让老旧Mac重获新生的OpenCore Legacy Patcher
  • Windows 11系统优化终极指南:Chris Titus Tech WinUtil完整使用教程
  • 浪琴中国官方售后服务中心|地址与官方服务热线权威信息公示(2026年7月最新) - 浪琴服务中心
  • Parsec VDD实战指南:解决无物理显示器下的游戏串流与远程办公痛点
  • FreeRouting终极指南:如何用开源PCB自动布线工具提升设计效率10倍
  • SrtEdit 新版发布(9.1.2026.07.10)
  • SAP AW01N 资产价值浏览器:5个关键字段深度解析与常见业务场景对照
  • 闲鱼买AI账号风险全解析:从401错误到法律追责
  • FFXIV TexTools终极指南:3步轻松掌握FF14模组管理技巧
  • 【数字员工ARM】企业数字化转型的三个十年
  • (10-3-01)地图、树结构以及节点相关的类和方法
  • Midjourney海报生成失效全解(参数冲突大揭秘):实测137组prompt组合后总结的4类致命错误
  • Claude Opus 4.7+国内稳定接入方案:四层代理架构实战
  • 2026安徽职教高考新政:在技校读书能考大学吗?安徽建工技师学院高级班,升学渠道畅通无阻! - 最新资讯
  • 如何3分钟配置智能百鬼夜行:阴阳师自动化脚本实战指南
  • 界面控件DevExpress JS ASP.NET Core v24.1 - 全新的分割器组件
  • 高精度数据采集系统设计与实现:基于ADS127L11与PIC18LF47K40
  • 免费解锁Emby Premiere功能:技术实现与本地化验证方案
  • 解锁可视化Web构建新时代:GrapesJS框架深度探索之旅