foldername中带点(.)的Kubernetes mountPath

foldername中带点(.)的Kubernetes mountPath,kubernetes,Kubernetes,使用带有“.”文件夹的装入路径时,我的部署出现问题 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 这导致pod具有“退回重新启动失败的容器” 但是,这完全可以: - image

使用带有“.”文件夹的装入路径时,我的部署出现问题

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
这导致pod具有“退回重新启动失败的容器”

但是,这完全可以:

- image: nginx
  name: nginx
  volumeMounts:
  - mountPath: /etc/nginx/conf/
    name: nginx-path
volumes
- hostPath:
    path: /somePath/conf.d
  name: nginx-path
类似地,下面的代码也可以正常工作,但是如果我用
php fpm.d
替换
php fpm
,它就会崩溃:

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

如何使用带有“.”值的文件夹作为挂载路径的一部分?

我尝试在以下设置中复制它(为了清晰起见,我省略了部分数据):

从我的WorkerNode创建一个简单的Nginx容器,其中包含
/etc/Nginx/conf.d/
作为
/tmp/somePath/conf.d
目录

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:

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
这就是为什么我同意@需要检查容器日志的原因


另外,我想你已经解决了这个问题。问题是什么

您确定问题不是您的配置未使用
/etc/nginx/conf
,而是
conf.d/
并且您的配置无效吗?您在容器输出中看到了什么?您创建了一个可以访问主机节点文件系统上目录的Pod,我说的对吗?我试图做同样的事情,结果得到了“CrashLoopBackOff”,然而在我的例子中,问题从
kubectl descripe
的输出中显而易见。即:“创建装载源路径“/somePath/conf.d”时出错:mkdir/somePath:只读文件系统”。我可以在集群上请求相同命令的输出吗?
kubectl exec -it test-nginx-with-volume -- /bin/bash
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