volumeMount subPath不起作用

时间:2016-08-01 11:10:23

标签: kubernetes

我正在尝试使用this拉取请求中实现的新subPath功能(最近在v1.3中发布)。

但是,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

2 个答案:

答案 0 :(得分:3)

我不是百分之百确定这一点,因为我使用configMap卷而非NFS,但我必须使mountPathsubPath匹配如下所示,在它为我工作之前。

仅供参考,我使用的是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

答案 1 :(得分:0)

当我尝试使用kubectl 1.2版更新Kubernetes 1.4群集时出现此问题。尝试更新您的kubectl,然后在相应的文件上运行kubectl apply