弹性容器实例 静态挂载NAS(PVC)

By | 2021年4月22日

前提条件:

  • K8S集群中正确部署了virtual-kubelet(serverless Kubernetes 默认集成)
  • 已经在virtual-kubelet配置的同VSwitch创建NAS挂载点

步骤1. 创建PV

将以下内容保存为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"

使用kubectl创建PV:

# 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

步骤2. 创建PVC

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

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

使用kubectl创建PVC:

# 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

步骤3. 创建Pod

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

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

使用kubectl创建ECI实例:

# 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


请关注公众号获取更多资料

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Iconic One Theme | Powered by Wordpress