Dependency between pods in helm charts

3/15/2019

I am trying to deploy a helm chart and I need help for my use case.

My requirement is that in helm chart templates folder, I have few deployment yml and .tpl files, When I invoke helm install command, one of the deployment yml in the template folder will deploy as kind 'job' with only one pod associated to it. The other deployment ymls in the templates folder should wait for this job to be finished successfully and then only should get deployed on kubernetes as a pod.

When I will trigger helm install command , helm will read all the yml and hence will try to deploy all the pods at once which I don't want. I want my job to be succeeded first and then only the other pods should start getting deployed. While the job is running , all the other pods should wait or should not start as they all are dependent on job to be successful.

How can I achieve this case using helm. Please suggest.How can I make other pods wait and let them know that job has been successfully completed now.

-- Saurabh
kubernetes-helm

1 Answer

3/15/2019

You are looking for helm hooks:

Helm provides a hook mechanism to allow chart developers to intervene at certain points in a release's life cycle. For example, you can use hooks to:

  • Load a ConfigMap or Secret during install before any other charts are loaded.
  • Execute a Job to back up a database before installing a new chart, and then execute a second job after the upgrade in order to restore data.
  • Run a Job before deleting a release to gracefully take a service out of rotation before removing it.

Add the following annotation to your job:

metadata:
  annotations:
    "helm.sh/hook": "pre-install"

You can even configure your hook to be run before any install or upgrade (see other options here)

metadata:
  annotations:
    "helm.sh/hook": "pre-install, pre-upgrade"

The resources that a hook creates are not tracked or managed as part of the release. Once Tiller verifies that the hook has reached its ready state, it will leave your job resource alone (or you can set a "helm.sh/hook-delete-policy" to delete it).

-- Eduardo Baitello
Source: StackOverflow