Skip to main content

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

  1. Go to KakaoCloud console > Beyond Compute Service > Virtual Machine.
  2. In the Instance menu, click the [⋮] button for the Virtual Machine instance to mount, then select SSH connection.
  3. In the SSH connection pop-up, click the [Copy] button to copy the command.
  4. 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

  1. Check the instance OS and install the NFS package using the following command.

    CentOS
    sudo yum install -y nfs-utils
  2. Verify that the installation is complete.

Mount NFS

  1. Connect to the Virtual Machine instance and create an NFS mount directory.

    mkdir {mount directory}
  2. Check that the mount directory was created.

    ls -la
  3. Confirm that the nfs-mount directory was created.

    drwxr-xr-x 2 deploy deploy 4096 Dec 13 06:17 nfs-mount
  4. 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}
  5. Check the mount status.

    mount
  6. 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

  1. Check the Worker Node IP address of Kubernetes Engine.

    kubectl --kubeconfig={kube_config} get nodes -o wide

    image. Check Worker Node IP address Check Worker Node IP address

  2. 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

  1. 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"
  2. Apply the PV YAML file to Kubernetes Engine.

    kubectl --kubeconfig={kube_config} apply -f nfs-pv.yaml
  3. Check whether it was applied.

    kubectl --kubeconfig={kube_config} get pv

    image. Check PV application Check PV application

Create PVC

  1. 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
  2. Apply the PVC YAML file to Kubernetes Engine.

    kubectl --kubeconfig={kube_config} apply -f nfs-pvc.yaml
  3. Check whether it was applied.

    kubectl --kubeconfig={kube_config} get pvc
  4. Confirm that it was applied.

    image. Check PV application Check PV application

Create Deployment

  1. 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
  2. Apply the Deployment YAML file to Kubernetes Engine.

    kubectl --kubeconfig={kube_config} apply -f deployment.yaml
  3. Check whether it was applied.

    kubectl --kubeconfig={kube_config} get deployments
  4. Confirm that it was applied.

    NAME         READY   UP-TO-DATE   AVAILABLE   AGE
    nginx-demo 2/2 2 2 1d
  5. Check the Pods created by the Deployment.

    kubectl --kubeconfig={kube_config} get pods
  6. 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

  1. Connect to the created Pod.

    kubectl --kubeconfig={kube_config} exec -it {Pod name} -- /bin/bash
  2. Check whether the mount completed successfully.

    $ mount
    ip:/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)