开发者社区> 问答> 正文

如何动态挂载NAS(PVC)?

如何动态挂载NAS(PVC)?

展开
收起
小天使爱美 2020-03-20 18:02:51 1363 0
1 条回答
写回答
取消 提交回答
  • 使用动态挂载NAS能力,需要在K8S集群内部署NAS Controller,将以下内容保存为nas_controller.yaml:

    kind: Deployment apiVersion: extensions/v1beta1 metadata: name: alicloud-nas-controller namespace: kube-system spec: strategy: type: Recreate template: metadata: labels: app: alicloud-nas-controller spec: affinity: nodeAffinity: preferredDuringSchedulingIgnoredDuringExecution: - weight: 1 preference: matchExpressions: - key: node-role.kubernetes.io/master operator: Exists priorityClassName: system-node-critical serviceAccount: admin hostNetwork: true containers: - name: nfs-provisioner image: registry.cn-hangzhou.aliyuncs.com/acs/alicloud-nas-controller:v1.14.3.8-58bf821-aliyun env: - name: PROVISIONER_NAME value: alicloud/nas securityContext: privileged: true volumeMounts: - mountPath: /var/log name: log volumes: - hostPath: path: /var/log name: log 使用kubectl部署NAS controller:

    kubectl create -f nas_controller.yaml

    deployment.extensions/alicloud-nas-controller created

    kubectl -n kube-system get deploy alicloud-nas-controller

    NAME READY UP-TO-DATE AVAILABLE AGE alicloud-nas-controller 1/1 1 1 20s 步骤1. 创建StorageClass 将以下内容保存为class.yaml:

    apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: alicloud-nas mountOptions: - nolock,tcp,noresvport - vers=3 parameters: server: "133aa489f0-rvn26.cn-beijing.nas.aliyuncs.com" driver: flexvolume provisioner: alicloud/nas reclaimPolicy: Delete 使用kubectl创建StorageClass:

    kubectl create -f class.yaml

    storageclass.storage.k8s.io/alicloud-nas created

    kubectl get sc alicloud-nas

    NAME PROVISIONER AGE alicloud-nas alicloud/nas 10s 步骤2. 创建PVC 将以下内容保存为pvc.yaml:

    apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-nas-dynamic spec: accessModes: - ReadWriteOnce storageClassName: alicloud-nas resources: requests: storage: 2Gi 通过kubectl创建PVC:

    kubectl create -f pvc.yaml

    persistentvolumeclaim/pvc-nas-dynamic created

    kubectl get pvc pvc-nas-dynamic

    NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE pvc-nas-dynamic Bound default-pvc-nas-dynamic-pvc-5462fda0-3bff-11ea-8c0c-4ac7cb9a7625 2Gi RWO alicloud-nas 2m52s 步骤3. 创建Pod 将以下内容保存为pod.yaml:

    apiVersion: v1 kind: Pod metadata: name: test-pvc-nas-dynamic spec: nodeName: virtual-kubelet containers: - image: nginx:latest name: test-container volumeMounts: - mountPath: /cache-test name: cache-volume volumes: - name: cache-volume persistentVolumeClaim: claimName: pvc-nas-dynamic 使用kubectl创建ECI实例:

    kubectl create -f pod.yaml

    pod/test-pvc-nas-dynamic created

    kubectl get pod test-pvc-nas-dynamic

    NAME READY STATUS RESTARTS AGE test-pvc-nas-dynamic 1/1 Running 0 64s

    kubectl exec -it test-pvc-nas-dynamic bash

    root@test-pvc-nas-dynamic:/# ls /cache-test/

    2020-03-20 18:03:12
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云上高性能NAS的技术揭秘和行业应用 立即下载
高性能NAS助力企业业务上云 立即下载
云上NAS:云上高性能NAS技术揭秘和行业应用 立即下载