未创建带有符号链接的Kubernetes卷主机路径

时间:2019-03-28 12:43:45

标签: docker kubernetes

我有一个用卷定义的服务,其中父目录是到另一台设备的符号链接。 yaml中的音量定义如下:

  volumes:
  -name: service-logs
   hostPath:
     path: /tmp/logs/service-logs
     type: DirectoryOrCreate

和/ tmp / logs是/ data / logs的符号链接。当我尝试启动Pod时,它无法创建/ tmp / logs / service-logs。

是否有办法使它正常工作?还是Kubernetes不能解析符号链接?

1 个答案:

答案 0 :(得分:0)

我用Kubernetes 1.14重新创建了您的问题。 我使用了以下yaml:

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: busybox
    name: test-container
    command: ["sleep"]
    args: ["3600"]
    volumeMounts:
    - mountPath: /test-pd
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      path: /data/folder
      type: DirectoryOrCreate
  nodeSelector:
    kubernetes.io/hostname: cluster-1

在节点cluster-1上,我创建了目录并对其进行符号链接:

lrwxrwxrwx 1 root        root           5 Mar 28 16:56 data -> data2
d--------- 3 testuser testuser       4096 Mar 28 17:04 data2

即使没有写权限,也无法在data2目录folder中写入。 Pod内部的进程能够对其进行写入。这是由于负责将卷装载到容器的kubelet进程是由root运行的。

相关问题