Member-only story

ENV variables in Kubernetes (Secrets)

Ishan Liyanage
3 min readDec 20, 2020

--

I suggest you first go thru my previous article on environment variables with config maps.

Config Maps are better way to specify environment variables. However assume below scenario.

You have a web application and it will connect to MySQL database. In a basic scenario you will need MySQL hostname, port, user and password to connect. Where do you store these sensitive values?

We can use config maps. However it will store data in plain text format. It would be ok to store hostname and port there, but it is definitely not a good practice to store username and password.

This is where Secretes comes in to place. Secrets are designed to store sensitive data like usernames and passwords. They are similar to config map but data are stored in encoded format.

There are two phases when configuring ConfigMap

  1. Create the Secrets.
  2. Inject in into the POD.

Just like any other Kubernetes object, we can create secrets either using imperative way or using definition file (declarative way).

Imperative way (command line)

--

--

Ishan Liyanage
Ishan Liyanage

Written by Ishan Liyanage

Passionate Technical Lead, Senior Software Developer and free and open source software advocate. Based in Singapore.

No responses yet

Write a response