gabrielgio.me @ f3504421d4658345917321dad40b79068aa760a8

 1---
 2title:  "Enable NFS on K3S"
 3date:   2021-12-26
 4tags: ['kubernetes', 'linux', 'helm', 'k3s']
 5---
 6
 7By default [[https://k3s.io/][K3S]] comes only with [[https://github.com/rancher/local-path-provisioner][local-path]] storage class, and if you are running
 8with more than one node in your cluster you may want to use a more "distributed"
 9solution. For may case I opted for NFS.
10
11To check the current storage class you can run:
12
13#+BEGIN_SRC bash
14k3s kubectl get storageclasses
15#+END_SRC
16
17And it will print something like:
18
19#+BEGIN_SRC
20NAME                   PROVISIONER                                     RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
21local-path (default)   rancher.io/local-path                           Delete          WaitForFirstConsumer   false                  154d
22#+END_SRC
23
24To start adding First you need to install [[https://github.com/helm/helm][helm]] on your server. To do so you may
25run:
26
27#+BEGIN_SRC bash
28curl -sSL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
29#+END_SRC
30
31*Be careful when running scripts directly into bash always check the source*
32*Sometimes is also recommended to do not pipe directly to bash*
33
34Once it is installed we need to add the [[https://kubernetes.io/docs/concepts/storage/storage-classes/#nfs][NFS storage classes]]. It has two
35providers, I have chose [[https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner][NFS Subdir External Provisioner]].
36
37Add the helm repo
38
39#+BEGIN_SRC bash
40helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/
41#+END_SRC
42
43Then we need to actually install the provider
44
45
46#+BEGIN_SRC bash
47helm install nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \
48    --set nfs.server=x.x.x.x \
49    --set nfs.path=/exported/path
50#+END_SRC
51
52Set the ~nfs.server~ and ~nfs.path~ accordingly with your setup.
53
54After that if we run ~k3s kubectl get storageclasses~ it will now print another
55NFS provider:
56
57#+BEGIN_SRC
58NAME                   PROVISIONER                                     RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
59local-path (default)   rancher.io/local-path                           Delete          WaitForFirstConsumer   false                  154d
60nfs-client             cluster.local/nfs-subdir-external-provisioner   Delete          Immediate              true                   76m
61#+END_SRC