Prerequisites:

  • The virtual-kubelet node is deployed in the target Kubernetes cluster. Note that a serverless Kubernetes cluster is embedded with the virtual-kubelet node.
  • A Network Attached Storage (NAS) mount target is added in the Virtual Private Cloud (VPC) where the virtual-kubelet node is deployed.

Save the following sample code in a YAML file named flexvolume_nas.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: test-flexvolume-nfs
spec:
  nodeName: virtual-kubelet
  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"

Use the kubectl client to create an Elastic Container Instance (ECI) based on the preceding configuration file.

# 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