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 Supervisor 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.

Prerequisites

Procedure

  1. Switch to the namespace where the cluster is running.
    kubectl config use-context NAMESPACE
  2. List the available storage classes.
    kubectl get storageclasses
  3. Create a YAML file that contains the PVC configuration.
    Use the following example. Replace the name, storageClassName, and storage variable values with yours.
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: my-pvc
    spec:
      accessModes:
        - ReadWriteOnce
      storageClassName: gold
      resources:
        requests:
            storage: 3Gi
               
  4. Apply the PVC to the cluster.
    kubectl apply -f PVC-NAME.yaml
  5. Verify the status of the persistent volume claim.
    kubectl get pvc
    The PVC is listed and available for use. The PVC also appears in the Supervisor Namespace because the storage comes out of its quota.

What to do next

Check out the stateful application example in the Kubernetes documentation: Deploying WordPress and MySQL with Persistent Volumes.