Mount NFS file systems
You can mount NFS file systems to Virtual Machine instances and Kubernetes Engine workloads.
Mount on Virtual Machine instances
To mount an NFS file system to a Virtual Machine instance:
Connect to a Virtual Machine instance
- Go to KakaoCloud console > Beyond Compute Service > Virtual Machine.
- In the Instance menu, click the [⋮] button for the Virtual Machine instance to mount, then select SSH connection.
- In the SSH connection pop-up, click the [Copy] button to copy the command.
- Connect to the instance using the copied command. For details about connecting to an instance using SSH, see Virtual Machine > Create and connect instances.
Install NFS package
-
Check the instance OS and install the NFS package using the following command.
- CentOS command
- Ubuntu command
CentOSsudo yum install -y nfs-utilsUbuntusudo apt-get install nfs-commonIf the NFS package is not installed, the following error occurs. If this error occurs, install the package by referring to Install NFS package.
Error when the NFS package is not installedsudo: unable to resolve host for[Virtual Machine instance name]
mount: /home/deploy/nfs-mount: bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program. -
Verify that the installation is complete.
Mount NFS
-
Connect to the Virtual Machine instance and create an NFS mount directory.
mkdir {mount directory} -
Check that the mount directory was created.
ls -la -
Confirm that the nfs-mount directory was created.
drwxr-xr-x 2 deploy deploy 4096 Dec 13 06:17 nfs-mount -
Mount the file system using the mount information from the file system details and the mount directory you created.
sudo mount -t nfs {file system private IP}:/{file share name} {created mount directory} -
Check the mount status.
mount -
Confirm that the mount completed successfully.
11.111.11.111:/share_storage on /home/deploy/nfs-mount type nfs4 (rw,relatime,vers=4.2,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=10.183.51.186,local_lock=none,addr=11.111.11.111)
Unmount NFS
To unmount NFS, run the following command.
umount {mount directory}
Mount on Kubernetes Engine
To mount an NFS file system on Kubernetes Engine:
Allow NFS access
-
Check the Worker Node IP address of Kubernetes Engine.
kubectl --kubeconfig={kube_config} get nodes -o wide
Check Worker Node IP address -
Allow the Worker Node IP address in File Storage access control settings.
- Add the Worker Node IP address to the allowed private IP addresses in Access control settings on the File Storage > Basic file system > Network tab.
Create PV
-
Create a YAML file for the PV (Persistent Volume).
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-nfs-share-storage
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
nfs:
server: {file system private IP}
path: /{file share name}
storageClassName: "nfs-share-storage" -
Apply the PV YAML file to Kubernetes Engine.
kubectl --kubeconfig={kube_config} apply -f nfs-pv.yaml -
Check whether it was applied.
kubectl --kubeconfig={kube_config} get pv
Check PV application
Create PVC
-
Create a PVC (Persistent Volume Claim) YAML file that includes the Persistent Volume.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-nfs-share-storage
spec:
storageClassName: "nfs-share-storage"
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi -
Apply the PVC YAML file to Kubernetes Engine.
kubectl --kubeconfig={kube_config} apply -f nfs-pvc.yaml -
Check whether it was applied.
kubectl --kubeconfig={kube_config} get pvc -
Confirm that it was applied.
Check PV application
Create Deployment
-
Create a Deployment YAML file to mount the PVC to Pods deployed on Kubernetes Engine.
apiVersion: apps/v1
kind: Deployment
metadata:
name: {Deployment name}
spec:
selector:
matchLabels:
app: {Label name}
replicas: 2
template:
metadata:
labels:
app: {Label name}
spec:
containers:
- name: master
image: {user container URL}
ports:
- containerPort: 77
volumeMounts:
- mountPath: /data/share-storage
name: pvc-volume
volumes:
- name: pvc-volume
persistentVolumeClaim:
claimName: pvc-nfs-share-storage -
Apply the Deployment YAML file to Kubernetes Engine.
kubectl --kubeconfig={kube_config} apply -f deployment.yaml -
Check whether it was applied.
kubectl --kubeconfig={kube_config} get deployments -
Confirm that it was applied.
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-demo 2/2 2 2 1d -
Check the Pods created by the Deployment.
kubectl --kubeconfig={kube_config} get pods -
Confirm that the Pods were created.
NAME READY STATUS RESTARTS AGE
nginx-demo- 1/1 Running 0 1d
nginx-demo- 1/1 Running 0 1d
Check mount status
-
Connect to the created Pod.
kubectl --kubeconfig={kube_config} exec -it {Pod name} -- /bin/bash -
Check whether the mount completed successfully.
$ mountip:/share_storage on /data/share-storage type nfs4 (rw,relatime,vers=4.2,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=ip,local_lock=none,addr=ip)