弹性容器实例 NFS

By | 2021年4月22日

使用前提:

  • K8S集群中正确部署了virtual-kubelet(serverless Kubernetes 默认集成)
  • 可用的NFS挂载点(默认可挂载目录为 /,若要指定挂载目录必须提前在nfs创建目录。)

ECI原生支持NFS,可以像使用原生K8S一样使用NFS,将以下文件保存为nfs.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: test-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
    nfs:
      server: 133aa489f0-rvn26.cn-beijing.nas.aliyuncs.com
      path: /  
      readOnly: false

使用kubectl创建:

# kubectl create -f nfs.yaml
pod/test-nfs created
# kubectl get pod test-nfs
NAME       READY   STATUS    RESTARTS   AGE
test-nfs   1/1     Running   0          50s
# kubectl exec -it test-nfs bash
root@default-test-nfs:/# ls
bin  boot  cache-test  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@default-test-nfs:/# mkdir cache-test/subpath
root@default-test-nfs:/# echo hello > cache-test/subpath/test
root@default-test-nfs:/# cat cache-test/subpath/test
hello

另外,NFS还支持subpath,将以下yaml文件保存为nfs_subpath.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: test-nfs-subpath
spec:
  # ACK场景下可以通过nodeName指定调度到ECI
  # nodeName: virtual-node-eci-0
  containers:
  - image: nginx:latest
    name: test-container
    volumeMounts:
    - mountPath: /cache-test
      name: cache-volume
      subPath: subpath
  volumes:
  - name: cache-volume
    nfs:
      server: 1a93e496ef-fuu9.cn-beijing.nas.aliyuncs.com
      path: /
      readOnly: false

kubectl创建,效果如下:

# kubectl create -f nfs_subpath.yaml
pod/test-nfs-subpath created
# kubectl get pod test-nfs-subpath
NAME               READY   STATUS    RESTARTS   AGE
test-nfs-subpath   1/1     Running   0          2m26s
# kubectl exec -it test-nfs-subpath bash
root@test-nfs-subpath:/# ls
bin  boot  cache-test  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@test-nfs-subpath:/# ls cache-test/
test
root@test-nfs-subpath:/# cat cache-test/test
hello

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

发表回复

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

Iconic One Theme | Powered by Wordpress