Configure volumes for multiple uses in a pod
You can configure a volume to share one volume for
multiple uses in a single pod by using the volumeMounts.subPath property to specify a subPath value inside a volume
instead of the volume’s root.
|
|
You cannot add a |
Procedure
-
To view the list of files in the volume, run the
oc rshcommand:$ oc rsh <pod>Example outputsh-4.2$ ls /path/to/volume/subpath/mount example_file1 example_file2 example_file3 -
Specify the
subPath:ExamplePodspec withsubPathparameterapiVersion: v1 kind: Pod metadata: name: my-site spec: securityContext: runAsNonRoot: true seccompProfile: type: RuntimeDefault containers: - name: mysql image: mysql volumeMounts: - mountPath: /var/lib/mysql name: site-data subPath: mysql securityContext: allowPrivilegeEscalation: false capabilities: drop: [ALL] - name: php image: php volumeMounts: - mountPath: /var/www/html name: site-data subPath: html securityContext: allowPrivilegeEscalation: false capabilities: drop: [ALL] volumes: - name: site-data persistentVolumeClaim: claimName: my-site-datawhere:
spec.containers.volumeMounts.subPath.mysql-
Specifies that databases are stored in the
mysqlfolder. spec.containers.volumeMounts.subPath.html-
Specifies that HTML content is stored in the
htmlfolder.