Kubernetes volume hostpath with symlink not created

3/28/2019

I've got a service defined with a volume where the parent directory is a symlink to another device. The volume definition in the yaml is like the below:

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

and /tmp/logs is a symlink to /data/logs. When I try to start the pod, it fails to create /tmp/logs/service-logs.

Is there a way to get this working? Or does kubernetes not resolve the symlink?

-- css
docker
kubernetes

1 Answer

3/28/2019

I recreated your issue with Kubernetes 1.14. I used following 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

On node cluster-1 I created directory and symlink to it:

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

Even with no permissions to write in data2 directory folder was created. Processes inside of the pod were able to write to it. This is due to the fact that kubelet process, responsible for mounting volumes to a container, is run by root.

-- MWZ
Source: StackOverflow