Skip to content

Multi apps for multi envs

If you want to manage a group of releases for several environments. This example will render all apps and all settings for all environments.

We can use one of two name conventions

  • 🤔 values/$app/$env.yml
  • 🤔 values/$env/$app.yml

But if we add some regions we will have

  • values/$app/$env/$region.yml
  • values/$app/$region/$env.yml
  • values/$region/$env/$app.yml
  • values/$region/$app/$env.yml
  • values/$env/$region/$app.yml
  • values/$env/$app/$region.yml

We see that next name convention is more suitable than others

  • values/$region/$env/$app.yml
  • values/$env/$region/$app.yml

Now we are dropping $region

  • values/$env/ $region /$app.yml –> values/$env/$app.yml
  • values/ $region /$env/$app.yml –> values/$env/$app.yml

Then the best name convention is 👍values/$env/$app.yml

This is also a good way when you will write your policy like:

prod/* @DevOps @SecOps
dev/* @Developers

Create the project

Project structure

docs/examples/multi-apps-multi-envs
├── README.md
├── envs.yml
├── helmwave.yml
├── helmwave.yml.tpl
└── values
    ├── _
       ├── _.yml
       ├── prod.yml
       ├── qa.yml
       └── stage.yml
    ├── my-app-a
       └── prod.yml
    ├── my-app-b
       ├── _.yml
       ├── prod.yml
       └── stage.yml
    └── my-app-c
        ├── _.yml
        ├── prod.yml
        ├── qa.yml
        └── stage.yml

5 directories, 16 files
helmwave.yml.tpl
version: "0.32.3"

{{- defineDatasource "envs" "envs.yml" }}
{{- $envs := (ds "envs") }}

# general options for all releases
.options: &options
  wait: true
  wait_for_jobs: true
  force: false
  chart: some-chart
  atomic: false
  max_history: 3
  create_namespace: true
  offline_kube_version: 1.25
  pending_release_strategy: rollback


releases:
  {{- range $env, $settings := $envs}}
  ###############################
  #                             #
  #       {{ $env }}
  #                             #
  ###############################
  {{- range $app := (file.ReadDir "./values") }}
  {{- if ne $app "_" }}
  {{- if has $settings.releases $app}}
  # use next command to deploy: helmwave up --build -t {{ $app }} -t {{ $env }}
  - name: {{ $app }}
    namespace: {{ $env }}
    timeout: {{ $settings.timeout }}
    kubecontext: {{ $settings.kubecontext }}
    values:
      - _/_.yml # values for all envs & all apps
      - _/{{ $env }}.yml # default values for specific env
      - {{ $app }}/_.yml # default values for an application
      - {{ $app }}/{{ $env }}.yml # values for specific application and specific env
    tags: [{{ $app }}, {{ $env }}]
    <<: *options
  {{- end }}
  {{- end }}
  {{ end }}
  {{ end }}
envs.yml
prod:
  kubecontext: prod-kube-context
  timeout: 10m
  releases:
    my-app-a: {}
    my-app-b: {}
    my-app-c: {}

stage:
  kubecontext: stage-kube-context
  timeout: 4m
  releases:
    my-app-b: {}
    my-app-c: {}

qa:
  kubecontext: qa-kube-context
  timeout: 4m
  releases:
    my-app-c: {}

Build

helmwave yml --templater gomplate 
helmwave.yml
version: "0.32.3"

# general options for all releases
.options: &options
  wait: true
  wait_for_jobs: true
  force: false
  chart: some-chart
  atomic: false
  max_history: 3
  create_namespace: true
  offline_kube_version: 1.25
  pending_release_strategy: rollback


releases:
  ###############################
  #                             #
  #       prod
  #                             #
  ###############################
  # use next command to deploy: helmwave up --build -t my-app-a -t prod
  - name: my-app-a
    namespace: prod
    timeout: 10m
    kubecontext: prod-kube-context
    values:
      - _/_.yml # values for all envs & all apps
      - _/prod.yml # default values for specific env
      - my-app-a/_.yml # default values for an application
      - my-app-a/prod.yml # values for specific application and specific env
    tags: [my-app-a, prod]
    <<: *options


  # use next command to deploy: helmwave up --build -t my-app-c -t prod
  - name: my-app-c
    namespace: prod
    timeout: 10m
    kubecontext: prod-kube-context
    values:
      - _/_.yml # values for all envs & all apps
      - _/prod.yml # default values for specific env
      - my-app-c/_.yml # default values for an application
      - my-app-c/prod.yml # values for specific application and specific env
    tags: [my-app-c, prod]
    <<: *options

  # use next command to deploy: helmwave up --build -t my-app-b -t prod
  - name: my-app-b
    namespace: prod
    timeout: 10m
    kubecontext: prod-kube-context
    values:
      - _/_.yml # values for all envs & all apps
      - _/prod.yml # default values for specific env
      - my-app-b/_.yml # default values for an application
      - my-app-b/prod.yml # values for specific application and specific env
    tags: [my-app-b, prod]
    <<: *options


  ###############################
  #                             #
  #       qa
  #                             #
  ###############################


  # use next command to deploy: helmwave up --build -t my-app-c -t qa
  - name: my-app-c
    namespace: qa
    timeout: 4m
    kubecontext: qa-kube-context
    values:
      - _/_.yml # values for all envs & all apps
      - _/qa.yml # default values for specific env
      - my-app-c/_.yml # default values for an application
      - my-app-c/qa.yml # values for specific application and specific env
    tags: [my-app-c, qa]
    <<: *options



  ###############################
  #                             #
  #       stage
  #                             #
  ###############################


  # use next command to deploy: helmwave up --build -t my-app-c -t stage
  - name: my-app-c
    namespace: stage
    timeout: 4m
    kubecontext: stage-kube-context
    values:
      - _/_.yml # values for all envs & all apps
      - _/stage.yml # default values for specific env
      - my-app-c/_.yml # default values for an application
      - my-app-c/stage.yml # values for specific application and specific env
    tags: [my-app-c, stage]
    <<: *options

  # use next command to deploy: helmwave up --build -t my-app-b -t stage
  - name: my-app-b
    namespace: stage
    timeout: 4m
    kubecontext: stage-kube-context
    values:
      - _/_.yml # values for all envs & all apps
      - _/stage.yml # default values for specific env
      - my-app-b/_.yml # default values for an application
      - my-app-b/stage.yml # values for specific application and specific env
    tags: [my-app-b, stage]
    <<: *options