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.

Step 1: Create a PV

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

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-nas-static
spec:
  capacity:
    storage: 5Gi
  storageClassName: nas
  persistentVolumeReclaimPolicy: Recycle
  accessModes:
    - ReadWriteMany
  flexVolume:
    driver: "alicloud/nas"
    options:
      server: "1a93e496ef-fuu9.cn-beijing.nas.aliyuncs.com"
      path: "/"
      vers: "3"

Use the kubectl client to create a persistent volume (PV) based on the preceding configuration file.

# kubectl create -f nas_pv_static.yaml
persistentvolume/pv-nas-static created 
# kubectl get pv pv-nas-static
NAME            CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM   STORAGECLASS   REASON   AGE
pv-nas-static   5Gi        RWX            Recycle          Available           nas                     97s

Step 2: Create a PVC

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

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-nas
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: nas
  resources:
    requests:
      storage: 5Gi

Use the kubectl client to create a persistent volume claim (PVC) based on the preceding configuration file.

# kubectl create -f nas_pvc_static.yaml
persistentvolumeclaim/pvc-nas created
# kubectl get pvc pvc-nas
NAME      STATUS   VOLUME          CAPACITY   ACCESS MODES   STORAGECLASS   AGE
pvc-nas   Bound    pv-nas-static   5Gi        RWX            nas            7s

Step 3: Create an ECI

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

apiVersion: v1
kind: Pod
metadata:
  name: test-pvc-nas
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

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

# kubectl create -f pod.yaml
pod/test-pvc-nas created
# kubectl get pod test-pvc-nas
NAME           READY   STATUS    RESTARTS   AGE
test-pvc-nas   1/1     Running   0          76s
# kubectl exec -it test-pvc-nas bash
root@test-pvc-nas:/# ls /cache-test/
subpath