[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
直接管理。
接下來的操作步驟:
-
重啟
kubelet
服務:
在你的主節點 (k8s-master01
) 上,執行以下命令來重啟kubelet
服務。重啟kubelet
會使其重新啟動由它管理的靜態 Pod(包括kube-apiserver
,kube-controller-manager
,kube-scheduler
和etcd
)。sudo systemctl restart kubelet
- 如果你有多個主節點 (HA 集群): 你需要在每一個主節點上都執行
sudo systemctl restart kubelet
命令。
- 如果你有多個主節點 (HA 集群): 你需要在每一個主節點上都執行
-
驗證組件是否已重啟并正常運行:
等待一兩分鐘,讓組件有時間重新啟動。然后進行檢查:-
檢查靜態 Pod 的狀態:
kubectl get pods -n kube-system
查看
kube-apiserver-k8s-master01
,kube-controller-manager-k8s-master01
,kube-scheduler-k8s-master01
和etcd-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
-
-
更新你的
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-system
和sudo kubeadm certs check-expiration
進行驗證。 - 更新你本地的
~/.kube/config
。
操作時請務必小心,尤其是在生產環境中。如果在重啟過程中遇到問題,請檢查相關組件的日志以獲取更詳細的錯誤信息。