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

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.lqws.cn/news/87229.html

相关文章:

  • 【信创-k8s】海光/兆芯+银河麒麟V10离线部署k8s1.31.8+kubesphere4.1.3
  • 03.搭建K8S集群
  • IPython 使用技巧整理
  • Impromptu VLA:用于驾驶视觉-语言-动作模型的开放权重和开放数据
  • 基于wifi的室内定位算法设计与实现
  • 25年宁德时代新能源科技SHL 测评语言理解数字推理Verify题库
  • 操作系统:生态思政
  • Java基础(二):八种基本数据类型详解
  • [蓝桥杯]路径之谜
  • 从 iPhone 备份照片: 保存iPhone图片的5种方法
  • 【Pandas】pandas DataFrame rename_axis
  • vue-15 (实践练习:使用路由防护实现身份验证和授权)
  • MTK的Download agent是什么下载程序?
  • 【开源工具】Python+PyQt5打造智能桌面单词记忆工具:悬浮窗+热键切换+自定义词库
  • 【开源工具】超全Emoji工具箱开发实战:Python+PyQt5打造跨平台表情管理神器
  • 【C++高并发内存池篇】性能卷王养成记:C++ 定长内存池,让内存分配快到飞起!
  • 第三章 3.MAC Address(CCNA)
  • Redis 缓存粒度如何控制?缓存整个对象还是部分字段?
  • 写读后感的时候,可以适当地引用书中的内容吗?
  • C++智能指针的知识!
  • 2048小游戏C++板来啦!
  • 第一篇:揭示模型上下文协议(MCP):AI的通用连接器
  • JavaSE:面向对象进阶之内部类(Inner Class)
  • STM32 智能小车项目 L298N 电机驱动模块
  • “application/json“,“text/plain“ 分别表示什么
  • 源码解析(三):Stable Diffusion
  • MySQL——事务
  • Java转义字符
  • PostgreSQL的扩展 insert_username
  • 复变函数 $w = z^2$ 的映射图像演示