Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Exercise 9.2: Creating A Persistent NFS Volume (PV)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

9.6.

LABS 1

Exercise 9.2: Creating a Persistent NFS Volume (PV)


We will first deploy an NFS server. Once tested we will create a persistent NFS volume for containers to claim.

1. Install the software on your master node.

student@lfs458-node-1a0a:~$ sudo apt-get update && sudo \


apt-get install -y nfs-kernel-server
<output_omitted>

2. Make and populate a directory to be shared. Also give it similar permissions to /tmp/

student@lfs458-node-1a0a:~$ sudo mkdir /opt/sfw

student@lfs458-node-1a0a:~$ sudo chmod 1777 /opt/sfw/

student@lfs458-node-1a0a:~$ sudo bash -c \


'echo software > /opt/sfw/hello.txt'

3. Edit the NFS server file to share out the newly created directory. In this case we will share the directory with all. You can
always snoop to see the inbound request in a later step and update the file to be more narrow.
student@lfs458-node-1a0a:~$ sudo vim /etc/exports
/opt/sfw/ *(rw,sync,no_root_squash,subtree_check)

4. Cause /etc/exports to be re-read:


student@lfs458-node-1a0a:~$ sudo exportfs -ra

5. Test by mounting the resource from your second node.


student@lfs458-worker:~$ sudo apt-get -y install nfs-common
<output_omitted>

student@lfs458-worker:~$ showmount -e k8smaster


Export list for k8smaster:
/opt/sfw *

student@lfs458-worker:~$ sudo mount k8smaster:/opt/sfw /mnt

student@lfs458-worker:~$ ls -l /mnt
total 4
-rw-r--r-- 1 root root 9 Sep 28 17:55 hello.txt

6. Return to the master node and create a YAML file for the object with kind, PersistentVolume. Use the hostname
of the master server and the directory you created in the previous step. Only syntax is checked, an incorrect name
or directory will not generate an error, but a Pod using the resource will not start. Note that the accessModes do not
currently affect actual access and are typically used as labels instead.

student@lfs458-node-1a0a:~$ vim PVol.yaml

LFS258: V 2019-08-12 © Copyright the Linux Foundation 2019. All rights reserved.
2 CHAPTER 9. VOLUMES AND DATA

PVol.yaml
1 apiVersion: v1
2 kind: PersistentVolume
3 metadata:
4 name: pvvol-1
5 spec:
6 capacity:
7 storage: 1Gi
8 accessModes:
9 - ReadWriteMany
10 persistentVolumeReclaimPolicy: Retain
11 nfs:
12 path: /opt/sfw
13 server: k8smaster #<-- Edit to match master node
14 readOnly: false

7. Create the persistent volume, then verify its creation.


student@lfs458-node-1a0a:~$ kubectl create -f PVol.yaml
persistentvolume/pvvol-1 created

student@lfs458-node-1a0a:~$ kubectl get pv


NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS
CLAIM STORAGECLASS REASON AGE
pvvol-1 1Gi RWX Retain Available 4s

LFS258: V 2019-08-12 © Copyright the Linux Foundation 2019. All rights reserved.

You might also like