Persistent Volumes (PV) & Storage In Tanzu Community Edition Part 2
Updated: Jan 6
In the previous post, we created a PVC. Lets proceed with the next steps.
1.) Create a Pod
The next step is to create a k8s pod which we will attach to our PVC. Use VI to create the pod.yaml file:
ice@tanzu-jumpsrvr01:~$ cat pv-pod.yaml apiVersion: v1 kind: Pod metadata: name: test-pv-pod spec: volumes: - name: task-pv-storage persistentVolumeClaim: claimName: database-pvc containers: - name: task-pv-container image: nginx ports: - containerPort: 80 name: "http-server" volumeMounts: - mountPath: "/usr/share/nginx/html" name: task-pv-storage
Then apply the file to our test namespace:
kubectl apply -f pv-pod.yaml -n storage-test
You will see the ContainerCreating message:
Use the following command to view the pod details:
kubectl describe pod test-pv-pod -n storage-test
Use the following command to connect to our pod:
kubectl exec -it -n storage-test test-pv-pod -- /bin/bash
Our pod is now connected to the PV:
1.) Delete the pod and PVC
To delete the pod that we just made, run this command:
kubectl delete pod test-pv-pod -n storage-test
And then run the following commands to delete the PV and PVC. (Deleting the PVC will automatically delete the PV).
kubectl delete pvc -n storage-test database-pvc
Deleting the PVC automatically deletes the objects in vCenter.