How to restart a failed pod in kubernetes deployment

3/21/2018

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

-- S Andrew
kubernetes

4 Answers

9/4/2019

kubectl -n <namespace> delete pods --field-selector=status.phase=Failed

I think the above command is quite useful when you want to restart 1 or more failed pods :D

And we doesn't need to care about name of failed pod.

-- Thọ Quách
Source: StackOverflow

3/21/2018

kubectl delete pod <podname> it will delete this one pod and DaemonSet will reschedule a new one

-- Radek 'Goblin' Pieczonka
Source: StackOverflow

12/6/2019

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
-- devstructor
Source: StackOverflow

11/28/2018

Just for others reading this...

A better solution (IMHO) is to implement a liveness prob that will force the pod to restart the container if it fails the probe test.

This is a great feature K8s offers out of the box. This is auto healing.

Also look into the pod lifecycle docs.

-- Eldad Assis
Source: StackOverflow