Kubernetes :: Restart terminated pod

12/6/2018

I'm using Kubernetes to run jobs with a RestartPolicy to Never.

Sometime, I would like to be able to debug a failed/terminated pod. In some way, I'm trying to find how restart it with a sleep XXX command to connect (exec) to the container and get the same state.

In Docker this is something doable using docker ps --all and then docker start X but I didn't find something similar with kubectl or the client-go

Thanks!

-- Ilan
docker
jobs
kubernetes

1 Answer

12/6/2018

Not sure about client-go as I have no experience there. But if I understood the question correctly, you can check the reason of the failure:

kubectl get pods (if you do not see your pod here add --all-namespaces)

NAME              READY     STATUS      RESTARTS   AGE
pi-c2x4r          0/1       Completed   0          19m
pi-test-c5hln     0/1       Error       0          16m`

And then run: kubectl describe pod pi-test-c5hln (name of your pod).

kubectl logs pi-test-c5hln

You can also find more information when you run:

kubectl describe job *job name*

You can find useful information about Jobs and how to work with them (including cleanup, termination and patterns) in here. Not sure if it needs to be added, but terminating is ongoing process, so you can work with the pod after it goes from terminating to other status (error, completed).

-- aurelius
Source: StackOverflow