Persistent volumes in practice
Class behaviour (reclaim policy, ReadWriteOnce, expansion, retained volumes) is in Storage classes. This page covers claiming and mounting volumes.
Requesting a PVC
Section titled “Requesting a PVC”apiVersion: v1kind: PersistentVolumeClaimmetadata: name: my-data namespace: <tenant>-prodspec: accessModes: - ReadWriteOnce storageClassName: csi-cinder-sc-delete # or csi-cinder-sc-retain resources: requests: storage: 10Gi- Class: the default,
csi-cinder-sc-delete, destroys the volume when the claim is deleted. Usecsi-cinder-sc-retainfor data that must survive a mistaken delete. No other class exists. - Size: the request counts against your tenant’s storage quota whatever you actually write; see Quotas.
- Start small: volumes can be expanded later but not shrunk.
Mounting a PVC in a Pod
Section titled “Mounting a PVC in a Pod”A new Cinder volume’s root directory is root:root with mode 0755. Kestrel Pods must run as non-root (PodSecurity restricted), so set fsGroup in the Pod’s securityContext; without it, every write to the volume fails with Permission denied.
apiVersion: v1kind: Podmetadata: name: app namespace: <tenant>-prodspec: securityContext: runAsNonRoot: true runAsUser: 1000 runAsGroup: 1000 fsGroup: 1000 # the volume becomes group-writable by GID 1000 fsGroupChangePolicy: OnRootMismatch # skip the recursive chown when ownership already matches seccompProfile: type: RuntimeDefault containers: - name: app image: your-image:latest securityContext: allowPrivilegeEscalation: false capabilities: drop: [ALL] volumeMounts: - name: data mountPath: /data volumes: - name: data persistentVolumeClaim: claimName: my-data- In a Deployment, StatefulSet or Job, put the same
securityContextin the Pod template. - A Deployment that mounts an RWO claim needs
strategy: {type: Recreate}, or use a StatefulSet. See ReadWriteOnce: one node at a time. fsGrouphas no effect on shared (RWX) volumes; see below.
Shared (RWX) volumes
Section titled “Shared (RWX) volumes”There is no ReadWriteMany StorageClass. There are two ways to get a shared volume:
- A CephFS share from your Arbutus project, self-service. You create the share in OpenStack and claim it with an annotated PVC, and Kestrel creates the PersistentVolume. See CephFS shares.
- A static PersistentVolume from RCS, on request, for storage that isn’t in your Arbutus project. The rest of this section covers this option.
Either way the claim’s storage request counts against your tenant’s storage quota, like any PVC.
Request one with an RCS ticket that gives:
- The namespace that will mount it. Each namespace needs its own PV and claim. PVs that point at the same storage see the same data, so to share data across namespaces, ask for one PV per namespace. For separate storage per namespace, such as dev and prod, say so and give each a size.
- The size, and any quota increase it needs.
- The UID and GID your Pods run as. Kubernetes does not change ownership on shared filesystems (
fsGrouphas no effect), so RCS makes the volume’s root writable by that UID and GID.
RCS replies with the PV name. The PV carries your tenant label and looks like this:
# Created by RCS; shown for reference. Tenants can't list or delete PersistentVolumes.apiVersion: v1kind: PersistentVolumemetadata: name: <pv-name> labels: capsule.clastix.io/tenant: <tenant>spec: capacity: storage: 20Gi accessModes: - ReadWriteMany storageClassName: "" # volume source set by RCSClaim it from the namespace you named:
apiVersion: v1kind: PersistentVolumeClaimmetadata: name: shared-data namespace: <tenant>-prodspec: accessModes: - ReadWriteMany storageClassName: "" # required: an omitted class gets the default, and the claim never binds volumeName: <pv-name> # required: admission rejects a class-less claim without it resources: requests: storage: 20Gi # any size up to the PV's capacityMount the claim as in the Pod example above, minus fsGroup, with runAsUser and runAsGroup set to the UID and GID you gave RCS. Any number of Pods, on any node, can mount it at once.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause and fix |
|---|---|
PVC Pending, event ProvisioningFailed … storageclass.storage.k8s.io "<name>" not found | The class doesn’t exist. Use csi-cinder-sc-delete or csi-cinder-sc-retain. |
Create or resize fails with exceeded quota | Your tenant’s storage ceiling is reached and nothing was created. See Quotas. |
Pod stuck in ContainerCreating, event Multi-Attach error | The RWO volume is still attached on another node. Use strategy: Recreate or a StatefulSet. |
Permission denied writing to a Cinder volume | Set fsGroup (above). |
Permission denied writing to an RWX volume | The volume root isn’t writable by your Pod’s UID/GID. Run as the UID/GID you gave RCS, or ask RCS to change the ownership. For a CephFS share, see its troubleshooting. |
Claim refused: A PVC without a StorageClass must set spec.volumeName… or spec.volumeName may name only a PersistentVolume reserved for this PVC… | Set volumeName to the PV name RCS gave you, and create the claim in the namespace you named. For CephFS share claims, see its admission errors. |
RWX claim stays Pending | Check accessModes: [ReadWriteMany] and a request no larger than the PV’s capacity. |
PVC condition FileSystemResizePending | Restart the Pod to finish the resize. |