aboutsummaryrefslogtreecommitdiff
path: root/content/logs/2021-12-26-nfs-k3s.org
blob: 5785d4f99db2f3d74898a61808dc41a50184cafd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---
title:  "Enable NFS on K3S"
date:   2021-12-26
tags: ['kubernetes', 'linux', 'helm', 'k3s']
---

By default [[https://k3s.io/][K3S]] comes only with [[https://github.com/rancher/local-path-provisioner][local-path]] storage class, and if you are running
with more than one node in your cluster you may want to use a more "distributed"
solution. For may case I opted for NFS.

To check the current storage class you can run:

#+BEGIN_SRC bash
k3s kubectl get storageclasses
#+END_SRC

And it will print something like:

#+BEGIN_SRC
NAME                   PROVISIONER                                     RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
local-path (default)   rancher.io/local-path                           Delete          WaitForFirstConsumer   false                  154d
#+END_SRC

To start adding First you need to install [[https://github.com/helm/helm][helm]] on your server. To do so you may
run:

#+BEGIN_SRC bash
curl -sSL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
#+END_SRC

*Be careful when running scripts directly into bash always check the source*
*Sometimes is also recommended to do not pipe directly to bash*

Once it is installed we need to add the [[https://kubernetes.io/docs/concepts/storage/storage-classes/#nfs][NFS storage classes]]. It has two
providers, I have chose [[https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner][NFS Subdir External Provisioner]].

Add the helm repo

#+BEGIN_SRC bash
helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/
#+END_SRC

Then we need to actually install the provider


#+BEGIN_SRC bash
helm install nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \
    --set nfs.server=x.x.x.x \
    --set nfs.path=/exported/path
#+END_SRC

Set the ~nfs.server~ and ~nfs.path~ accordingly with your setup.

After that if we run ~k3s kubectl get storageclasses~ it will now print another
NFS provider:

#+BEGIN_SRC
NAME                   PROVISIONER                                     RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
local-path (default)   rancher.io/local-path                           Delete          WaitForFirstConsumer   false                  154d
nfs-client             cluster.local/nfs-subdir-external-provisioner   Delete          Immediate              true                   76m
#+END_SRC