Kubernetes-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.
LAB
1. Creating Configmap from "multiple files" & Consuming it inside Pod from "volumes"
1a. Create Configmap "nginx-configmap-vol" from "multiple files":
------------------------------------------------------------------
echo -n 'Properties for Staging env' > web_stag.xml
echo -n 'Properties for Prod env' > web_prod.xml
kubectl create configmap nginx-configmap-vol --from-file=web_stag.xml --from-file=web_prod.xml
# rm *
- kubectl get configmaps
- kubectl get configmaps nginx-configmap-vol -o yaml
- kubectl describe configmaps nginx-configmap-vol
1b. Consume above "nginx-configmap-vol" configmap inside Pod from "volumes"
==========================================================
1c. Create | Display | Validate:
--------------------------------
Create
kubectl create -f nginx-pod-configmap-vol.yaml
Display
kubectl get po
kubectl get configmaps
kubectl describe pod nginx-pod-configmap-vol
Validate from "inside" the pod
kubectl exec nginx-pod-configmap-vol -it -- bash
cd /etc/non-sensitive-data
ls
cat web.xml
exit
(OR)
# Validate from "outside" the pod
kubectl exec nginx-pod-configmap-vol ls /etc/non-sensitive-data
kubectl exec nginx-pod-configmap-vol cat /etc/non-sensitive-data/web.xml
*************************************************************************************************************************************************
2. Creating Configmap from "literal values" & Consuming it inside Pod from "environment variables"
2a. Create configmap “redis-configmap-env” from "literal values"
-----------------------------------------------------------------
kubectl create configmap redis-configmap-env --from-literal=stagenv=stagenvvalue --from-literal=prodenv=prodenvvalue
kubectl get configmap
kubectl describe configmap redis-configmap-env
===============================================================================
2b. Consume “redis-configmap-env” configmap inside pod from “Environment Variables” inside pod
2c. Create | Display | Validate:
# Create
kubectl create -f redis-pod-configmap-env.yaml
# Display
kubectl get pods
kubectl get configmaps
kubectl describe pod redis-pod-configmap-env
# Validate from "inside" the pod
kubectl exec -it redis-pod-configmap-env -- env
(OR)
# Validate from "outside" the pod
kubectl exec redis-pod-configmap-env -- env
Try Your Self
kubectl create -f podcm.yaml
3. Cleanup
# Delete configmaps
kubectl delete configmaps nginx-configmap-vol redis-configmap-env
# Delete pods
kubectl delete pods nginx-pod-configmap-vol redis-pod-configmap-env
# Validate
kubectl get pods
kubectl get configmaps
Comments
Post a Comment