-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from lalithkota/main
Updated NFS Install scripts
- Loading branch information
Showing
4 changed files
with
68 additions
and
96 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 " |