gabrielgio.me @ 5768522de4e0ceccff1455da7171f4674339230c

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