Kubernetes deployment failure - how to inspect?

9/16/2019

I have a deployment file and when I do kubectl apply -f my pods don't get deployed after a few restart and crashes. Hence my questions:

1- If I set the replicas to 1, is there a way to have an "interactive" mode where I can see in my terminal what's going on?

2- Is there a way to limit - in the deployment file - the number of restart? This can be specified for pods (restartPolicy...) but not for deployment apparently?

3- Any troubleshooting guidelines? For example, how to check that the values in the config maps are properly picked up? Many thanks - Christian

-- Christian68
deployment
kubernetes

2 Answers

9/16/2019

1) You can use

# kubectl get pods -n <your namespace>

command to see your pods. To see them "interactive", you can use watch command with kubectl like this;

# watch kubectl get pods -n <your-namespace>

2) Currently, there is no way to limit the pod restart counts.

3) You can see what's going on with your deployments and pods while they are created with kubectl describe command.

For getting info about pod status,

# kubectl get pods -n <your-namespace> --> here you can get your pod's name.
# kubectl describe po <pod-name> -n <your-namespace>

For getting info about deployment status,

# kubectl get deployments -n <your-namespace> --> here you can get your deployment's name.
# kubectl describe deployment <deployment-name> -n <your-namespace>

Hope it helps.

-- Armagan Karatosun
Source: StackOverflow

9/16/2019

If your pods have managed to actually be scheduled and start, but the app inside the container crashes, then usually kubectl logs will be able to show you the logs that were written to stdout / stderr inside the container.

E.g. kubectl logs -n your-namespace your-pod-name

You can also tail or head logs. E.g.

  • kubectl logs -n your-namespace your-pod-name --tail=50 (for the last 50 log lines)
  • kubectl logs -n your-namespace your-pod-name -f (follow logs)

Otherwise if your container has failed to be scheduled by kubernetes, then describe is probably a better option.

E.g. kubectl -n your-namespace describe your-pod-name

Here are some other useful examples around interacting with pods that are running (and have not crashed yet).

-- Shogan
Source: StackOverflow