kubeadm 常见操作

目录

  1. renew 证书

  2. 升级 Kubernetes

    1. 升级 Master 节点

    2. 升级剩余的节点

    3. 使用自定义的 kubeadm config

  3. 新增节点

  4. 清理节点

renew 证书

使用下列命令直接 renew 所有证书:

[root@k8s-m01 ~]# 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'
W0920 20:40:32.931747    5070 configset.go:77] Warning: No kubeproxy.config.k8s.io/v1alpha1 config is loaded. Continuing without it: configmaps "kube-proxy" not found

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

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-m01 ~]#

升级 Kubernetes

升级 Master 节点

参考文档:https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/

开始升级:

相关升级日志:

升级 Master 节点的 kubelet

相关日志:

升级 kubelet 和 kubectl:

升级完成后检查 Master 版本正常:

升级剩余的节点

依次登陆 Worker 节点,使用下列命令升级:

相关日志:

在 Master 节点依次 drain 节点,并升级 kubelet

登陆相关 Worker 节点,使用下列命令升级:

在 Master 节点依次 uncordon 所有节点:

再重复上述步骤,处理剩余节点。

最终检查所有版本升级完毕:

使用自定义的 kubeadm config

如果在升级时想调整 kubeadm 的配置,可以使用下列方法导出 kubeadm config,修改后再调用:

编辑 kubeadm config 文件,将里面的 data 提取出来,去掉 configmap 的内容。修改里面的 Kubernetes 版本号为目标版本 (此处为 v1.21.9)

使用 kubeadm upgrade plan 并调用上述的 yaml 文件,进行升级检查:

确保无问题后使用下列命令进行升级:

其余步骤和前面文章的一致。

新增节点

默认 kubeadm 生成的 token 只有一天的有效期,在 token 过期后,新增的 worker 不能再通过之前的 join 加入 Master,因此需要创建新的 token,同时生产加入集群的命令,之后在 Worker 直接执行即可:

清理节点

通过下列命令卸载 Kubernetes(注意这些步骤并不会卸载 CNI 残留的组件,所以如果卸载后安装其他 CNI 可能会出问题):

这有帮助吗?