Kubernetes mountPath with dot (.) in foldername

11/21/2019

I am having problems with my deployment when using a mountPath with a '.' folder

E.g. 
containers:
- image: nginx
  name: nginx
  volumeMounts:
  - mountPath: /etc/nginx/conf.d/
    name: nginx-path
volumes
- hostPath:
    path: /somePath/conf.d
  name: nginx-path

This results in the pod having "Back-off restarting failed container"

However, this works completely fine:

- image: nginx
  name: nginx
  volumeMounts:
  - mountPath: /etc/nginx/conf/
    name: nginx-path
volumes
- hostPath:
    path: /somePath/conf.d
  name: nginx-path

Similarly, the below will work fine, but if I replace php-fpm with php-fpm.d it breaks:

volumeMounts:
- mountPath: "/usr/local/etc/php-fpm/www.conf" 
  subPath: www.conf
  name: config
volumes:
- configMap:
 name: config
name: config  

How can I use a folder with a '.' value as part of my mountPath?

-- xbfh0516
kubernetes

1 Answer

11/28/2019

I have attempted to reproduce it on a following setup (i have omitted data partially in sake of clarity):

kubectl version
Client Version: ... GitVersion:"v1.16.3", 
Server Version: ... GitVersion:"v1.14.8-gke.12" 

Creating a simple Nginx container with /etc/nginx/conf.d/ as a /tmp/somePath/conf.d dir from my WorkerNode.

cat pod_with_volume.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: test-nginx-with-volume
spec:
  containers:
  - image: nginx
    name: nginx
    volumeMounts:
    - mountPath: /etc/nginx/conf.d/
      name: nginx-path
  volumes:
  - hostPath:
      path: /tmp/somePath/conf.d
    name: nginx-path

Below is the content of original dir located on my Worker Node:

username@gke-your-first-cluster-1-pool-1 /tmp/somePath/conf.d $ ls 
nginx-override.conf  random_file.txt
username@gke-your-first-cluster-1-pool-1 /tmp/somePath/conf.d $ cat random_file.txt 
The Marcus King Band - Virginia

The pod spins up fine:

kubectl get pods
NAME                     READY   STATUS    RESTARTS   AGE
test-nginx-with-volume   1/1     Running   0          8s

kubectl describe pod/test-nginx-with-volume
Name:         test-nginx-with-volume
Namespace:    default
Priority:     0
Node:         gke-your-first-cluster-1-pool-1/IP
...
Containers:
  nginx:
    Container ID:   docker://9d40****b747
    Image:          nginx
    Image ID:       docker-pullable://nginx@sha256:189c****ba0a
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Thu, 28 Nov 2019 12:15:15 +0100
    Ready:          True
    Restart Count:  0
    Requests:
      cpu:        100m
    Environment:  <none>
    Mounts:
      /etc/nginx/conf.d/ from nginx-path (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-sdgxn (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  nginx-path:
    Type:          HostPath (bare host directory volume)
    Path:          /tmp/somePath/conf.d
    HostPathType:  
  default-token-sdgxn:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-sdgxn
    Optional:    false
QoS Class:       Burstable
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:          <none>

Let's run the bash shell on that Pod to check what we have there:

kubectl exec -it test-nginx-with-volume -- /bin/bash

From Pod:

root@test-nginx-with-volume:/# ls -lah /etc/nginx
total 44K
drwxr-xr-x 3 root root 4.0K Nov 23 01:12 .
drwxr-xr-x 1 root root 4.0K Nov 28 11:15 ..
drwxr-xr-x 2 5000 5000   80 Nov 28 12:01 conf.d
-rw-r--r-- 1 root root 1007 Nov 19 12:50 fastcgi_params
...
-rw-r--r-- 1 root root  643 Nov 19 12:50 nginx.conf

root@test-nginx-with-volume:/# ls -lah /etc/nginx/conf.d/
total 8.0K
drwxr-xr-x 2 5000 5000   80 Nov 28 12:34 .
drwxr-xr-x 3 root root 4.0K Nov 23 01:12 ..
-rw-r--r-- 1 5000 5000    0 Nov 28 10:56 nginx-override.conf
-rw-r--r-- 1 5000 5000   32 Nov 28 12:01 random_file.txt

root@test-nginx-with-volume:/# cat /etc/nginx/conf.d/random_file.txt 
The Marcus King Band - Virginia

That is why I agree to @coderanger that it is needed to check your container's logs.

P.S. I assume you have already solved the issue. What was the issue?

-- Nick
Source: StackOverflow