Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes check if "silent" pod finished executing

Tags:

kubernetes

Let's say that I defined a pod that simply runs a few pieces of code and exits afterwards. I need to make sure that this pod exits before allowing other pods to run. What is the best way to implement this?

I used to check whether a pod is ready by performing network requests, e.g. once ready, some webapps pods will block and listen to pre-defined ports, hence I can have the waiting pods performing netcat requests to them. But in this particular case the pod does not need to open any port, hence this approach does not work. Can anyone suggest an alternative?

Thanks

like image 279
João Matos Avatar asked Dec 21 '25 21:12

João Matos


1 Answers

If the "pieces of code" needs to be run in every pod start/restart, you maybe are looking for an Init Container implementation:

Init Containers are specialized Containers that run before app Containers and can contain utilities or setup scripts not present in an app image.

If your code is a dependency for multiple pods and needs to be run once (e.g., on every new deploy), you may consider using a Job Controller, and implement a logic to check if it's completed before deploying new pods/containers. (You can use commands like kubectl wait --for=condition=complete job/myjob on your deploy script).

If you are using helm to deploy, the best option is to use k8s job combined with pre-install and pre-upgrade helm hooks.

like image 195
Eduardo Baitello Avatar answered Dec 23 '25 12:12

Eduardo Baitello



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!