Helm to deploy a template for different values in one chart

Anand
2 min readMay 14, 2020

This article will talk about how can we use the Helm to deploy the same k8s resource multiple times within one chart without having multiple charts or multiple templates in the same chart.

We are going to use the helm range achieve that.

Example Scenario:

We have to create multiple pvc of different size and name.

Typical way of solving above problem is to create the multiple pvc templates and use it. But other way and I figure out more easy and structured way of doing it with no too much hassle is using helm range functionality and the fact that k8s uses YAML syntax and we can create multiple document in single physical file with — — three(-) delimiter.

Values.yaml file — This file contain the variables for creation of three different pvcs

pvc:
- name: my-pvc-1
storage: 1Gi
sc:
name: standard
- name: my-pvc-2
storage: 2Gi
sc:
name: standard
- name: my-pvc-3
storage: 3Gi
sc:
name: standard

pvc.yaml — PVC template for creation of pvc with above values. The trick lies in below pvc template where we are using — — — (in line no. 2 )

{{- range .Values.pvc }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ .name }}-pvc
namespace: {{ .namespace }}
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: {{ .storage }}
storageClassName: {{…

--

--

Responses (1)