Skip to content

Commit

Permalink
Merge pull request #23 from lalithkota/main
Browse files Browse the repository at this point in the history
Updated NFS Install scripts
  • Loading branch information
pjoshi751 authored May 16, 2024
2 parents b0ea8ac + ce6a790 commit 47d2e0e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 96 deletions.
40 changes: 0 additions & 40 deletions kubernetes/nfs-client/install-nfs-client-provisioner.sh

This file was deleted.

25 changes: 25 additions & 0 deletions kubernetes/nfs-client/install-nfs-csi-driver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

export NS=${NS:-kube-system}
export NFS_SERVER=${NFS_SERVER:-}
export NFS_PATH=${NFS_PATH:-/srv/nfs/global}

if [ -z "$NFS_SERVER" ]; then
echo "NFS_SERVER not provided; EXITING;";
exit 1;
fi
if [ -z "$NFS_PATH" ]; then
echo "NFS_PATH not provided; EXITING;";
exit 1;
fi

echo Add helm csi-driver-nfs repo
helm repo add csi-driver-nfs https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/charts
helm repo update

echo "Installing CSI Driver for NFS"
helm -n $NS upgrade --install csi-driver-nfs csi-driver-nfs/csi-driver-nfs \
--version v4.7.0

echo "Installing NFS CSI Storage Class"
envsubst '${NFS_PATH},${NFS_SERVER}' < storage-class.template.yaml | kubectl apply -f -
14 changes: 14 additions & 0 deletions kubernetes/nfs-client/storage-class.template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
annotations:
storageclass.kubernetes.io/is-default-class: "true"
name: nfs-csi
parameters:
mountPermissions: "0"
server: ${NFS_SERVER}
share: ${NFS_PATH}
subDir: '${pvc.metadata.namespace}-${pvc.metadata.name}-${pv.metadata.name}'
provisioner: nfs.csi.k8s.io
reclaimPolicy: Retain
volumeBindingMode: Immediate
85 changes: 29 additions & 56 deletions nfs-server/install-nfs-server.sh
Original file line number Diff line number Diff line change
@@ -1,61 +1,34 @@
#!/bin/sh
# Script to install NFS server.
# Usage: ./install-nfs-server.sh.

#This function is to prompt weather user is able to access sudo or not!!!!
chkSudoer(){
if [ "$USER"=="root" ]; then
return ;
fi
count=$( groups $USER | grep "sudo" | wc -l )
if [ $count -eq 0 ]; then
echo " $(tput setaf 1) User $USER does not has sudo access; EXITING $(tput sgr 0) "
exit 1;
else
return
fi
}

## The script starts from here
echo "This Script will Install NFS server."

chkSudoer # calling chkSudoer function

read -p "Please Enter Environment Name: " env

if [ -z $env ]; then
echo "Environment Name not provided; EXITING;";
exit 1;
#!/bin/bash

export NFS_PATH=${NFS_PATH:-/srv/nfs}

if [ $USER != "root" ]; then
echo "Run this as root"
exit 1
fi
nfsUser=nfsnobody
nfsStorage=/srv/nfs/openg2p/$env
echo "\n$(tput setaf 9)[ Install NFS Server ] $(tput sgr 0)"
sudo apt update
sudo apt install nfs-kernel-server -y

echo "\n$(tput setaf 9)[ Add User For NFS ] $(tput sgr 0)"
sudo useradd $nfsUser
echo "User $nfsUser created"
echo "\n$(tput setaf 9)[ Install NFS Server ] $(tput sgr 0)"

apt update
apt install nfs-kernel-server -y

echo "\n$(tput setaf 9)[ Create NFS Storage ] $(tput sgr 0)"
sudo mkdir -p $nfsStorage
sudo chown -R $nfsUser:$nfsUser $nfsStorage
sudo chmod 777 $nfsStorage
echo "NFS storage $nfsStorage created."

echo "\n$(tput setaf 9)[ Enable & Start NFS server ] $(tput sgr 0)"
sudo systemctl enable nfs-kernel-server
sudo systemctl start nfs-kernel-server
echo "NFS server started and enabled."

echo "\n$(tput setaf 9)[ Update NFS export file ] $(tput sgr 0)"
sudo echo "$nfsStorage *(rw,sync,no_root_squash,no_all_squash,insecure,subtree_check)" | sudo tee -a /etc/exports
sudo cat /etc/exports | sort | uniq > /tmp/exports
sudo mv /tmp/exports /etc/exports
echo "Updated NFS export file."

echo "\n$(tput setaf 9)[ Export the NFS Share Directory ] $(tput sgr 0)"
sudo exportfs -rav

echo "\n NFS Server Path: $nfsStorage "
mkdir -p $NFS_PATH
chmod 777 $NFS_PATH
echo "NFS storage $NFS_PATH created."

echo "\n$(tput setaf 9)[ Enable & Start NFS server ] $(tput sgr 0)"
systemctl enable nfs-kernel-server
systemctl start nfs-kernel-server
echo "NFS server started and enabled."

echo "\n$(tput setaf 9)[ Update NFS export file ] $(tput sgr 0)"
echo "$NFS_PATH *(rw,sync,no_root_squash,no_all_squash,insecure,subtree_check)" | tee -a /etc/exports
cat /etc/exports | sort | uniq > /tmp/exports
mv /tmp/exports /etc/exports
echo "Updated NFS export file."

echo "\n$(tput setaf 9)[ Export the NFS Share Directory ] $(tput sgr 0)"
exportfs -rav

echo "\n NFS Server Path: $NFS_PATH "

0 comments on commit 47d2e0e

Please sign in to comment.