gbt
gbt

Reputation: 49

helm single template for multiple similar deployments

Apologies if this is a really simple question

I have a 2 applications that can potentially share the same template

applications:
  #
  app1:
    containerName: app1
    replicaCount: 10
    logLevel: warn
    queue: queue1
  #
  app2:
    containerName: app2
    replicaCount: 20
    logLevel: info
    queue: queue2
  ...

If I create a single template for both apps, is there a wildcard or variable i can use that will iterate over both of the apps (i.e. app1 or app2) ? ...e.g. the bit where ive put <SOMETHING_HERE> below ...

spec:
    env:
    - name: LOG_LEVEL
      value: "{{ .Values.applications.<SOMETHING_HERE>.logLevel }}"

Currently (which im sure is not very efficient) I have two seperate templates that each define their own app .e.g

app1_template.yaml

{{ .Values.applications.app1.logLevel }} 

app2_template.yaml

{{ .Values.applications.app2.logLevel }}

Which im pretty sure is not the way Im supposed to do it?

any help on this would be greatly appreciated

Upvotes: 1

Views: 1923

Answers (2)

jonnybinthemix
jonnybinthemix

Reputation: 727

You can just use a single values file as you've done, and then set the app name when you run helm..

helm upgrade --install app1 ./charts --set app=app1

and

helm upgrade --install app2 ./charts --set app=app2

Then in your templates use:

spec:
    env:
    - name: LOG_LEVEL
      value: "{{ .Values.applications (.Values.app) "loglevel" }}"

Upvotes: 0

mehowthe
mehowthe

Reputation: 841

One of the solutions would be to have one template and multiple value files, one per deployment/environment

spec:
    env:
    - name: LOG_LEVEL
      value: "{{ .Values.logLevel }}"

values-app1.yaml:

containerName: app1
replicaCount: 10
logLevel: warn
queue: queue1

values-app2.yaml:

containerName: app2
replicaCount: 20
logLevel: info
queue: queue2

then, specify which values file should be used, by adding this to helm command:

APP=app1 # or app2

helm upgrade --install . --values ./values-${APP}.yaml

you can also have shared values, let say in regular values.yaml and provide multiple files:

APP=app1

helm upgrade --install . --values ./values.yaml --values ./values-${APP}.yaml

Upvotes: 2

Related Questions