I am trying to run a application that has around 40 microservices. How to pass 40 different docker images from values.yml file to template.yml file.
name:{{ .values.name }}
spec:
containers:
- image: {{ .values.container.image }}
values file
name:A
container:
image:A
name :B
container :
image:B
i have 40 more docker images like that, how to pass all those images to template. And will passing like that creates 40 different pods?, because we would need 40 different pods. Any guidance is highly appreciated.
Focusing only on images and templates you can create a helm template that will spawn an X amount of pods by:
Chart.yaml file values.yaml file with the variable that store all image names{{ range }} directive Below is the structure of files and directories:
❯ tree helm-dir
helm-dir
├── Chart.yaml
├── templates
│ └── pod.yaml
└── values.yaml
1 directory, 3 files
Chart.yaml fileBelow is the Chart.yaml file:
apiVersion: v2
name: helm-templates
description: A Helm chart for spawning pods from images
version: 0.1.0
values.yaml file with the variable that store all image namesBelow is the simple values.yaml file with different images name that will be used with a template:
different_images:
- ubuntu
- nginx
{{ range }} directiveThis template is stored in templates directory with a name pod.yaml
Below YAML definition will be a template for all the pods:
{{- range .Values.different_images }}
apiVersion: v1
kind: Pod
metadata:
name: {{ . }}
labels:
app: {{ . }}
spec:
restartPolicy: Never
containers:
- name: {{ . }}
image: {{ . }}
imagePullPolicy: Always
command:
- sleep
- infinity
---
{{- end }}
{{- range .Values.different_images }} will iterate over different_images variable and replace the {{ . }} with an image name.
Run below command from helm-dir directory to check if helm YAML definitions of pods are correctly created:
$ helm install NAME . --dry-run --debug
You should get an output with multiple pods definition that look similar to one below:
# Source: helm-templates/templates/pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: ubuntu
labels:
app: ubuntu
spec:
restartPolicy: Never
containers:
- name: ubuntu
ports:
- containerPort: 3000
image: ubuntu
imagePullPolicy: Always
command:
- sleep
- infinity
resources:
requests:
memory: 500Mi
cpu: 500m
You can now run:
$ helm install NAME .
and check if pods spawned correctly with $ kubectl get pods:
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 8s
ubuntu 1/1 Running 0 8s
Please take a look on additional resources:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With