Use ConfigMap as Volume¶
Let's see how we can use ConfigMap as a volume and mount it in a container.
Step 1: Create a ConfigMap¶
Apply the manifest to create ConfigMap:
Step 2: Verify ConfigMap¶
Step 3: Create Pods That Uses ConfigMap as Volume¶
Let's create pods that uses ConfigMap as volume and mounts it in a container. We'll use a deployment to create pods:
Observe the following:
- The pod uses the ConfigMap
my-configmapas volume - The volume is mounted at
/configdirectory in thenginxcontainer
Apply the manifest to create deployment:
Step 4: Verify Deployment and Pods¶
Step 5: Verify Volume Mount and Data¶
-
Open a shell session inside the
nginxcontainer: -
View data:
Please note that when a ConfigMap is mounted as a volume in a container, each key in the ConfigMap is stored as a file in the container's file system. This means that the container can read the contents of each file as if they were regular files in the container's file system.
Clean Up¶
Assuming your folder structure looks like the one below:
Let's delete all the resources we created: