Persistent Volume using SFS
Deploy a resilient and fault-tolerant persistent volume utilizing SFS within a Kubernetes environment.
Step 1: Create SFS (Scalable File System)
- You have to click on Scalable File System (SFS) from the left sidebar menu.
- After that, click on the 'click here' link or the Create SFS icon to create a Scalable File System (SFS).
- After clicking on Create Scalable File System, give a name to your SFS, select the plan and VPC, and then click on the Create SFS button.
- After clicking on the Create SFS button, your created Scalable File System will be shown like this.
Step 2: Grant All Access
- To grant all access, select a particular SFS (Scalable File System) and click on Grant all access under actions.
- After clicking Grant all access, you can see the popup below. If you click on the Grant button, it will grant full access to all resources like Nodes, LB, Kubernetes, and DBaaS within the same VPC to access this SFS.
- Permission has been granted, and the process has started. It should be completed within a few minutes. You can view the configured Virtual Private Cloud (VPC) under the ACL tab.
Step 3: Download Kubeconfig.yaml File
- After launching Kubernetes, download the Kube config file.
-
Please make sure
kubectl
is installed on your system. -
To install
kubectl
, follow this documentation. -
Run the below command in Kubernetes to retrieve information about the nodes in the cluster:
kubectl get nodes
Step 4: Connect Using the Persistent Volume Resource
- You can also use the SFS volume through a PersistentVolumeClaim. First, create a PersistentVolume that holds the information about the SFS server. Then, create a PersistentVolumeClaim that will be bound to the PersistentVolume. Finally, you can mount the PVC into a pod.
Create PersistentVolume
Below is the YAML for the PersistentVolume that provisions a volume from the /data
directory of the SFS server. Create a file named pv.yaml
and add the following code to it:
cat << EOF > pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
labels:
name: mynfs # name can be anything
spec:
storageClassName: manual # same storage class as pvc
capacity:
storage: 200Mi
accessModes:
- ReadWriteMany
nfs:
server: 10.10.12.10 # SFS server IP address
path: "/data"
EOF
- To run PersistentVolume YAML file, you have to run below command.
kubectl apply -f pv.yaml
Step 5: Create a PersistentVolumeClaim
-
Now, we have to create a PersistentVolumeClaim. This PVC will be bounded with the PersistentVolume we have created above.
-
Below is the YAML for the PersistentVolumeClaim that we are going to create.You have to create pvc.yaml file and put the below code into this pvc.yaml file.
cat << EOF > pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc
spec:
storageClassName: manual
accessModes:
- ReadWriteMany # must be the same as PersistentVolume
resources:
requests:
storage: 50Mi
EOF
- To run PersistentVolumeClaim YAML file, you have to run below command.
kubectl apply -f pvc.yaml
Step 6: Create a Deployment
- You have to create deployment.yaml file and put the below code into this deployment.yaml file.
cat << EOF > deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: nfs-nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
volumes:
- name: nfs-test
persistentVolumeClaim:
claimName: nfs-pvc # same name of pvc that was created
containers:
- image: nginx
name: nginx
volumeMounts:
- name: nfs-test # name of volume should match claimName volume
mountPath: /usr/share/nginx/html # mount inside of contianer
EOF
- To run deployment YAML file, you have to run below command.
kubectl apply -f deployment.yaml
Step 7: Get Pod Details
- Run the below command to retrieve information about the pods running within a Kubernetes cluster.
kubectl get pod
Step 8: Execution
- Run the below command to execute a command inside a running container in a Kubernetes pod.
kubectl exec -it nfs-nginx-85d5ffd747-n88f9 -- /bin/bash
Step 9: Disk Space Usage
- Run the following command to display disk space usage statistics for file systems in a human-readable format.
df -h
- This command will list information about all mounted file systems on your system, including total size, used space, available space, and usage percentage. The sizes will be displayed in an easy-to-read format. This command is useful for monitoring disk space usage and identifying potential storage issues.
Alternative way to use — Dynamic provisioning using StorageClass :
Steps 1,2 and 3 are same for this method.
Step 4: Install helm
-
To install Helm, follow this documentation. Click here :
install Helm <https://helm.sh/docs/intro/quickstart/#install-helm>
_ -
To run helm, you have to run below commands
helm repo add csi-driver-nfs https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/charts
helm install csi-driver-nfs csi-driver-nfs/csi-driver-nfs --namespace kube-system --version v4.9.0
Step 5: Create sc.yaml file
- You have to create sc.yaml file and put the below code into this sc.yaml file.
cat << EOF > sc.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: nfs-csi
provisioner: nfs.csi.k8s.io
parameters:
server: 10.10.12.10 # SFS server IP address
share: /data
reclaimPolicy: Delete
volumeBindingMode: Immediate
mountOptions:
- nfsvers=4.1
EOF
- To run sc.yaml file, you have to run below command.
kubectl apply -f sc.yaml
Step 6: Create pvc-sc.yaml file
- After that you have to run pvc-sc.yaml file and put the below code into this pvc-sc.yaml file.
cat << EOF > pvc-sc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc-1
spec:
accessModes:
- ReadWriteOnce
storageClassName: nfs-csi # Reference to the NFS storage class
resources:
requests:
storage: 500Gi # Requested storage size
EOF
- To run pvc-sc.yaml file, you have to run below command.
kubectl apply -f pvc-sc.yaml
Step 7: Create a Deployment file
- You have to create deployment.yaml file and put the below code into this deployment.yaml file.
cat << EOF > deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: nfs-nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
volumes:
- name: nfs-test
persistentVolumeClaim:
claimName: nfs-pvc # same name of pvc that was created
containers:
- image: nginx
name: nginx
volumeMounts:
- name: nfs-test # name of volume should match claimName volume
mountPath: /usr/share/nginx/html # mount inside of contianer
EOF
- To run deployment YAML file, you have to run below command.
kubectl apply -f deployment.yaml
Step 8: Get Pod Details
- Run the following command to get details of the pods running in your Kubernetes cluster.
kubectl get pods
Step 9: Execution
- Run the below command to execute a command inside a running container in a Kubernetes pod.
kubectl exec -it nfs-nginx-85d5ffd747-n88f9 -- /bin/bash
Step 10: Disk Space Usage
- Run the following command to display disk space usage statistics for file systems in a human-readable format.
df -h
Disable All Access
Note: If you disable all access, it will deny full access to all resources such as Nodes, Load Balancers, Kubernetes, and DBaaS within the same VPC from accessing this SFS.
- If you want to disable all access from the SFS (Scalable File System), click on Disable all access under actions.
- After clicking the Disable all access action, you will see a popup. If you click the Disable button, access will be denied from all the services.
- The process to disable access has started. It should be completed within a few minutes. You can view the configured Virtual Private Cloud (VPC) under the 'ACL' tab.