How to pass different confimap map values in helm chart kubernetes for different services?

Viewed 1103

we have 9 microservices in our application. In this all the services have same yaml manifest file(deployment, service and configmap(to supply environment variable to containers)).

But when we try to get it as helm template. We couldn't able to pass different environment variable for different services.

We have been using same template by having different values.yaml file for different service. Is there any way to support different environment variables using same configmap.

1 Answers

a helm chart acts as a collection of templates, which you can (re-)use to deploy multiple services, especially in a microservices context.

you configure different deployments (and therefore different environments) with the same helm chart by providing values-files during installation, which contain the configuration that should be applied during installation.

values.yaml in the helm chart folder:

service:
  port: 123

microservice-a-values.yaml provided during installation:

service:
  port: 456

configmap template in the helm charts templates/ folder:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: "{{ .Release.Name }}"
data:
  port: {{ .Values.service.port }}

to run the installation and actually use the microservice-a-values.yaml, provide it when calling the helm install:

helm upgrade --install microservice-a --values microservice-a-values.yaml

remember that there is a "hierarchy" of provided values files: the last one wins and overwrites the previous ones.

Related