前提条件:

  • K8S集群中正确部署了virtual-kubelet(serverless Kubernetes 默认集成)
  • 与virtual-kubelet配置相同可用区的NAS挂载点
  • nas挂载的目录需要提前创建(默认为 / )

将以下内容保存为flexvolume_nas.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: test-flexvolume-nfs
spec:
  # ACK场景下可以通过nodeName指定调度到ECI
  # nodeName: virtual-node-eci-0
  containers:
  - image: nginx:latest
    name: test-container
    volumeMounts:
    - mountPath: /cache-test
      name: cache-volume
  volumes:
  - name: cache-volume
    flexVolume:
      driver: alicloud/nas
      fsType: nfs
      options:
        server: "133aa489f0-rvn26.cn-beijing.nas.aliyuncs.com"
        path: "/"
        vers: "3"
        options: "nolock,tcp,noresvport"

使用kubectl创建ECI实例:

# kubectl create -f flexvolume_nas.yaml
pod/test-flexvolume-nas created
# kubectl get pod test-flexvolume-nas
NAME                  READY   STATUS    RESTARTS   AGE
test-flexvolume-nas   1/1     Running   0          6m9s
# kubectl exec -it test-flexvolume-nas bash
root@test-flexvolume-nas:/# ls
bin  boot  cache-test  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@test-flexvolume-nas:/# ls -l /cache-test/
total 1
drwxr-xr-x 2 root root 4096 Jan 19 13:55 subpath