Use Secret as Volume¶
Let's see how we can use Secret
as a Volume and mount it in a container.
Step 1: Create a Secret¶
Let's create a Secret
that stores a certificate:
Apply the manifest to create Secret:
Step 2: Verify Secret¶
Step 3: Create Pods That Uses Secret as Volume¶
Let's create pods that uses Secret
as volume and mounts it in a container. We'll use a deployment to create pods:
Observe the following:
- The pod uses the Secret
my-secret
as volume - The volume is mounted at
/config
directory in thenginx
container
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 nginx container:
-
View data:
Please note that when a Secret
is mounted as a volume in a container, each key in the Secret
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: