ConfigMaps
A ConfigMap is an API object used to store non-confidential data in key-value pairs. Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume.
A ConfigMap allows you to decouple environment-specific configuration from your container images so that your applications are easily portable. The size of the individual configmap is limited to 1mb, according to kubernetes.io
Creating config map using command
kubectl create cm cm1 --from-literal=database_ip="x.x.x.x"
we can describe the config map using
kubectl describe cm cm1
we also can pass multiple values for the command as well
kubectl create cm cm1 --from-literal=database_ip="x.x.x.x" --from-literal=user="user1" --from-literal=paaword="xxxxx"
Creating config map using yaml file
mkdir configmap
vi application.properties
database_ip="x.x.x.x"
database_user="user1"
database_password="xxxxxx"
kubectl create cm cm3 --from-file=application.properties
kubectl describe cm cm3
Note - Here we can see the values in key value format
We also can we can specify multiple config files for one config map, and it will add two data into a single config map
Let's create one more application.properties file
vi adminapplication.properties
admin_user="user1"
admin_password="xxxxxx"
now, we can use the below command to create one config map with multiple application properties file values, for this example, we are using the above two application.properties file
kubectl create cm cm4 --from-file=application.properties --from-file=adminapplication.properties
what if we have multiple applications.properties, like 40 applications.properties file into one single folder. Then in that case we can use below command to create config map using multiple files
kubectl create cm cm5 --from-file=foldername/
in the above example we have a specified folder of application.properties in which we have multiple application.properties file. So now the newly created cm5 config map will have all the config values which are presented in the folder