Using a default storage class will allow you to deploy volumes as they are claimed / requested without any manual intervention. Kubernetes provides multiple built-in storage provisioners but most of them are focused on cloud environments and since I run my cluster on-prem with nfs as shared storage, I will have to use the nfs-subdir external provisioner (github).
This will allow me to share one directory and the provisioner will create a directory on the nfs share for each volume that is being allocated. For more documentation, check the link above.
First, clone the git repository:
[ 17:25:09 ] - archy ~> git clone https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner.git git/kubernetes/prod/nfs-subdir-external-provisioner
[ 17:25:10 ] - archy ~> cd git/kubernetes/prod/nfs-subdir-external-provisioner
Create the RBAC Bindings required for the provisioner to work:
[ 17:25:24 ] - archy ~/git/kubernetes/prod/nfs-subdir-external-provisioner - master> kubectl -n default apply -f deploy/rbac.yaml
I will adjust some values in 'deploy/deployment.yaml' since my nfs-server and path differ from the defaults:
[ 17:26:04 ] - archy ~/git/kubernetes/prod/nfs-subdir-external-provisioner - master> git diff deploy/deployment.yaml
diff --git a/deploy/deployment.yaml b/deploy/deployment.yaml
index 26d2a23..e07e5f6 100644
--- a/deploy/deployment.yaml
+++ b/deploy/deployment.yaml
@@ -29,11 +29,11 @@ spec:
- name: PROVISIONER_NAME
value: k8s-sigs.io/nfs-subdir-external-provisioner
- name: NFS_SERVER
- value: 10.3.243.101
+ value: nfssrv.archyslife.lan
- name: NFS_PATH
- value: /ifs/kubernetes
+ value: /var/nfs/kubernetes
volumes:
- name: nfs-client-root
nfs:
- server: 10.3.243.101
- path: /ifs/kubernetes
+ server: nfssrv.archyslife.lan
+ path: /var/nfs/kubernetes
Apply the modified deployment:
[ 17:26:09 ] - archy ~/git/kubernetes/prod/nfs-subdir-external-provisioner - master> kubectl -n default apply -f deploy/deployment.yaml
I will also adjust the path pattern with which the directories are created and make the storageclass my default storage class using the annotation below. I also added a pattern after which the directories will be created:
[ 17:27:36 ] - archy ~/git/kubernetes/prod/nfs-subdir-external-provisioner - master> git diff deploy/class.yaml
diff --git a/deploy/class.yaml b/deploy/class.yaml
index fbbf086..a676814 100644
--- a/deploy/class.yaml
+++ b/deploy/class.yaml
@@ -1,7 +1,10 @@
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
- name: nfs-client
+ name: managed-nfs
+ annotations:
+ storageclass.kubernetes.io/is-default-class: "true"
provisioner: k8s-sigs.io/nfs-subdir-external-provisioner # or choose another name, must match deployment's env PROVISIONER_NAME'
parameters:
+ pathPattern: "${.PVC.namespace}-${.PVC.name}"
archiveOnDelete: "false"
Apply the modified storage class:
[ 17:26:44 ] - archy ~/git/kubernetes/prod/nfs-subdir-external-provisioner - master> kubectl -n default apply -f deploy/class.yaml
You should now have a default storage class managed by the k8s-sigs.io/nfs-subdir-external-provisioner but you can check using this command: [ 17:29:10 ] - archy ~/git/kubernetes/prod/nfs-subdir-external-provisioner - master> kubectl -n default -o wide -l app=nfs-client-provisioner get pods,deployments
So let's test if everything works as expected. Thankfully, the maintainers provided two test yamls that will create a volumeclaim and pod that will access said volume, so apply them: [ 17:29:21 ] - archy ~/git/kubernetes/prod/nfs-subdir-external-provisioner - master> kubectl -n default apply -f deploy/test-claim.yaml -f deploy/test-pod.yaml
[17:29:44 - archy@nfssrv ~]$ ls -lh /var/nfs/kubernetes
total 0
drwxrwxrwx. 2 root root 6 Sep 13 17:29 default-test-claim
[17:29:50 - archy@nfssrv ~]$ ls -lh /var/nfs/kubernetes/default-test-claim
total 0
-rw-r--r--. 1 root root 0 Sep 13 17:29 SUCCESS
Comments
Post a Comment