Search code examples
kuberneteskubernetes-helmhelmfile

Helmchart deployment in a specific order


I want to deploy helm chart in a specific order,

I have helm file where i have added multiple helm chart, I want them to deploy in order the of sequence based order which i have defined.

below is my helmFile where i have two helm chart

repositories:
  - name: my-repo
    url: https://myrepo.example.com/charts
  - name: stable
    url: https://kubernetes-charts.storage.googleapis.com
 
 
releases:
  - name: my-release
    chart: stable/mychart
    version: 1.2.3
    values:
      image:
        repository: myrepo/myimage
        tag: "1.0.0"
      db:
        usernameSecret:
          name: db-credentials
          key: username
        passwordSecret:
          name: db-credentials
          key: password
      apiKeySecret:
        name: api-key
        key: key
 
  - name: my-mariadb
    chart: bitnami/mariadb
    version: 9.3.14
    values:
      replicaCount: 1
      auth:
        rootPassword: mypassword
 
secrets:
  - name: db-credentials
    type: Opaque
    data:
      username: YWRtaW4=
      password: MWYyZDFlMmU2N2Rm
  - name: api-key
    type: Opaque
    data:
      key: Zm9vYmFy
 
 
environments:
  dev:
    values:
    - values-dev.yaml
  staging:
    values:
    - values-staging.yaml
  prod:
    values:
    - values-prod.yaml

in case if i have multiple chart how to control the installisation sequence


Solution

  • You can do this with the needs keyword. If in your example, you wanted "my-mariadb" to be installed first and then "my-release", it would look like this:

    releases:
      - name: my-release
        chart: stable/mychart
        version: 1.2.3
        needs: 
        - my-mariadb
        values:
          image:
            repository: myrepo/myimage
            tag: "1.0.0"
          db:
            usernameSecret:
              name: db-credentials
              key: username
            passwordSecret:
              name: db-credentials
              key: password
          apiKeySecret:
            name: api-key
            key: key
     
      - name: my-mariadb
        chart: bitnami/mariadb
        version: 9.3.14
        values:
          replicaCount: 1
          auth:
            rootPassword: mypassword
    

    The documentation for this feature is here:

    https://helmfile.readthedocs.io/en/latest/#dag-aware-installationdeletion-ordering-with-needs