Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to loop different templates in Helm for Kubernetes?

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?

like image 266
Math is Hard Avatar asked Jan 19 '26 22:01

Math is Hard


1 Answers

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 }}
like image 199
David Maze Avatar answered Jan 22 '26 17:01

David Maze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!