使用动态挂载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:
deployment.extensions/alicloud-nas-controller created
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:
storageclass.storage.k8s.io/alicloud-nas created
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:
persistentvolumeclaim/pvc-nas-dynamic created
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实例:
pod/test-pvc-nas-dynamic created
NAME READY STATUS RESTARTS AGE test-pvc-nas-dynamic 1/1 Running 0 64s
root@test-pvc-nas-dynamic:/# ls /cache-test/
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。