Kahibaro
Discord Login Register

9.3 Persistent Volume Claims

Role of Persistent Volume Claims in OpenShift

Persistent Volume Claims (PVCs) are the way applications request storage in OpenShift. While Persistent Volumes (PVs) represent actual storage resources in the cluster, PVCs represent an application’s claim on that storage, using an abstract description (size, access mode, sometimes a class of storage) instead of tying the application to a specific backend implementation.

PVCs are namespaced user-facing resources, while PVs are cluster-scoped. Most application developers interact only with PVCs, not directly with PVs.

PVC Lifecycle and Binding

The lifecycle of a PVC in OpenShift (and Kubernetes) usually follows these steps:

  1. Create a PVC
    A developer (or automation) creates a PVC in a project/namespace, specifying:
    • Requested storage capacity
    • Access mode(s)
    • Optionally, a storageClassName and other attributes
  2. Binding to a PV
    The control plane attempts to satisfy the PVC:
    • With dynamic provisioning: the StorageClass provisions a new PV, which is then bound to the PVC.
    • With pre-provisioned PVs: the system searches for a matching existing PV and binds it.
  3. Use by Pods
    Pods in the same namespace reference the PVC in their volume definitions. When scheduled, the Pod receives the bound storage.
  4. Release and Reclaim
    When the PVC is deleted:
    • The binding between PV and PVC is removed.
    • What happens to the underlying PV/data is governed by the PV’s reclaimPolicy (covered elsewhere).

PVCs are bound one-to-one with PVs. Multiple Pods can mount the same PVC, but multiple PVCs cannot bind to the same PV.

Key PVC Attributes

The most important fields in a PVC spec are:

These shape how the storage is provisioned and used.

Access Modes

Access modes describe how a volume can be mounted:

Depending on the underlying storage plugin, not all access modes are supported. For example:

Choosing the wrong access mode can prevent a PVC from binding or make Pods unschedulable.

Requested Capacity

The line:

yaml
resources:
  requests:
    storage: 10Gi

tells the cluster how much storage you need. Some important aspects:

Increasing requested size after creation is possible with many (but not all) storage providers (volume expansion), assuming the underlying StorageClass and driver support it.

StorageClass Selection

storageClassName ties your PVC to a class of storage with certain characteristics (performance, availability, backend type, reclaim policy, etc.).

Typical patterns in OpenShift:

yaml
  storageClassName: fast-ssd
yaml
  storageClassName: ""

This disables dynamic provisioning. The PVC will only bind if an appropriate pre-created PV is available.

Choosing the right StorageClass is often a policy and performance decision and is typically defined by cluster administrators.

Volume Mode: Filesystem vs Block

volumeMode controls how the volume appears in the Pod:

If omitted, Filesystem is assumed. Not all storage drivers support block mode.

Basic PVC Manifest Structure

A minimal PVC might look like:

yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-data-claim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  storageClassName: standard

Key points:

How Pods Use PVCs

PVCs are not directly mounted; they are referenced through the volumes section of a Pod (or a higher-level controller like a Deployment). A typical Pod snippet:

yaml
apiVersion: v1
kind: Pod
metadata:
  name: app-using-pvc
spec:
  volumes:
    - name: app-storage
      persistentVolumeClaim:
        claimName: my-data-claim
  containers:
    - name: app
      image: registry.example.com/my-app:latest
      volumeMounts:
        - name: app-storage
          mountPath: /var/lib/app-data

Important constraints:

PVC Binding Behavior and Matching

When a PVC is created, the control plane attempts to match it with a suitable PV:

Once bound:

Working with PVCs via the OpenShift CLI

Using oc you can manage PVCs similarly to other resources.

Listing and Inspecting PVCs

bash
# List PVCs in the current project
oc get pvc
# Show details of a specific PVC
oc describe pvc my-data-claim

oc describe is particularly useful to:

Creating and Deleting PVCs

Create from a manifest:

bash
oc apply -f pvc.yaml

Delete a claim:

bash
oc delete pvc my-data-claim

Deleting a PVC does not always delete the underlying storage; what happens is tied to the PV’s reclaim policy (covered elsewhere). From the application’s perspective, deleting the PVC generally means the volume is no longer mountable.

PVC Status and Common States

PVCs have a .status.phase that indicates their current state:

For troubleshooting, always inspect:

PVCs and Namespaces

PVCs are namespaced:

This aligns with multi-tenant isolation in OpenShift and supports resource governance via quotas and limits at the namespace level.

Using PVCs with Stateful Workloads

Many stateful workloads (databases, message queues, data processing systems) rely on PVCs to persist data beyond Pod lifetimes:

For simple workloads, a single PVC may be shared by multiple Pods (subject to access mode and backend limitations).

Resizing and Modifying PVCs

PVC modification capabilities depend on the StorageClass and storage driver:

bash
  oc patch pvc my-data-claim \
    -p '{"spec":{"resources":{"requests":{"storage":"20Gi"}}}}'

Considerations:

PVCs and Security Considerations

Although detailed security topics are treated elsewhere, a few PVC-specific points matter:

Patterns and Best Practices for PVC Usage

When designing applications for OpenShift with PVCs, common patterns include:

By understanding PVCs as the bridge between applications and the cluster’s persistent storage infrastructure, you can design workloads on OpenShift that are both portable and resilient, without coupling them tightly to specific storage technologies.

Views: 50

Comments

Please login to add a comment.

Don't have an account? Register now!