Helm chart deployment ordering

11/23/2019

I created a new chart with 2 podPresets and 2 deployments and when I go to run helm install the deployment(pod) object is created first and then podPresets hence my values from podPreset are not applied to the pods, but when I manually create podPreset first and then deployment the presets are applied properly, Is there a way I can specify in helm as to which object should be created first.

-- Nikhil Soni
kubernetes
kubernetes-helm
kubernetes-pod

2 Answers

12/3/2019

Posting this as Community Wiki for better visibility as answer was provided in comments below another answer made by @Rastko.

PodPresents

A Pod Preset is an API resource for injecting additional runtime requirements into a Pod at creation time. Using a Pod Preset allows pod template authors to not have to explicitly provide all information for every pod. This way, authors of pod templates consuming a specific service do not need to know all the details about that service.

For more information, please check official docs.

Order of deploying objects in Helm

Order of deploying is hardcoded in Helm. List can be found here.

In addition, if resource is not in the list it will be executed as last one.

Answer to question from comments*

Answer to your question - To achieve order different then default one, you can create two helm charts in which one with deployments is executed afterwards with preinstall hook making sure that presets are there.

Pre-install hook annotation allows to execute after templates are rendered, but before any resources are created.

This workaround was mentioned on Github thread. Example for service:

apiVersion: v1
kind: Service
metadata:
  name: foo
  annotations:
    "helm.sh/hook": "pre-install"

As additional information, there is possibility to define weight for a hook which will help build a deterministic executing order.

  annotations:
    "helm.sh/hook-weight": "5"

For more details regarding this annotation, please check this Stackoverflow qustion.

-- PjoterS
Source: StackOverflow

11/23/2019

Since you are using Helm charts and have full control of this part, why not make optional parts in your helm charts that you can activate with an external value?

This would be a lot more "Helm native" way:

{{- if eq .Values.prodSecret "enabled"}}
      - name: prod_db_password
        valueFrom:
          secretKeyRef:
            name: prod_db_password
            key: password
{{- end}}

Then you just need to add --set prodSecret=enabled when executing your Helm chart.

-- Rastko
Source: StackOverflow