How to avoid K8s kill pod on startup

9/28/2019

I have a backend pod running a quite migration script on startup (1 minute or more). How to avoid K8s thinks that the pods failed to start and tries to re-launch it?

-- pditommaso
kubernetes

1 Answer

9/28/2019

I'm assuming you have a liveness probe set on your Pod. This is what k8s is looking at when it decides whether a pod needs restarted. You can fix this by setting the initialDelaySeconds attribute on your script to something beyond the length of time the migration script needs to run. https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/

An alternative is to use an initContainer for the Pod that runs the migration script. This is what init containers are used for. https://kubernetes.io/docs/concepts/workloads/pods/init-containers/

-- Grant David Bachman
Source: StackOverflow