ConfigMap in kubernetes: Use case

In this blog, i will show you from very basic how to use config map on kubernetes.

In reference to official documentation, config map is used to setting up configuration file data separately from application. Basically, is an API object used to stored data in key-value pair format.

For more details, go an check the official documentation:

For example, you want to create a pod with apache web server that you can run on top of kubenetes ec2 instances. Your plan is to manage config file by updating apache port number.

In this blog, we are going to create a pod with httpd service running and implement configmap to update port number.

let’s start with implementation part:

  • Run kubernetes ec2 instance

Connect to your amazon aws account. Go to EC2 services and launch instance.

Choose kubernetes_base_setup_image in community AMI from Mumbai region .

Follow all step to run images. make sure to create a key pair for remote connection.

  • Remote connection to ConfigMaps instance

Use putty for remote connection

Before performing all the above task, make sure to initialize your kubernetes master nodes.

For more details, go and check

Use a following command to print or list table of pods and deployment

kubectl get pods 

This command list all pods in a ps output format

kubectl get deploy

this command list all deployment in a ps output format

List configmap table by using this command

kubectl get configmap

Launch a deployment pods with my docher image: komlan2019/httpd-rhel:v3

kubectl create deploy mypod --image=komlan2019/httpd-rhel:v3
  • Connect to the pods

Use “kubectl exec” command to connect to your pods

kubectl get pods
kubectl exec -it mypod-6d686d4785-hf5tp -- bash

Notice with netstat command, apache web server is running on port 80

  • create configmap configuration file

Check configuration file set up successfully

Edit deployment file

Add the following line

Notice after save file, pods will terminated and another pods will be launch with configuration file “web.conf” load into /etc/httpd/conf.d/

Connect to a new pods and notice web.conf file successfully add to conf.d repository. Netstat command gives details about httpd open port. Notice httpd services listen on port number 90.

Thanks for your reading !!!!!!!!!!!!

Cloud / Cybersecurity enthusiast. CehV10, RHCSA, RHCE, Comptia Sec +, ITF +, AWS Architect