- Take me to Video Tutorial
In this section, we will take a look at configuring configmaps in applications
- There are 2 phases involved in configuring ConfigMaps.
- First, create the configMaps
- Second, Inject then into the pod.
- There are 2 ways of creating a configmap.
-
The Imperative way
$ kubectl create configmap app-config --from-literal=APP_COLOR=blue --from-literal=APP_MODE=prod $ kubectl create configmap app-config --from-file=app_config.properties (Another way)
-
The Declarative way
apiVersion: v1 kind: ConfigMap metadata: name: app-config data: APP_COLOR: blue APP_MODE: prod
Create a config map defination file and run the 'kubectl create` command to deploy it. $ kubectl create -f config-map.yaml
-
-
To view configMaps
$ kubectl get configmaps (or) $ kubeclt get cm
-
To describe configmaps
$ kubectl describe configmaps
-
Inject configmap in pod
apiVersion: v1 kind: Pod metadata: name: simple-webapp-color spec: containers: - name: simple-webapp-color image: simple-webapp-color ports: - containerPort: 8080 envFrom: - configMapRef: name: app-config
apiVersion: v1 kind: ConfigMap metadata: name: app-config data: APP_COLOR: blue APP_MODE: prod
$ kubectl create -f pod-defination.yaml
- https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/
- https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#define-container-environment-variables-using-configmap-data
- https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#create-configmaps-from-files