To restart a pod in Kubernetes, you can use the kubectl rollout
command with the restart
option. This will trigger a rolling update for the specified deployment or statefulset, causing all pods to be recreated with their latest configurations.
Here’s an example command to restart a deployment:
kubectl rollout restart deployment/<deployment-name>
And here’s an example command to restart a statefulset:
kubectl rollout restart statefulset/<statefulset-name>
Note that this method of restarting a pod will cause some downtime for your application as each pod is terminated and recreated. To minimize this disruption, you can use Kubernetes’ built-in rolling update strategy, which gradually replaces old pods with new ones instead of doing it all at once. To use this strategy, specify appropriate values for the maxSurge
and maxUnavailable
fields in your deployment or statefulset configuration.