2

I have a k3s (v1.21.1+k3s1) cluster with following pods:

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

How can I restart (stop and start the pods again) the pods either with command (kubectl maybe) or any script?

solveit
  • 255
  • 2
  • 11

1 Answers1

3

Kubernetes doesn't support stopping/pausing the current state of Pods. However, you can perform a rollout restart of the Deployment/DaemonSet with the kubectl rollout restart command (see: the Kubectl Reference Docs).

To restart all Deployments and DaemonSets in the kube-system namespace, you can use the following command:

# 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

As you probably noticed from the output above, the calico-node is a DaemonSet and rest of the Pods are managed by Deployments.

If you want, you can restart specific 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
matt_j
  • 350
  • 2
  • 6