ConfigMaps - Setting ConfigMaps From The Oc CLI
ConfigMaps - Setting ConfigMaps From The Oc CLI
FYI; This blog is written for OpenShift but for most command’s oc and kubectl are
interchangeable.
In this blog I’ll talk about creating ConfigMap’s and how to mount and use them.
The command’s for secrets look a lot like these but I’ll save that for some other
time.
Namespace
Deployment
Creates
Manages
Supplies Data
Supplies Data
ReplicaSet
Deployment
Pod
ConfigMap: application-env
ConfigMap: application-config
Preparing the environment
So, if not clear already, you can do this on you own cluster or local K3s setup. We
will use the bintami/nginx image as Deployment because it’s nice and easy
$ oc new-project configmaps-demo
$ oc new-app --name super-app --docker-image bitnami/nginx
This should resolve in a running nginx container called super-app:
$ oc get pods
NAME READY STATUS RESTARTS AGE
super-app-67b7c69cfb-v5rr7 1/1 Running 0 8
Creating the ConfigMap’s
We will create 2 config maps for this example:
When mounting a volume to a pod all data on the mount path will be made
inaccessible. This means that any files present at /mount/config/application-config
will not show up in your pod
$ oc get pods
NAME READY STATUS RESTARTS AGE
super-app-67b7c69cfb-v5rr7 1/1 Running 0 7m8s
$ oc rsh super-app-67b7c69cfb-v5rr7 bash
No we can cat the mounted file:
$ oc get pods
NAME READY STATUS RESTARTS AGE
super-app-79fc5bf5df-zsjlg 1/1 Running 0 12m
$ oc get pods super-app-79fc5bf5df-zsjlg -o yaml | grep mountPath -A 2
- mountPath: /mount/config/application-config
name: volume-qcxd4
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: kube-api-access-wddx2
readOnly: true
ConfigMaps and multible keys
Please note that the config is being mounted as config.txt. This is because when we
created the ConfigMap from file we did not asigne the contents of the file to a
key. When you oc describe the config map you can see that the contents has been
“keyed” to config.txt:
Data
====
config.txt:
----
I am your config
If we wanted to mount multible files we could add more key value pairs to a single
config map like:
Data
====
config.txt:
----
I am your config
list.txt:
----
I am your list
users.txt:
----
I am your users
Events: <none>
And mount it to the pod (on a different path):