Home > database >  Kubernetes Deployments and Jobs
Kubernetes Deployments and Jobs

Time:05-09

I am trying to run a single job which should wait for MySql deployment to start. And then there are several deployments where all deployments will wait for that single job to complete.

CodePudding user response:

The better thing for this use case is to use initcontainer in your others deployment that would check the MySQL pod to be up and running instead of a job - this is the best practice in kubernetes for this kind of thing ( you should add readiness probe in your MySQL deployment too )

Here is how to do this: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#init-containers-in-use

CodePudding user response:

You can right small bash script in Job to check the status of MySQL deployment as soon as it comes Ready Job should move ahead.

it would be more easy with HELM Hooks to resolve your issue.

You just need to add annotation to helm template : https://helm.sh/docs/topics/charts_hooks/

apiVersion: batch/v1
kind: job
metadata:
  annotations:
    "helm.sh/hook": pre-install

Helm will further release the deployment if the job gets successful or complete.

Read more : https://helm.sh/docs/topics/charts_hooks/

Extra :

If you are running CI/CD and executing a series of commands using just kubectl you can also checkout wait : https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#wait

kubectl wait will check for the condition to be met and print message acrrodingly.

  • Related