Persistent Volumes (PV) & Storage In Tanzu Community Edition Part 1
Two terms commonly used in the Kubernates universe when it comes to applications are Stateful and Stateless.
The main difference between stateful and stateless workloads is that stateless workloads don’t store data on the host, whereas stateful workloads require some kind of storage on the host who serves the requests which does not get deleted, thus the storage volume persists.
Containers are stateless by default and uses Persistent Volumes (PV) to address this requirement.
Kubernates uses Persistent Volumes Claims (PVCs) to mount the persistent volumes and access the underlying storage. The PVC will create a persistent volume object and a matching virtual disk. The claim is bound to the persistent volume. When the claim is deleted, the corresponding persistent volume object and the provisioned virtual disk are also deleted.
TCE uses the Container Storage Interface (CSI) driver to integrate with underlying storage platforms. When a TCE cluster is created, a number of CSI k8s pods are automatically created:
You can run the following command to gather details about the controller pod:
kubectl describe pod vsphere-csi-controller -n kube-system
One container in particular- the csi-provisioner, handles the PV creation and deletion requests:
You can also use examine the CSI node pods:
kubectl describe pod vsphere-csi-node -n kube-system
TCE creates a default storage class for the system which can be found by running these commands:
kubectl get sc default kubectl get sc default -o yaml > default_storage_class.yaml
Use the following steps to create a PVC:
1.) Switch to the context where your cluster is running
kubectl config use-context tce-prod
2.) Create a Namespace
kubectl create namespace storage-test
2.) Create PVC YAML file
I used the VI editor in this example:
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: database-pvc spec: accessModes: - ReadWriteOnce storageClassName: default resources: requests: storage: 2Gi
3.) Apply the PVC to the cluster
kubectl apply -f database-pvc.yaml -n storage-test
And use the following command to view the PVC:
kubectl get pvc,pv -n storage-test
In the view above we can see that the PVC has been successfully created and is available for use.
In my lab environment I am using vSphere 6.7U3 with vSAN. You can also view the PVC from vCenter by going to Cluster > Monitor > Cloud Native Storage:
We were able created our PVC with just a few steps. I will dive deeper into this topic in my next post.