I am new to Helm and I want to create multiple deployments in k8s from a single deployment YAML file. I’ve used a placeholder in the deployment.yaml like
metadata:
name: job-{{ .Values.app.ujn }}
...
replicas: {{ .Values.app.replicas }}
and my values.yaml looks like
app:
replicas: 10
ujn: 1
---
app:
replicas: 20
ujn: 2
---
app:
replicas: 30
ujn: 3
The use case is something like that I want to create many deployment files with similar configuration but some params changed and I also don’t want to make multiple values file for each deployment. Can I do something like that in the above example and create multiple files from a single values.yaml?
Also a follow up question, if I deploy this chart on the cluster and if I modify the number of deployments in next deploy, will helm delete the old ones or do those have to be deleted manually?
The syntax you have puts multiple YAML documents into a single file. It’s unusual for tools to support this well (though
kubectl apply
and the output of Helm templates do support it); the most common case is that a toll will only read the first document.Instead of having multiple documents, you can put a YAML list into the values file.
Then in your template file, you can use a
range
loop to loop over this. Here Helm does support multiple documents in a single output stream, so you need to make sure each template begins with the YAML start-of-document marker. Also remember that therange
loop rebinds.
so you may need different syntax for the top-level Helm objects like.Values
or.Release
, or if you call a helper template.