Kubernetes

如何重啟或重置 K3s 集群 Pod

  • August 12, 2021

我有一個帶有以下 pod 的 k3s ( v1.21.1+ k3s1) 集群:

kube-system   pod/calico-node-xxxx                          
kube-system   pod/calico-kube-controllers-xxxxxx   
kube-system   pod/metrics-server-xxxxx
kube-system   pod/local-path-provisioner-xxxxx
kube-system   pod/coredns-xxxxx

如何使用命令(kubectl可能)或任何腳本重新啟動(停止並再次啟動 pod)pod?

Kubernetes 不支持停止/暫停 Pod 的目前狀態。但是,您可以使用命令重新啟動Deployment/ (請參閱:Kubectl 參考文件)。DaemonSet``kubectl rollout restart

要重新啟動所有DeploymentsDaemonSetskube-system命名空間中,您可以使用以下命令:

# kubectl -n kube-system rollout restart daemonsets,deployments
daemonset.apps/calico-node restarted
deployment.apps/local-path-provisioner restarted
deployment.apps/coredns restarted
deployment.apps/metrics-server restarted
deployment.apps/calico-kube-controllers restarted

正如您可能從上面的輸出中註意到的那樣,calico-nodeis aDaemonSet和其餘的 Pod 由Deployments.

如果需要,您可以重新啟動特定Deployment/ Daemonset

# kubectl -n kube-system rollout restart deployment metrics-server
deployment.apps/metrics-server restarted
# kubectl get pod -n kube-system | grep metrics-server
metrics-server-6bd8786b6c-74qlt            1/1     Running       0          2s
metrics-server-647d5b4475-ch9zj            1/1     Terminating   0          28s

引用自:https://serverfault.com/questions/1073966