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.




React Developer & DevOps Engineer @HBK

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

Recommended from Medium

CS371p Fall 2021 Week 5: Kevin Chen

Build a realtime comment app with Go and Pusher Channels

Search engine optimization

Transcript of Indigitus AMA on the Sentinel Telegram Group, Hosted by Dan from Exidio

Elasticsearch is neither free nor open

Let’s Cure Blindness (AI in Unity)

Installing SSL Certificate for GeoServer/Jetty

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

React Developer & DevOps Engineer @HBK

More from Medium

Learning note for Kubernetes - Basic command cheat sheet

GitOps Fundamentals with Codefresh

How to manage all my K8s secrets in git securely with Bitnami sealed secrets

Practical example of how to set requests and limits on Kubernetes