edit-icon download-icon

Use Alibaba Cloud NAS

Last Updated: Apr 25, 2018

You can use the Alibaba Cloud NAS data volumes in Container Service Kubernetes clusters.

Currently, Alibaba Cloud NAS provides the following two Kubernetes mount methods:

Static storage volumes

You can use Alibaba Cloud NAS file storage service by using the flexvolume plug-in provided by Alibaba Cloud or the NFS drive of Kubernetes.

Prerequisites

Before using NAS data volumes, you must create a file system in the NAS console and add the mount point of a Kubernetes cluster in the file system (for more information, see Add a mount point). The created NAS file system and your cluster must be in the same Virtual Private Cloud (VPC).

Use flexvolume plug-in

Use the flexvolume plug-in and then you can use the Alibaba Cloud NAS data volumes by using the volume method or using PV/PVC.

Instructions:

  • NAS is a shared storage and can provide shared storage service for multiple pods at the same time.
  • server: The mount point of the NAS data disk. Pay attention to distinguish whether the network type is classic or VPC. For more information, see Manage mount points.
  • path: The mount directory for connecting to the NAS data volumes. You can mount NAS data volumes to a NAS sub-directory. The system automatically creates the sub-directory if the sub-directory does not exist and mounts the NAS data volumes to the created sub-directory.
  • vers: Defines the version number of NFS mount protocol. 4.0 is supported.
  • mode: Defines the access permission of the mount directory. If the NAS disk contains a huge amount of data, configuring the mode leads to the slow mounting or even the mounting failure.
    Note: The mount permission cannot be configured if you mount the NAS data volumes to the NAS root directory.

Use volume method

Use the nas-deploy.yaml file to create the pod.

  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: "flexvolume-nas-example"
  5. spec:
  6. containers:
  7. - image: "nginx"
  8. name: "nginx"
  9. volumeMounts:
  10. - mountPath: "/data"
  11. name: "nas1"
  12. volumes:
  13. - name: "nas1"
  14. flexVolume:
  15. driver: "alicloud/nas"
  16. options:
  17. server: "xxxxxx.cn-hangzhou.nas.aliyuncs.com" #Enter the NAS mount address.
  18. path: "/k8s"
  19. vers: "4.0"

Use PV/PVC

Step 1 Create PV

You can create NAS data volumes in the Container Service console or by using the YAML file.

  • Create PV by using YAML file

    Use the nas-pv.yaml file to create the PV.

    1. apiVersion: v1
    2. kind: PersistentVolume
    3. metadata:
    4. name: pv-nas
    5. spec:
    6. capacity:
    7. storage: 5Gi
    8. storageClassName: nas
    9. accessModes:
    10. - ReadWriteMany
    11. flexVolume:
    12. driver: "alicloud/nas"
    13. options:
    14. server: "0cd8b4a576-uih75.cn-hangzhou.nas.aliyuncs.com"
    15. path: "/k8s"
    16. vers: "4.0"
  • Create NAS data volumes in Container Service console

    1. Log on to the Container Service console.

    2. Click Kubernetes > Clusters > Storage in the left-side navigation pane.

    3. Select the cluster from the Clusters drop-down list and then click Create in the upper-right corner.

      1

    4. The Create Data Volume dialog box appears. Configure the data volume parameters.

      • Type: Select NAS in this example.
      • Name: Enter the name of the data volume you are about to create. The data volume name must be unique in the cluster. In this example, enter pv-nas.
      • Capacity: Enter the capacity of the data volume to be created. Make sure the capacity cannot exceed the disk capacity.
      • Access Mode: ReadWriteMany is selected by default.
      • Mount Point Domain Name: Enter the mount address of the mount point in the NAS file system for the cluster.
      • Path: The sub-directory under the NAS path, which starts with a forward slash (/). The data volume is mounted to the specified sub-directory after being created.
        • If this sub-directory does not exist in the NAS root directory, the data volume is mounted after the sub-directory is created by default.
        • If this field is left empty, the data volume is mounted to the NAS root directory by default.
      • Privilege: Configure the access permission of the mount directory, such as 755, 644, and 777.
        • You can only configure the privilege when the data volume is mounted to the NAS sub-directory, that is, you cannot configure the privilege if the data volume is mounted to the NAS root directory.
        • If this field is left empty, use the permissions of the NAS files by default.
      • Tag: Click Add Tag to add tags for this data volume.

      1

    5. Click Create after the configurations.

Step 2 Create PVC

Use the nas-pvc.yaml file to create the PVC.

  1. kind: PersistentVolumeClaim
  2. apiVersion: v1
  3. metadata:
  4. name: pvc-nas
  5. spec:
  6. accessModes:
  7. - ReadWriteMany
  8. storageClassName: nas
  9. resources:
  10. requests:
  11. storage: 5Gi

Step 3 Create pod

Use the nas-pod.yaml file to create the pod.

  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: "flexvolume-nas-example"
  5. spec:
  6. containers:
  7. - name: "nginx"
  8. image: "nginx"
  9. volumeMounts:
  10. - name: pvc-nas
  11. mountPath: "/data"
  12. volumes:
  13. - name: pvc-nas
  14. persistentVolumeClaim:
  15. claimName: pvc-nas

