Skip to main content
A newer release of this product is available.

Provision a volume

Contributors netapp-aruldeepa

Create a PersistentVolume (PV) and a PersistentVolumeClaim (PVC) that uses the configured Kubernetes StorageClass to request access to the PV. You can then mount the PV to a pod.

Overview

A PersistentVolume (PV) is a physical storage resource provisioned by the cluster administrator on a Kubernetes cluster. The PersistentVolumeClaim (PVC) is a request for access to the PersistentVolume on the cluster.

The PVC can be configured to request storage of a certain size or access mode. Using the associated StorageClass, the cluster administrator can control more than PersistentVolume size and access mode—​such as performance or service level.

After you create the PV and PVC, you can mount the volume in a pod.

Sample manifests

PersistentVolume sample manifest

This sample manifest shows a basic PV of 10Gi that is associated with StorageClass basic-csi.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-storage
  labels:
    type: local
spec:
  storageClassName: basic-csi
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/my/host/path"
PersistentVolumeClaim sample manifests

These examples show basic PVC configuration options.

PVC with RWO access

This example shows a basic PVC with RWO access that is associated with a StorageClass named basic-csi.

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc-storage
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: basic-csi
PVC with NVMe/TCP

This example shows a basic PVC for NVMe/TCP with RWO access that is associated with a StorageClass named protection-gold.

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pvc-san-nvme
spec:
accessModes:
  - ReadWriteOnce
resources:
  requests:
    storage: 300Mi
storageClassName: protection-gold
Pod manifest samples

These examples show basic configurations to attach the PVC to a pod.

Basic configuration
kind: Pod
apiVersion: v1
metadata:
  name: pv-pod
spec:
  volumes:
    - name: pv-storage
      persistentVolumeClaim:
       claimName: basic
  containers:
    - name: pv-container
      image: nginx
      ports:
        - containerPort: 80
          name: "http-server"
      volumeMounts:
        - mountPath: "/my/mount/path"
          name: pv-storage
Basic NVMe/TCP configuration
---
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: nginx
  name: nginx
spec:
  containers:
    - image: nginx
      name: nginx
      resources: {}
      volumeMounts:
        - mountPath: "/usr/share/nginx/html"
          name: task-pv-storage
  dnsPolicy: ClusterFirst
  restartPolicy: Always
  volumes:
    - name: task-pv-storage
      persistentVolumeClaim:
      claimName: pvc-san-nvme

Create the PV and PVC

Steps
  1. Create the PV.

    kubectl create -f pv.yaml
  2. Verify the PV status.

    kubectl get pv
    NAME        CAPACITY  ACCESS MODES  RECLAIM POLICY  STATUS    CLAIM  STORAGECLASS  REASON  AGE
    pv-storage  4Gi       RWO           Retain          Available                              7s
  3. Create the PVC.

    kubectl create -f pvc.yaml
  4. Verify the PVC status.

    kubectl get pvc
    NAME        STATUS VOLUME     CAPACITY ACCESS MODES STORAGECLASS AGE
    pvc-storage Bound  pv-name 2Gi      RWO                       5m
  5. Mount the volume in a pod.

    kubectl create -f pv-pod.yaml
    Note You can monitor the progress using kubectl get pod --watch.
  6. Verify that the volume is mounted on /my/mount/path.

    kubectl exec -it task-pv-pod -- df -h /my/mount/path
  7. You can now delete the Pod. The Pod application will no longer exist, but the volume will remain.

    kubectl delete pod task-pv-pod

Refer to Kubernetes and Trident objects for details on how storage classes interact with the PersistentVolumeClaim and parameters for controlling how Astra Trident provisions volumes.