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

k8s更新证书

[root@k8s-master01 ~]# sudo 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’

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
certificate embedded in the kubeconfig file for the super-admin 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.
[root@k8s-master01 ~]#

好的,根据提示,你已经成功更新了证书,接下来你需要重启相关的控制平面组件,以便它们加载并使用新的证书。这些组件通常作为静态 Pod (static pods) 运行在你的主节点上,由 kubelet直接管理。

接下来的操作步骤:

  1. 重启 kubelet 服务:
    在你的主节点 (k8s-master01) 上,执行以下命令来重启 kubelet 服务。重启 kubelet 会使其重新启动由它管理的静态 Pod(包括 kube-apiserver, kube-controller-manager, kube-scheduleretcd)。

    sudo systemctl restart kubelet
    
    • 如果你有多个主节点 (HA 集群): 你需要在每一个主节点上都执行 sudo systemctl restart kubelet 命令。
  2. 验证组件是否已重启并正常运行:
    等待一两分钟,让组件有时间重新启动。然后进行检查:

    • 检查静态 Pod 的状态:

      kubectl get pods -n kube-system
      

      查看 kube-apiserver-k8s-master01, kube-controller-manager-k8s-master01, kube-scheduler-k8s-master01etcd-k8s-master01 (Pod 名称中的主机名部分可能与你的节点名一致) 是否处于 Running 状态,并注意它们的 AGE 是否比较新,表明它们是最近重启的。

    • 检查组件日志 (可选,用于排错):
      如果某个 Pod 没有正常启动,你可以查看它的日志:

      kubectl logs <pod-name> -n kube-system
      # 例如:
      # kubectl logs kube-apiserver-k8s-master01 -n kube-system
      
    • 检查集群状态:

      kubectl cluster-info
      kubectl get nodes
      

      确保集群API可访问,节点状态正常。

    • (重要) 再次检查证书过期时间:
      如果之前使用了 kubeadm certs check-expiration,可以再次运行它来确认新的证书生效并且过期时间已更新:

      sudo kubeadm certs check-expiration
      
  3. 更新你的 kubectl 配置文件 (如果需要):
    证书更新过程通常也会更新 /etc/kubernetes/admin.conf 文件。为了让你本地的 kubectl 能够使用新的凭证与集群通信,你需要将更新后的 admin.conf 复制到你的 ~/.kube/config

    mkdir -p $HOME/.kube
    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    sudo chown $(id -u):$(id -g) $HOME/.kube/config
    

    执行完这个操作后,你可能需要退出当前 shell 会话再重新登录,或者新开一个终端,以确保新的 kubectl 配置生效。

总结一下关键步骤:

  • 在所有主节点上:sudo systemctl restart kubelet
  • 等待片刻,然后使用 kubectl get pods -n kube-systemsudo kubeadm certs check-expiration 进行验证。
  • 更新你本地的 ~/.kube/config

操作时请务必小心,尤其是在生产环境中。如果在重启过程中遇到问题,请检查相关组件的日志以获取更详细的错误信息。

http://www.xdnf.cn/news/10882.html

相关文章:

  • Python基于SVM技术的手写数字识别问题项目实战
  • 一个html实现数据库自定义查询
  • Scrapy爬虫框架Spiders爬虫脚本使用技巧
  • 【蓝桥杯】包子凑数
  • 用Python训练自动驾驶神经网络:从零开始驾驭未来之路
  • VR线上展厅特点分析与优势
  • 计算机组成原理知识点汇总(五)计算机运算方法
  • web攻防之SSTI 注入漏洞
  • 黑马Java面试笔记之 集合篇(算法复杂度+ArrayList+)
  • 【数据库】安全性
  • 【笔记】使用Media Creation Tool给新主机装win10魔改iso
  • 00 Deep learning 之回归、拟合、逻辑回归
  • SAP学习笔记 - 开发20 - 前端Fiori开发 Nest View(嵌套视图) ,Fragment(片段)
  • 深入解析 MultipartFile:Spring 框架下的高效文件处理方案
  • backend 服务尝试连接 qdrant 容器,但失败了,返回 502 Bad Gateway 问题排查
  • [Java恶补day14] 56. 合并区间
  • JAVA获取ES连接并查询所有数据
  • RTP over TCP 模式
  • 如何用 pnpm patch 给 element-plus 打补丁修复线上 bug(以 2.4.4 修复 PR#15197 为例)
  • 4-C#的不同窗口传值
  • 洛谷P12610 ——[CCC 2025 Junior] Donut Shop
  • 转战海外 Web3 远程工作指南
  • (10)Fiddler抓包-Fiddler如何设置捕获Firefox浏览器的Https会话
  • 双周报Vol.73:移除使用方法实现 trait 、新增了 “错误多态” 功能、.语法支持使用 _ 的匿名函数...
  • 16QAM在瑞利信道下的性能仿真:从理论到实践的完整解析(附完整代码)
  • 【HarmonyOS 5】鸿蒙Taro跨端框架
  • 【TMS570LC4357】之相关驱动开发学习记录1
  • 总结:线程安全问题的原因和解决方案
  • 初识vue3(vue简介,环境配置,setup语法糖)
  • LlamaIndex的IngestionPipeline添加本地存储(本地文档存储)