Using Environment variables in helm chart with config maps


In the last post we discussed how to pass environment variables to a docker image from Kubernetes pod manifest. So continuing where we left off, In this post we will be using environment variables with Config maps in helm charts. We will create a Helm Chart & see how we can use environment variable with config map & use them in our docker image.

For full code refer this repository



  1. Create a folder named helmchart. Directory structure will look like this:
|-- |--config.yaml
|-- |--pod.yaml

2. Create helmchart/Chart.yaml

This file provides the metadata about the chart to your definitions such as name, description, version.

3. Create helmchart/values.yaml

This file contains the configuration value- message in this case. These values can then be used in templates file by using syntax {{ .Values.message }}

4. Create helmchart/templates/config.yaml

Here we create a ConfigMap where we use the value of message from values.yaml

5. Create helmchart/templates/pod.yaml

This file contains the pod configuration. We are using the image yg18/website for our container. We are passing environment variable which is using the value from config.yaml which specifies the message value as environment variable.

6. Run the following commands to install helm chart & deploy the chart to minikube:

  • Start minikube & Install the helm application
minikube start
kubectl config use-context minikube
helm install <app-name> <chart-name>
helm install mypod helmchart/
  • View the chart and pod created in minikube
kubectl get pods
helm ls
  • Port forward the pod to view the application in localhost:3001
kubectl port-forward <podName> 3001:3000kubectl port-forward helm-practice-1 3001:3000
  • Now we see the message we set in values.yaml in our running application. Now let’s change the message value in values.yaml & redeploy the pod.
helm upgrade mypod .kubectl delete pod helm-practice-1

We deleted the pod because image was using the earlier value of message. Restarting the pod will get the latest value from the ConfigMap & rerun the pod with latest value


In this post you learned about how to create Helm Charts & use environment variables in ConfigMap & pass the values over to Pod manifest to be used by the docker image.




DevOps | Kubernetes | Docker | ReactJS | SDE @HBK

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

RAMP GENERATOR A sweep circuit is a time base circuit that is used to generate ramp waveform.

SQL Query Writing (PART V)

Extraterm+Docker: Azure CLI on-demand

Write Your Own RSA Encryption Tool — Part 1 starting with theory

What learning to code taught me about life

Thanks to StartupStockPhotos on Pixabay:

Comprehensive Guide To Styling a GitHub README

Cascading Laravel Factories

Duet Protocol Weekly Updates

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yash Gupta

Yash Gupta

DevOps | Kubernetes | Docker | ReactJS | SDE @HBK

More from Medium

How to Deploy FileBeat to a Kubernetes cluster

Kubernetes deployment YAML Walkthrough

Learn Kubernetes: Creation of a pod running a Nginx server

Configure traefik to use your own existing SSL certificate in kubernetes