...
| Code Block |
|---|
| language | bash |
|---|
| title | Deploy rbac.yam & clientProvider.yaml |
|---|
|
$ kubectl create ns dynamic
namespace/dynamic created
$ kubectl apply -f rbac.yaml -f provisioner.yaml -n dynamic
serviceaccount/nfs-client-provisioner created
clusterrole.rbac.authorization.k8s.io/nfs-client-provisioner-runner unchanged
clusterrolebinding.rbac.authorization.k8s.io/run-nfs-client-provisioner configured
role.rbac.authorization.k8s.io/leader-locking-nfs-client-provisioner created
rolebinding.rbac.authorization.k8s.io/leader-locking-nfs-client-provisioner created
deployment.apps/nfs-client-provisioner created |
We claim a piece of storage, instantiating a PV thanks to a PVC. Copy
| Code Block |
|---|
| language | yml |
|---|
| title | pvc.yaml (dynamic) |
|---|
| collapse | true |
|---|
|
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mypvc
spec:
storageClassName: mysc
accessModes:
- ReadWriteMany
resources:
requests:
storage: 60Mi |
So deploy the PVC and see what happens. Note that the PVC status is pending. This is because the SC (see above) has the VOLUMEBINDINGMODE equal to WaitForFirstConsumer. This means that the PV will be created as soon as an application that requires it is created.
| Code Block |
|---|
| language | bash |
|---|
| title | Deploy pvc.yaml (dynamic) |
|---|
|
$ kubectl get pvc -n dynamic
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/mypvc Pending mysc 3m3s |
We use the same application seen in the static case and see again what happens to the SC, PV and PVC supply chain
| Code Block |
|---|
| language | bash |
|---|
| title | Deploy application.yaml |
|---|
|
$ k apply -f stateful.yaml -n dynamic
statefulset.apps/mystate created
service/mysvc created
$ k get sc,pv,pvc -n dynamic
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
storageclass.storage.k8s.io/mysc (default) nfs Retain WaitForFirstConsumer false 80m
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS AGE
persistentvolume/pvc-100108de-18fb-4b85-864e-56e204f5b2d8 60Mi RWX Retain Bound dynamic/mypvc mysc 12s
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/mypvc Bound pvc-100108de-18fb-4b85-864e-56e204f5b2d8 60Mi RWX mysc 7m18s |
Then, after the application is deployed, a PV is automatically generated (the system hooks a hash code to the end of the component name) with exactly the required capacity. The PVC is now in the status bound and reports, in the adjacent column, the PV to which it is connected. If we go to check in the /home/share folder, we will find a new one with the composite name <namespace>-<pvc_name>-pvc-<hash_code>. We insert a simple index.html file in this directory and perform the same checks carried out in the static case.