You can statically create a persistent volume (PV) in a TKG 2.0 cluster using a persistent volume claim (PVC) from the Supervisor.
Persistent Volume Definition
Below is an example definition for a static persistent volume (PV). The definition requires a storage class and a volume handle. The volumeHandle
is the name of a persistent volume claim (PVC) that is created on Supervisor in the same vSphere Namespace where the target TKG cluster is provisioned. This PVC must not be attached to any pod.
Use the following command to get the
storageClassName.
kubectl get storageclass
For
volumeHandle, enter the name of the PVC on
Supervisor.
apiVersion: v1 kind: PersistentVolume metadata: name: static-tkg-block-pv annotations: pv.kubernetes.io/provisioned-by: csi.vsphere.vmware.com spec: storageClassName: gc-storage-profile capacity: storage: 2Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Delete claimRef: namespace: default name: static-tkg-block-pvc csi: driver: "csi.vsphere.vmware.com" volumeAttributes: type: "vSphere CNS Block Volume" volumeHandle: "supervisor-block-pvc-name" #Enter the PVC name from Supervisor.
Use the following to create the PV.
kubectl apply -f redis-leader-pvc.yaml -n guestbook
Persistent Volume Claim (PVC) for Statically Defined PV
If you have deployed Supervisor across zones.
Set the
storageClassName to the same value as in the PV.
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: static-tkg-block-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 2Gi storageClassName: gc-storage-profile volumeName: static-tkg-block-pv
Verify that the PVC is bound to the PV that you created.
kubectl get pv,pvc