Learn Kubernetes: ConfigMap — Inject the values of a ConfigMap in a container as a volume
Published in
3 min readFeb 21, 2022
In this series of stories, you will learn how to use Kubernetes. Today, let’s inject the values of a ConfigMap in a container as a volume.
After this story, you can read the following stories:
- Storing configuration in ConfigMap,
- Inject the values of a ConfigMap in a container as environment variables,
- Inject the values of a ConfigMap in a container as a volume,
- Multiple ways to modify a ConfigMap,
- Two solutions to update the deployment following a change in the ConfigMap.
In first, let’s store the Nginx configuration file nginx.conf
in a ConfigMap:
kubectl create configmap nginx-config --from-file=./nginx.conf
If the command succeeds, the output is:
configmap/nginx-config created
Confirm that the contents of the nginx.conf
file are in the data:
section of the ConfigMap:
kubectl get cm nginx-config -o yaml
The output is similar to:
apiVersion: v1
data:
nginx.conf: |
server {
listen 80;root /usr/share/nginx/html;
}
kind: ConfigMap
metadata:
creationTimestamp: "2022-02-21T09:46:18Z"
managedFields:
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
f:data:
.: {}…