ConfigMap

sonu kushwaha
3 min readAug 6, 2021

ConfigMap its also one of the core resources of kubernetes .Its type of centralized storage like the secrets,persistant volume claim(PVC).

CENTRALIZED STORAGES
* secrets -->its for secrets and information( to prevent shoulder hacking)
* PVC --> for data and fileSystem
* ConfigMap -->for configuration files(for central management)

As we all know all the software or service comes with the configuration file , that provides freedom to configure as per one’s usage so let have a look onto one example

so, talking about the web server ie Apache webserver , by default index.php/index.html which is the by default page runs on the port 80 , can be changed as per users choise and the configuration file of the the Apache web server is located at /etc/httpd/conf.d and after making the changes , restart the service “systemctl restart httpd”.

But the above example we discussed is totally manual process . Let talk in context to container orchestration / dynamic OS prespective as the pods ie containers are scheduled on its own with the help of replicaset , once it encounters the pod failure and once the pod that is destroyed on which we had manually changed the configuration files as discussed , the new pod ie launched will have the by default configuration so we need to again change the configuration file on the newly launched pod.

there can be another use case suppose that there is the sudden requirment to change the port of the running service and it becomes the tough/overwhelming job to manually make changes to all the config files of the pods .

so,what we desire is there should be another centralized storage where we can set our own configuration by mounting the storage/volume to the by default configuration folder of that software/service.

Other use Case of configMap:-

  • Config map can also be used to setup the environment variable

lets have some hands on explaination :-

as you can see i have started a pod with httpd image and went inside the pod to find what is the active port number ie active for the pods which clearly shows the port 80 is currently active.

netstat -tnlp

now the below image is the file created with sonu.conf with the following content

now we have created the configmap with the name sonu ,as shown in pic below

now i have edited the yaml of deployment with the name sonu , and i have added the volume section and volume mout section ie highlighted in the image below

so what we gona do is go into the pod and check the ports that are active into the pod , if it shows port 85 then the configmap is succesfully setup

so here its , config map is succesfully setup as port no 85 is also present .

--

--