NFS and Microk8s
Jump to navigation
Jump to search
It is important to understand this file. Client ip addresses are highly trusted and controlled kubernetes nodes.
Do not run files on nas directory it should only be used as a file store.
#!/usr/bin/env bash if [ "$#" -ne 2 ]; then echo "Usage: $0 <uuid> <nfs node type server/client>" echo "Example: $0 28a1f1f8-e686-11eb-bf45-7f257ca7269b server" exit fi uuid=$1 node_type=$2 server_host=nas server_mnt=/$uuid server_net_mnt=${server_host}:{server_dir} # local_mnt=/var/snap/microk8s/common/nas-nfs-standard client_mnt=/opt/local-path-provisioner client_ips="10.x.x.x 10.x.x.x 10.x.x.x" if ! [[ $uuid =~ ^\{?[A-F0-9a-f]{8}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{12}\}?$ ]]; then echo "E: Invalid uuid format." exit fi install_client(){ echo Installing client. grep $server_mnt /etc/fstab || sudo echo "$server_net_mnt $client_mnt nfs" | sudo tee -a /etc/fstab sudo mkdir -p $client_mnt && sudo chmod 0755 $client_mnt sudo apt install -y nfs-client # nfs-common } install_server(){ echo Installing server. sudo apt install nfs-kernel-server sudo mkdir -p $server_mnt && sudo chmod 0755 $server_mnt sudo mv /etc/exports /etc/exports.bkp for ip in $client_ips; do echo "$server_mnt $ip(rw,sync,no_subtree_check,insecure,no_root_squash)" | sudo tee -a /etc/exports done sudo chmod 0644 /etc/exports sudo systemctl reload nfs-server } install_localpathprov(){ # https://github.com/rancher/local-path-provisioner kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml kubectl create -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/examples/pvc/pvc.yaml kubectl create -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/examples/pod/pod.yaml } if [[ "$node_type" == "server" ]]; then install_server elif [[ "$node_type" == "client" ]]; then install_client else echo "E: Unsupported node_type." fi
Testing
mkdir ~/mnt sudo mount -t nfs $server_host:/28a1f1f8-e686-11eb-bf45-7f257ca7269b ~/mnt echo hi > ~/mnt/hi.txt cat ~/mnt/hi.txt