Use NFS drive of Kubernetes

Step 1 Create PV

You can create NAS data volumes in the Container Service console or by using an orchestration template.

  • Use an orchestration template

    Use the nas-pv.yaml file to create the PV.

    Run the following command to create a NAS type PersistentVolume.

    1. root@master # cat << EOF |kubectl apply -f -
    2. apiVersion: v1
    3. kind: PersistentVolume
    4. metadata:
    5. name: nas
    6. spec:
    7. capacity:
    8. storage: 8Gi
    9. accessModes:
    10. - ReadWriteMany
    11. persistentVolumeReclaimPolicy: Retain
    12. nfs:
    13. path: /
    14. server: 055f84ad83-ixxxx.cn-hangzhou.nas.aliyuncs.com
    15. EOF
  • Create NAS data volumes in Container Service console

    For more information, see Create NAS data volumes in Container Service console in Use PV/PVC.

Step 2 Create PVC

Create a PersistentVolumeClaim to request to bind this PersistentVolume.

  1. root@master # cat << EOF | kubectl apply -f -
  2. apiVersion: v1
  3. kind: PersistentVolumeClaim
  4. metadata:
  5. name: nasclaim
  6. spec:
  7. accessModes:
  8. - ReadWriteMany
  9. resources:
  10. requests:
  11. storage: 8Gi
  12. EOF

Step 3 Create pod

Create an application to declare to mount and use this data volume.

  1. root@master # cat << EOF |kubectl apply -f -
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5. name: mypod
  6. spec:
  7. containers:
  8. - name: myfrontend
  9. image: registry.aliyuncs.com/spacexnice/netdia:latest
  10. volumeMounts:
  11. - mountPath: "/var/www/html"
  12. name: mypd
  13. volumes:
  14. - name: mypd
  15. persistentVolumeClaim:
  16. claimName: nasclaim
  17. EOF

Then, the NAS remote file system is mounted to your pod application.

Dynamic storage volumes

To use dynamic NAS storage volumes, you must manually install the drive plug-in and configure the NAS mount point.

Install plug-in

  1. apiVersion: storage.k8s.io/v1
  2. kind: StorageClass
  3. metadata:
  4. name: alicloud-nas
  5. provisioner: alicloud/nas
  6. ---
  7. apiVersion: v1
  8. kind: ServiceAccount
  9. metadata:
  10. name: alicloud-nas-controller
  11. namespace: kube-system
  12. ---
  13. kind: ClusterRoleBinding
  14. apiVersion: rbac.authorization.k8s.io/v1beta1
  15. metadata:
  16. name: run-alicloud-nas-controller
  17. subjects:
  18. - kind: ServiceAccount
  19. name: alicloud-nas-controller
  20. namespace: kube-system
  21. roleRef:
  22. kind: ClusterRole
  23. name: alicloud-disk-controller-runner
  24. apiGroup: rbac.authorization.k8s.io
  25. ---
  26. kind: Deployment
  27. apiVersion: extensions/v1beta1
  28. metadata:
  29. name: alicloud-nas-controller
  30. namespace: kube-system
  31. spec:
  32. replicas: 1
  33. strategy:
  34. type: Recreate
  35. template:
  36. metadata:
  37. labels:
  38. app: alicloud-nas-controller
  39. spec:
  40. tolerations:
  41. - effect: NoSchedule
  42. operator: Exists
  43. key: node-role.kubernetes.io/master
  44. - effect: NoSchedule
  45. operator: Exists
  46. key: node.cloudprovider.kubernetes.io/uninitialized
  47. nodeSelector:
  48. node-role.kubernetes.io/master: ""
  49. serviceAccount: alicloud-nas-controller
  50. containers:
  51. - name: alicloud-nas-controller
  52. image: registry.cn-hangzhou.aliyuncs.com/acs/alicloud-nas-controller:v1.8.4
  53. volumeMounts:
  54. - mountPath: /persistentvolumes
  55. name: nfs-client-root
  56. env:
  57. - name: PROVISIONER_NAME
  58. value: alicloud/nas
  59. - name: NFS_SERVER
  60. value: 0cd8b4a576-mmi32.cn-hangzhou.nas.aliyuncs.com
  61. - name: NFS_PATH
  62. value: /
  63. volumes:
  64. - name: nfs-client-root
  65. nfs:
  66. server: 0cd8b4a576-mmi32.cn-hangzhou.nas.aliyuncs.com
  67. path: /

Use dynamic storage volumes

  1. apiVersion: apps/v1beta1
  2. kind: StatefulSet
  3. metadata:
  4. name: web
  5. spec:
  6. serviceName: "nginx"
  7. replicas: 2
  8. volumeClaimTemplates:
  9. - metadata:
  10. name: html
  11. spec:
  12. accessModes:
  13. - ReadWriteOnce
  14. storageClassName: alicloud-nas
  15. resources:
  16. requests:
  17. storage: 2Gi
  18. template:
  19. metadata:
  20. labels:
  21. app: nginx
  22. spec:
  23. containers:
  24. - name: nginx
  25. image: nginx:alpine
  26. volumeMounts:
  27. - mountPath: "/usr/share/nginx/html/"
  28. name: html
Thank you! We've received your feedback.