Prevent Pod From Endless Restart
When a pod in error state (crashloopbackoff), kubernetes would
restart the pod. If you try to exec into the pod to check the log or
debug, the following error message appears: 1
unable to upgrade connection: container not found ("")
Because the old pod has been killed and you cannot exec into it anymore. So how can we prevent the pod from endless restart?
Just add a command to the deployment yaml to override the default
command by the container image. Make the pod never finished by
sleep infinity or tail -f /dev/null:
1 | command: ["sleep"] |
or
1 | command: ["tail"] |
Add them to spec.template.spec.containers like this:
1 | ... |
Remove the liveness/readiness section from the yaml to make the deployment status green if necessary.
You can exec into the pod to debug as you want.
Reference: