Deploy Network File System (NFS) Server
Steps to deploy NFS server on Rancher
Overview
Pre-requisites
Steps
Last updated
Was this helpful?
Steps to deploy NFS server on Rancher
Last updated
Was this helpful?
Was this helpful?
[ec2-user@ip-10-0-14-162 ~]$ sudo -i[root@ip-10-0-14-162 ~]# yum install -y nfs-utilsLast metadata expiration check: 0:14:06 ago on Thu May 30 08:24:15 2024.
Package nfs-utils-1:2.5.4-2.rc3.amzn2023.0.3.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete![root@ip-10-0-14-162 ~]# systemctl enable rpcbind
[root@ip-10-0-14-162 ~]# systemctl enable nfs-server
[root@ip-10-0-14-162 ~]# systemctl start rpcbind
[root@ip-10-0-14-162 ~]# systemctl start nfs-server[root@ip-10-0-14-162 ~]# mkdir -p /nfs-share[root@ip-10-0-14-162 ~]# blkid /dev/sdb
[root@ip-10-0-14-162 ~]# mkfs.xfs /dev/sdbmeta-data=/dev/sdb isize=512 agcount=16, agsize=3276800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=1 inobtcount=1
data = bsize=4096 blocks=52428800, imaxpct=25
= sunit=1 swidth=1 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=25600, version=2
= sectsz=512 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0dmesg | grep sdb
journalctl -xe | grep sdbxfs_repair /dev/sdb[root@ip-10-0-14-162 ~]# vi /etc/exports/nfs-share *(rw,sync,no_subtree_check,no_root_squash,insecure)[root@ip-10-0-14-162 ~]# exportfs -rv[root@ip-10-0-14-162 ~]# showmount -eExport list for ip-10-0-14-162.ap-south-1.compute.internal:
/nfs-share *apiVersion: apps/v1
kind: DaemonSet
metadata:
name: install-nfs-common
namespace: kube-system
spec:
selector:
matchLabels:
app: install-nfs-common
template:
metadata:
labels:
app: install-nfs-common
spec:
hostPID: true
hostNetwork: true
containers:
- name: install
image: busybox:latest
command: ["/bin/sh", "-c"]
args:
- nsenter --mount=/proc/1/ns/mnt -- /bin/sh -c 'apt update && apt install -y nfs-common' && sleep infinity
securityContext:
privileged: true
restartPolicy: Always[root@ip-10-0-14-162 ~]# kubectl apply -f nfs.yamlapiVersion: v1
kind: Namespace
metadata:
name: nfs
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: nfs-client-provisioner
namespace: nfs
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: nfs-client-provisioner-runner
rules:
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["get", "list", "watch", "create", "delete"]
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["get", "list", "watch", "update"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "update", "patch"]
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["get", "list", "watch", "create", "update", "delete"]
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["get", "list", "watch", "create", "update", "delete"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: run-nfs-client-provisioner
subjects:
- kind: ServiceAccount
name: nfs-client-provisioner
namespace: nfs
roleRef:
kind: ClusterRole
name: nfs-client-provisioner-runner
apiGroup: rbac.authorization.k8s.io
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: nfs
annotations:
storageclass.kubernetes.io/is-default-class: "true"
provisioner: nfs-test
parameters:
archiveOnDelete: "false"
reclaimPolicy: Delete
volumeBindingMode: Immediate
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nfs-client-provisioner
namespace: nfs
spec:
replicas: 1
selector:
matchLabels:
app: nfs-client-provisioner
strategy:
type: Recreate
template:
metadata:
labels:
app: nfs-client-provisioner
spec:
serviceAccountName: nfs-client-provisioner
containers:
- name: nfs-client-provisioner
image: k8s.gcr.io/sig-storage/nfs-subdir-external-provisioner:v4.0.2
volumeMounts:
- name: nfs-client-root
mountPath: /persistentvolumes
env:
- name: PROVISIONER_NAME
value: nfs-test
- name: NFS_SERVER
value: 10.0.14.162 # Replace with your NFS server IP
- name: NFS_PATH
value: /nfs-share # Replace with your NFS share path
volumes:
- name: nfs-client-root
nfs:
server: 10.0.14.162 # Replace with your NFS server IP
path: /nfs-share # Replace with your NFS share path