Kubernetes mountPath在文件夹名中带有点(。)

时间:2019-11-21 05:15:16

标签: kubernetes

在将mountPath与'。'一起使用时,我的部署出现问题。文件夹

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

这导致吊舱中有"Back-off restarting failed container"

但是,这完全可以正常工作:

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

类似地,下面的方法也可以正常工作,但是如果我将php-fpm替换为php-fpm.d,它将破坏:

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

如何使用带有'。'的文件夹价值是我的mountPath的一部分?

1 个答案:

答案 0 :(得分:0)

我尝试在以下设置中重现它(为了清楚起见,我已部分省略了数据):

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

使用我的WorkerNode中的/etc/nginx/conf.d/作为/tmp/somePath/conf.d目录创建一个简单的Nginx容器。

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

以下是位于我的工作节点上的原始目录的内容:

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

吊舱旋转良好:

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>

让我们在该Pod上运行bash shell来检查我们那里的内容:

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

从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

这就是为什么我同意@ coderanger来检查您的容器日志的原因。

P.S。我认为您已经解决了这个问题。有什么问题