This is an internal documentation. There is a good chance you’re looking for something else. See Disclaimer.
Persistent Volumes¶
In some cases it is necessary to add custom, persistent volumes.
Caveats¶
Only ReadWriteOnce volumes are available. That is, only a single pod may have read or write access to a volume. As result, the deployment strategy needs to be adjusted in the deploymentconfig (or deployment) to Recreate:
spec:
strategy:
type: Recreate
recreateParams: # this is used rather than rollingParams with Recreate
# …
With the recreate strategy, the old pod is stopped before starting the new pod. Thus, the application will be offline during deployment. However, it’s avoided that both pods need access to the volume concurrently.
Technical note:
The above description of ReadWriteOnce isn’t fully accurate and technically read/write access is limited to a single node. It may be possible to use inter-pod affinity to schedule pods onto the same node in some cases to allow access to a volume by multiple pods.
See also:
Creating a Persistent Volume¶
Warning
Read Caveats first.
This creates a PVC of size 1 GiB called cms
which is mounted in the nice
container at /app/var/cms
.
oc set volume dc/nice -c nice --add --name=cms --claim-name=cms --claim-size=1G --mount-path=/app/var/cms
Hint
It’s also possible to request cheaper and slower bulk storage via --claim-class=bulk
. Minimum
size for bulk storage is 100 GiB.
Show available classes: oc get storageclass
You can list the PVCs using oc get pvc
and you’ll see the mounted volumes in the deployment config
using oc describe dc ${POD}
, section Mount.
Populating a Persistent Volume¶
Here is how you copy the directory cms
on your machine into a volume located at /var/app/cms
.
Find a running pod (a nice pod in this example)
# find a running pod (a nice pod in this case) $ oc get pods -l run=nice NAME READY STATUS RESTARTS AGE nice-169-v2vsx 2/2 Running 0 11m
Now, copy the content into the volume within that pod
oc cp -c nice cms nice-169-v2vsx:/app/var/cms
Resizing a Persistent volume¶
Show volumes:
oc get persistentvolumeclaim
Resize volume:
oc edit persistentvolumeclaim ${name}
and edit the size:
spec: resources: requests: storage: ${size} # <-- e.g 15Gi
Removing a Persistent Volume¶
First remove the volume from the container. Then, remove the actual PVC.
oc set volume dc/nice -c nice --remove --name=cms
oc delete pvc cms