4

Goal - Start deployment of pod when a particular jobs in completed using helm.

Currently I am using helm to deploy the configmap/pods/jobs. When I do "helm install" everything get deployed at the same time. Can I add delay/trigger saying when a particular jobs is completed then only deploy other pods.

I tried using "init container" but it difficult to get status of job in "init container"

pythonhmmm
  • 833
  • 1
  • 18
  • 38

2 Answers2

3

Helm chart hooks can do this. There's a series of points where Helm can deploy a set of resources one at a time and wait for them to be ready or completed.

For what you're describing, it is enough to use an annotation to mark a job as a pre-install hook:

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

None of the other resources in the chart will be deployed until the hook executes successfully. If the Job fails, it will block deploying any other resources. This pre-install hook only runs on first installation, but if you want the hook to run on upgrades or rollbacks, there are corresponding hooks to be able to do this.

There are still some workflows that are hard to express this way. For instance, if your service includes a database and you want a job to run migrations or seed data, you can't really deploy the database StatefulSet, then block on a Job hook, then deploy everything else; your application still needs to tolerate things maybe not being in the exact state it expects.

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • [This recent question](https://stackoverflow.com/questions/60262802/how-to-use-wait-with-post-install-hook-in-helm) is a good example of a case where hooks don't work well: a setup job and the main pods depend on each other, so the caller doesn't want the deployment to "succeed" until the job is done, but you can't clearly specify it to run either before or after the rest of the deployment. – David Maze Feb 18 '20 at 10:43
  • 1
    What I want to achieve is this -- Run some couple of pod deployment first, Run the job after that, when job status is completed run the rest of pod deployment. – pythonhmmm Feb 18 '20 at 12:27
  • Okay, then as @coderanger says in their answer, you’re probably in “write a custom operator” territory. – David Maze Feb 18 '20 at 13:16
1

This is somewhat out of the wheelhouse of Helm. You can use Hooks to get some relatively simplistic forms of this, but many people find them frustrating as complexity grows. The more complete form of this pattern requires writing an operator instead.

coderanger
  • 52,400
  • 4
  • 52
  • 75