kubernetes volumeMount subPath不工作

4smxwvx5  于 2023-11-17  发布在  Kubernetes
关注(0)|答案(3)|浏览(146)

我正在尝试使用this pull request(最近在v1.3中发布)中实现的新subPath特性。
但是,mount的输出显示它忽略了subPath,为两个卷挂载挂载相同的NFS目录:

nfs-server:/mnt/nfs/exports/apps/my-app on /home/share/foo type nfs4 (rw,relatime,vers=4.0,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=10.128.0.4,local_lock=none,addr=nfs-server)
nfs-server:/mnt/nfs/exports/apps/my-app on /home/share/bar/baz type nfs4 (rw,relatime,vers=4.0,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=10.128.0.4,local_lock=none,addr=nfs-server)

字符串
我的部署YAML的相关部分:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: app
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: app
    spec:
      containers:
      - name: app
        image: my-org/my-app:latest
        volumeMounts:
        - mountPath: /home/share/foo
          name: nfs
          subPath: foo-resources
        - mountPath: /home/share/bar/baz
          name: nfs
          subPath: baz-resources
      volumes:
      - name: nfs
        nfs:
          path: /mnt/nfs/exports/apps/my-app
          server: nfs-server

tct7dpnv

tct7dpnv1#

我不能100%确定这一点,因为我使用的是configMap卷而不是NFS,但我必须使mountPath匹配subPath,如下所示,然后才能为我工作。
FYI,我正在使用Kubernetes v1.4.5。
如果我没阅读错的话,你想:

  • 挂载NFS文件或目录/mnt/nfs/exports/apps/my-app/foo-resources,使其在容器中的路径为/home/share/foo/foo-resources
  • 挂载NFS文件或目录/mnt/nfs/exports/apps/my-app/baz-resources,使其在容器中的路径为/home/share/bar/baz/baz-resources

试试这个:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: app
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: app
    spec:
      containers:
      - name: app
        image: my-org/my-app:latest
        volumeMounts:
        - mountPath: /home/share/foo/foo-resources
          name: nfs
          subPath: foo-resources
        - mountPath: /home/share/bar/baz/baz-resources
          name: nfs
          subPath: baz-resources
      volumes:
      - name: nfs
        nfs:
          path: /mnt/nfs/exports/apps/my-app
          server: nfs-server

字符串
差异:

16c16
<         - mountPath: /home/share/foo/foo-resources
---
>         - mountPath: /home/share/foo
19c19
<         - mountPath: /home/share/bar/baz/baz-resources
---
>         - mountPath: /home/share/bar/baz

disho6za

disho6za2#

我在尝试使用kubectl版本1.2更新Kubernetes 1.4集群时遇到了这个问题。请尝试更新kubectl,然后在相应的文件上运行kubectl apply

kgqe7b3p

kgqe7b3p3#

我试着用subPath打开/etc/openresty/nginx.conf,但是没有用。
原来/etc/openrestry是到/usr/local/openresty/nginx的链接,我也挂载了那个卷。
所以基本上我是用subPath挂载到某个位置,然后它被一个不同的volumeMount覆盖。

相关问题