To provision a static persistent volume, you manually create a virtual disk to use as a backing storage for the persistent volume. You then create a persistent volume that contains details of the backing storage. A pod can request this storage through a persistent volume claim.

Only Tanzu Kubernetes clusters support static provisioning.

Procedure

  1. Create a virtual disk.
    1. Log in to the ESXi host that has access to the datastore where the persistent volume will reside.
    2. Change directory to that datastore, for example, vsanDatstore and use the vmkfstools command to create virtual disk files.
      $ cd /vmfs/volumes/vsanDatastore/demo/
      $ vmkfstools -c 2G demo.vmdk
  2. Create a persistent volume.
    1. Access your namespace in the vSphere Kubernetes environment.
    2. Define a persistent volume using a YAML manifest that references the virtual disk file.
      For example, create a file named demo-pv.yaml with the following contents.
      apiVersion: v1
      kind: PersistentVolume
      metadata:
        name: demo-pv
      spec:
        capacity:
          storage: 2Gi
        accessModes:
          - ReadWriteOnce
        persistentVolumeReclaimPolicy: Retain
        vsphereVolume:
          volumePath: "[vsanDatastore] demo/demo.vmdk"
          fsType: ext4
    3. Deploy the persistent volume.
      $ kubectl create -f demo-pv.yaml
      persistentvolume/demo-pv created
    4. Verify that the persistent volume has been created.
      $ kubectl get pv
      NAME      CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM   STORAGECLASS   REASON   AGE
      demo-pv   2Gi        RWO            Retain           Available                                   3s
  3. Define a persistent volume claim to match the persistent volume.
    Use the following YAML manifest as an example.
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: demo-pvc
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 2Gi
  4. Define a deployment that mounts your persistent volume.
    The following sample YAML manifest references your demo-pvc persistent volume claim.
    apiVersion: v1
    kind: Pod
    metadata:
      name: demo-pod
    .....
    .....
      volumes:
        - name: demo-vol
          persistentVolumeClaim:
            claimName: demo-pvc