2

I want to deploy multiple Deployments of Pods with different images, ports, etc. but with very similar other properties. So I want to declare a single deployment.yaml file that looks something like this

{{- range .Values.types }}
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
...
{{- end }}

Where my values.yaml is

types:
  - foo
  - bar
  - baz

However, this only spins up a single Kubernetes Deployment when I helm install because everything is in one template file. Any ideas on how to do this?

Community
  • 1
  • 1
Math is Hard
  • 896
  • 1
  • 12
  • 24
  • Possible duplicate of [loop in go helm chart templating](https://stackoverflow.com/questions/47762628/loop-in-go-helm-chart-templating) – Lukas Eichler Mar 14 '19 at 09:09

1 Answers1

7

Kubernetes generally uses YAML syntax, and that allows multiple "documents" to be in a single physical file with a --- delimiter before each one. Helm in turn generally operates by applying the templating to produce a plain-text file and in effect feeding it to kubectl apply.

The upshot of this is that if you start each Kubernetes object description with the --- start-of-document delimiter, it should work:

{{- range .Values.types }}
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
...
{{- end }}
David Maze
  • 130,717
  • 29
  • 175
  • 215