Middle
How can a pod be restarted in Kubernetes? List several options.
sobes.tech AI
Answer from AI
In Kubernetes, there are several ways to restart a pod:
- Delete the pod manually:
kubectl delete pod <pod-name>
The controller (e.g., Deployment) will automatically create a new pod.
- Update the Deployment: Change the configuration (e.g., add or modify an annotation) to trigger a rollout:
kubectl rollout restart deployment/<deployment-name>
-
Modify the pod's metadata: For example, update an annotation to trigger pod recreation.
-
Use the patch command:
kubectl patch deployment <deployment-name> -p '{"spec":{"template":{"metadata":{"annotations":{"date":"$(date +%s)"}}}}}'
- Restart via scaling: Reduce the number of replicas to 0, then revert back:
kubectl scale deployment <deployment-name> --replicas=0
kubectl scale deployment <deployment-name> --replicas=3
All these methods allow updating or restarting pods without stopping the entire cluster.