Bootstrap FreeKB - OpenShift - List Persistent Volume Claims using the oc get pvc command
OpenShift - List Persistent Volume Claims using the oc get pvc command

Updated:   |  OpenShift articles

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.

 

The oc get persistentvolumeclaims (or oc get pvc) command will return the list of Persistent Volume Claims. 

TIP

The -A or --all-namespaces flag can be used to list the Persistent Volume Claims in every project / namespace.

The -n or --namespace flag can be used to list the Persistent Volume Claims in a certain project / namespace.

Access Modes can be one or more of the following:

  • ReadWriteOnce (RWO) - The volume may only be mounted on a single node
  • ReadWriteOncePod (RWOP) - The volume may only be mounted on a single pod
  • ReadOnlyMany (ROX) - The volume may be mounted on different nodes
  • ReadWriteMany (RWX) - The volume can be mounted on different nodes
~]$ oc get pvc
NAME          STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
my-pvc-1       Bound    pvc-385996a0-70af-4791-aa8e-9e6459e6b123   1Gi        RWO            file-storage   659d
my-pvc-2       Bound    pvc-8aeddd4d-aad5-4039-8d04-640a71c9a72d   10Gi       RWO            file-storage   659d
my-pvc-3       Bound    pvc-0050144d-940c-4c4e-a23a-2a660a5490eb   10Gi       RWO            file-storage   659d

 

Or a single persistent volume claim can be returned.

~]$ oc get pvc pvc001
NAME          STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
my-pvc-1      Bound    pvc-385996a0-70af-4791-aa8e-9e6459e6b123   1Gi        RWO            file-storage   659d

 

The --output wide option can be used to include VOLUMEMODE in the output.

~]$ oc get pvc --output WIDE
NAME          STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE     VOLUMEMODE
my-pvc-1      Bound    pvc-385996a0-70af-4791-aa8e-9e6459e6b123   1Gi        RWO            file-storage   659d    Filesystem
my-pvc-2      Bound    pvc-8aeddd4d-aad5-4039-8d04-640a71c9a72d   10Gi       RWO            file-storage   659d    Filesystem
my-pvc-3      Bound    pvc-0050144d-940c-4c4e-a23a-2a660a5490eb   10Gi       RWO            file-storage   659d    Block

 

The -A o --all-namespaces flag can be used to return every persistent volume claim in every namespace.

oc get pvc --all-namespaces

 

The oc describe pvc command can be used to display the details of a Persistent Volume Claim. In this example, the details of the pvc001 Persistent Volume Claim will be displayed.

~]$ oc describe pvc my-pvc-1
Name:          my-pvc-1
Namespace:     foo
StorageClass:  file-storage
Status:        Bound
Volume:        pvc-2db07c57-e282-48e7-bfb1-4cbd7245c25e
Labels:        <none>
Annotations:   pv.kubernetes.io/bind-completed: yes
               pv.kubernetes.io/bound-by-controller: yes
               volume.beta.kubernetes.io/storage-provisioner: csi.trident.netapp.io
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      1Gi
Access Modes:  ROX,RWX
VolumeMode:    Filesystem
Used By:       my-app-2mp2k

 

Or, the oc get pvc command with the --output json‚Äč or --output yaml option can be used.

~]$ oc get pvc my-pvc-1 --output json
{
    "apiVersion": "v1",
    "kind": "PersistentVolumeClaim",
    "metadata": {
        "annotations": {
            "pv.kubernetes.io/bind-completed": "yes",
            "pv.kubernetes.io/bound-by-controller": "yes",
            "volume.beta.kubernetes.io/storage-provisioner": "csi.trident.netapp.io"
        },
        "creationTimestamp": "2022-06-28T01:50:12Z",
        "finalizers": [
            "kubernetes.io/pvc-protection"
        ],
        "labels": {
            "app": "my-app",
            "component": "my-app",
            "template": "my-app-template"
        },
        "name": "my-pvc-1",
        "namespace": "my-project",
        "resourceVersion": "416942905",
        "uid": "4db1c848-720f-44cd-9fdc-bc004037575d"
    },
    "spec": {
        "accessModes": [
            "ReadWriteOnce"
        ],
        "resources": {
            "requests": {
                "storage": "10Gi"
            }
        },
        "storageClassName": "file-storage",
        "volumeMode": "Filesystem",
        "volumeName": "pvc-4db1c848-720f-44cd-9fdc-bc004037575d"
    },
    "status": {
        "accessModes": [
            "ReadWriteOnce"
        ],
        "capacity": {
            "storage": "10Gi"
        },
        "phase": "Bound"
    }
}

 

The --output jsonpath option can be used to print the value of a specific JSON key.

~]$ oc get pvc my-pvc-1 --output jsonpath={.spec.resources.requests.storage}
10Gi

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter a07305 in the box below so that we can be sure you are a human.