Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restart a failed pod in kubernetes deployment

Tags:

kubernetes

I have 3 nodes in kubernetes cluster. I create a daemonset and deployed it in all the 3 devices. This daemonset created 3 pods and they were successfully running. But for some reasons, one of the pod failed.

I need to know how can we restart this pod without affecting other pods in the daemon set, also without creating any other daemon set deployment?

Thanks

like image 915
S Andrew Avatar asked Mar 21 '18 12:03

S Andrew


People also ask

What happens if a pod fails Kubernetes?

If Pod's status is Failed , Kubernetes will try to create new Pods until it reaches terminated-pod-gc-threshold in kube-controller-manager . This will leave many Failed Pods in a cluster and need to be cleaned up.


2 Answers

kubectl delete pod <podname> it will delete this one pod and Deployment/StatefulSet/ReplicaSet/DaemonSet will reschedule a new one in its place

like image 173
Radek 'Goblin' Pieczonka Avatar answered Nov 12 '22 05:11

Radek 'Goblin' Pieczonka


There are other possibilities to acheive what you want:

  • Just use rollout command

    kubectl rollout restart deployment mydeploy

  • You can set some environment variable which will force your deployment pods to restart:

    kubectl set env deployment mydeploy DEPLOY_DATE="$(date)"

  • You can scale your deployment to zero, and then back to some positive value

    kubectl scale deployment mydeploy --replicas=0     kubectl scale deployment mydeploy --replicas=1 
like image 37
devstructor Avatar answered Nov 12 '22 03:11

devstructor