Kubernetes Persistent Volumes using NFS

Last modified by matto on 2018/09/03 05:19

 

Setup:

Ubuntu 18.04

Enable private networking

First of all, enable private networking on your hosting control panel (I'm using vultr.com)

vi /etc/netplan/10-ens7.yaml

Make sure that it looks like:

network:
  version: 2
  renderer: networkd
  ethernets:
    ens7:
      mtu: 1450
      dhcp4: no
      addresses: [{your host private IP}/16]

 Replace the IP address 10.1.36.2 with the one, which is displayed in your control panel in the private network settings

netplan apply

After that, you should see a new network interfacen, when you type:

ifconfig

Do this for each host in your cluster.

Then, you should be able to ping these private IPs between your host in your private network.

Install NFS server

apt install nfs-kernel-server

vi /etc/exports

/share 10.1.36.2/16(rw,sync,no_subtree_check,no_root_squash)

Replace 10.1.36.2 with your own private networking IP on which you have the server running.
Make sure that path you've specified is accessible and has correct permissions

apt-get install nfs-common

Then, try to mount the NFS folder: 

mkdir /mnt/nfs

mount 10.1.36.2:/share /mnt/nfs 

(Replace 10.1.36.2 with your own IP)

Voila ! when you access /mnt/nfs, it serves content from /share

This server shall be accessible within your private network. Make sure that you don't have it accessible to the outside world.

For further configuration options, please refer to 

Creating Kubernetes Persistent Volume

This assumes, that you should have your kubernetes cluster up and running.

Create a new file: pv.yaml:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv0001
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: slow
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    path: /share
    server: 10.1.96.3

(Replace 10.1.96.3 with your own IP and /share with the path the NFS server exports)

After that, execute:

kc create -f pv.yaml 

Check, if the Kubernetes persistent volume has been created successfully:

kubectl get pv

You should see something like:

1528261366040-601.png

Tags:
Created by matto on 2018/06/06 04:25
    
CodeGravity.com ©
Web
Analytics Made Easy - StatCounter