The following are examples of pod specifications for creating projected volumes.
Example 1. Pod with a secret, a downward API, and a configmap
apiVersion: v1
kind: Pod
metadata:
name: volume-test
spec:
containers:
- name: container-test
image: busybox
volumeMounts: (1)
- name: all-in-one
mountPath: "/projected-volume"(2)
readOnly: true (3)
volumes: (4)
- name: all-in-one (5)
projected:
defaultMode: 0400 (6)
sources:
- secret:
name: mysecret (7)
items:
- key: username
path: my-group/my-username (8)
- downwardAPI: (9)
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
- path: "cpu_limit"
resourceFieldRef:
containerName: container-test
resource: limits.cpu
- configMap: (10)
name: myconfigmap
items:
- key: config
path: my-group/my-config
mode: 0777 (11)
1 |
Add a volumeMounts section for each container that needs the secret. |
2 |
Specify a path to an unused directory where the secret will appear. |
3 |
Set readOnly to true . |
4 |
Add a volumes block to list each projected volume source. |
5 |
Specify any name for the volume. |
6 |
Set the execute permission on the files. |
7 |
Add a secret. Enter the name of the secret object. Each secret you want to use must be listed. |
8 |
Specify the path to the secrets file under the mountPath . Here, the secrets file is in /projected-volume/my-group/my-config. |
9 |
Add a Downward API source. |
10 |
Add a ConfigMap source. |
11 |
Set the mode for the specific projection |
|
If there are multiple containers in the pod, each container needs a volumeMounts section, but only one volumes section is needed.
|
Example 2. Pod with multiple secrets with a non-default permission mode set
apiVersion: v1
kind: Pod
metadata:
name: volume-test
spec:
containers:
- name: container-test
image: busybox
volumeMounts:
- name: all-in-one
mountPath: "/projected-volume"
readOnly: true
volumes:
- name: all-in-one
projected:
defaultMode: 0755
sources:
- secret:
name: mysecret
items:
- key: username
path: my-group/my-username
- secret:
name: mysecret2
items:
- key: password
path: my-group/my-password
mode: 511
|
The defaultMode can only be specified at the projected level and not for each
volume source. However, as illustrated above, you can explicitly set the mode
for each individual projection.
|