
If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.
A Persistent Volume (PV) is the "physical" volume (such as a hard disk drive or solid state drive) on the host machine (node) that stores your persistent data, whereas a Persistent Volume Claim (PVC) is a reference to a persistent volume, used by a pod. A Shared Volume contains both a Persistent Volume and a Persistent Volume Claim and is typically used for an Amazon Web Services (AWS) Elastic File System (EFS).
The oc get sharedvolumes (or oc get sv) command will return the list of Shared Volumes.
~]$ oc get sharedvolumes
AME FILE SYSTEM ACCESS POINT PHASE CLAIM MESSAGE
my-shared-volume fs-07b736fc4cf1bb6a5 fsap-04e274b343f1de096 Ready pvc-my-shared-volume
The volumes and volumeMounts options can be used to mount a shared volume in a container. Here is what you could have in your deployment YAML file.
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
template:
spec:
containers:
- name: my-deployment
image: openshift-image-registry.svc:5000/my-deployment:latest
volumeMounts:
- mountPath: /var/data
name: my-volume
volumes:
- name: my-volume
persistentVolumeClaim:
claimName: my-shared-volume
Assuming the volume was successfully mounted, the oc exec command can be used to validate that the volume has been mounted in the pod. Notice in this example that the /var/data directory that was mounted is owned by 99 instead of root, as an indication that /var/data is a mounted volume.
~]$ oc exec pod/my-pod-hp5w4 -- ls -l /var
total 4
drwxr-xr-x. 2 root root 6 Apr 23 2020 adm
drwxr-xr-x. 1 root root 33 Apr 15 2021 cache
drwxrwxrwx. 2 99 99 4096 Aug 2 10:24 data
drwxr-xr-x. 2 root root 6 Apr 23 2020 db
drwxr-xr-x. 2 root root 6 Apr 23 2020 empty
drwxr-xr-x. 2 root root 6 Apr 23 2020 ftp
drwxr-xr-x. 2 root root 6 Apr 23 2020 games
drwxr-xr-x. 2 root root 6 Apr 23 2020 gopher
drwxr-xr-x. 3 root root 18 Apr 14 2021 kerberos
drwxr-xr-x. 1 root root 60 Apr 15 2021 lib
drwxr-xr-x. 2 root root 6 Apr 23 2020 local
lrwxrwxrwx. 1 root root 11 Apr 14 2021 lock -> ../run/lock
drwxr-xr-x. 1 root root 93 Apr 15 2021 log
lrwxrwxrwx. 1 root root 10 Apr 23 2020 mail -> spool/mail
drwxr-xr-x. 2 root root 6 Apr 23 2020 nis
drwxr-xr-x. 2 root root 6 Apr 23 2020 opt
drwxr-xr-x. 2 root root 6 Apr 23 2020 preserve
lrwxrwxrwx. 1 root root 6 Apr 14 2021 run -> ../run
drwxr-xr-x. 5 root root 41 Apr 14 2021 spool
drwxrwxrwt. 1 root root 6 Apr 15 2021 tmp
drwxr-xr-x. 2 root root 6 Apr 23 2020 yp
Or, the mount command can be used, which should show that the Shared Volume has been mounted as a Network File System (NFS).
~]$ oc exec pod/my-pod-hp5w4 -- mount
127.0.0.1:/ on /var/data type nfs4 (rw,relatime,vers=4.1,rsize=1048576,wsize=1048576,namlen=255,hard,noresvport,proto=tcp,port=20053,timeo=600,retrans=2,sec=sys,clientaddr=127.0.0.1,local_lock=none,addr=127.0.0.1)
Did you find this article helpful?
If so, consider buying me a coffee over at