To run stateful workloads on Tanzu Kubernetes clusters, you can create a persistent volume claim (PVC) to request persistent storage resources without knowing the details of the underlying storage infrastructure. The storage used for the PVC is allocated out of the storage quota for the vSphere Namespace.

Containers by default are ephemeral and stateless. For stateful workloads, a common approach is to create a persistent volume claim (PVC). You can use a PVC to mount the persistent volumes and access storage. The request dynamically provisions a persistent volume object and a matching virtual disk. The claim is bound to the persistent volume. When you delete the claim, the corresponding persistent volume object and the provisioned virtual disk are also deleted.

Procedure

  1. Log in to the target Tanzu Kubernetes cluster. See Connect to a Tanzu Kubernetes Cluster as a vCenter Single Sign-On User.
  2. Switch to the namespace where the cluster is running.
    kubectl config use-context NAMESPACE
  3. Verify the storage class, or create one.
    To verify an existing storage class:
    kubectl get storageclass
    To create a storage class, see Tanzu Kubernetes Storage Class Example.
  4. Create a namespace.
    kubectl create namespace guestbook
  5. Create the Guestbook PVC YAML files.
  6. Apply the Guestbook PVCs to the cluster.
    kubectl apply -f redis-leader-pvc.yaml -n guestbook
    kubectl apply -f redis-follower-pvc.yaml -n guestbook
  7. Verify the status of the PVCs.
    kubectl get pvc,pv -n guestbook
    The PVCs and persistent volumes (PVs) are listed and available for use.
    NAME                                       STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS         AGE
    persistentvolumeclaim/redis-follower-pvc   Bound    pvc-37b72f35-3de2-4f84-be7d-50d5dd968f62   2Gi        RWO            tkgs-storage-class   66s
    persistentvolumeclaim/redis-leader-pvc     Bound    pvc-2ef51f31-dd4b-4fe2-bf4c-f0149cb4f3da   2Gi        RWO            tkgs-storage-class   66s
    
    NAME                                                CAPACITY   ACCESS MODES   RECLAIM POLICY STATUS   CLAIM                 STORAGECLASS         
    persistentvolume/pvc-2ef51f31-dd4b-4fe2-bf4c   2Gi  RWO            Delete           Bound    guestbook/redis-leader-pvc     tkgs-storage-class
    persistentvolume/pvc-37b72f35-3de2-4f84-be7d   2Gi  RWO            Delete           Bound    guestbook/redis-follower-pvc   tkgs-storage-class