ConfigMap — Kubernetes

Always learning
3 min readNov 20, 2023

Configmaps allow you to decouple configuration artifacts from images.

Portability of Containers.

ConfigMap create a ways

  1. From Files & folders — from-file
  2. From Literals — from-literals
  3. Mounting ConfigMaps as Volumes

First create a two file using ConfigMaps

Check any configmaps is created?

kubectl get configmaps

Create a ConfigMaps file

kubectl create configmap myconfig --from-file=game.properties
kubectl get configmaps
kubectl describe configmap myconfig

Folder via created to configmaps

kubectl create configmap myconfig-02 --from-file=.
kubectl describe configmap myconfig-02

Creating ConfigMaps using literals

kubectl create configmap literal-config --from-literal=mykey=myval --from-literal=myname=IbrahimS
kubectl get configmaps
kubectl describe configmap literal-config

Creating ConfigMaps using YAML

apiVersion: v1
kind: ConfigMap
metadata:
name: spec-configmap
data:
game.properties:
enemies=aliens
lives=3
cheatcode=testing
kubectl create -f spec-config.yml
kubectl get configmaps
kubectl describe configmap spec-config

Kubernetes will auto create a spec file for resources created using command line

kubectl get configmaps myconfig -o yaml

Using configmaps in pods

Create a pod.yml

apiVersion: v1
kind: Pod
metadata:
name: my-configmap-pod
spec:
containers:
- name: myctr
image: busybox
command: ['sh', '-c', 'echo-$(MY_VAL)']
env:
-name: MY_VAL
valueFrom:
configMapKeyRef:
name: literal-config
key: myName
kubectl describe configmap literal-config

Create a pod

kubectl create -f pod.yml 
kubectl get pods

Facing some issue will fix the issue tomorrow…

--

--

Always learning

கற்றுக் கொள்ளும் மாணவன்...