我正在尝试创建一个Nginx服务器,使用Kubernetes和正式的对接映像。不幸的是,当我试图挂载自定义配置文件时,什么都没有发生。我的容器工作正常,但它的默认配置文件。此外,/etc上的另一个挂载(让我们加密文件夹)也不能工作。尽管如此,certbot坐骑工作得很好.(如果我检查容器/etc/nginx/nginx.conf,它不是我要挂载的文件,而且/etc/letsencrypt不存在),我将我的部署文件链接到下面。如果有人有一个想法,并想帮助,这将是令人愉快的!
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.19.6
ports:
- containerPort: 80
- containerPort: 443
volumeMounts:
- name: nginx-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
readOnly: true
volumeMounts:
- name: letsencrypt
mountPath: /etc/letsencrypt
readOnly: true
volumeMounts:
- name: certbot
mountPath: /var/www/certbot
volumes:
- name: nginx-config
nfs:
server: 192.168.2.9
path: /volume1/nginx/nginx.conf
- name: letsencrypt
nfs:
server: 192.168.2.9
path: /volume1/nginx/letsencrypt
- name: certbot
nfs:
server: 192.168.2.9
path: /volume1/nginx/certbot编辑:为了解决这个问题,我必须将所有的卷挂载放在一个volumeMount节中,并删除卷部分中对文件的引用,如下所示:
volumeMounts:
- name: nginx-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
readOnly: true
- name: letsencrypt
mountPath: /etc/letsencrypt
readOnly: true
- name: certbot
mountPath: /var/www/certbot
volumes:
- name: nginx-config
nfs:
server: 192.168.2.9
path: /volume1/nginx/
- name: letsencrypt
nfs:
server: 192.168.2.9
path: /volume1/nginx/letsencrypt
- name: certbot
nfs:
server: 192.168.2.9
path: /volume1/nginx/certbot发布于 2021-02-08 10:45:40
这是不起作用的,因为您引用的Volumes不正确。不需要在Volumes挂载阶段引用文件名:
volumes:
- name: nginx-config
nfs:
server: 192.168.2.9
path: /volume1/nginx/nginx.conf 一旦我应用了您的配置,我的吊舱就处于CreateContainerConfigError状态,failed to prepare subPath for volumeMount "nginx-config" of container "nginx"错误。
在本例中,正确的yaml应该如下所示:
volumes:
- name: nginx-config
nfs:
server: 192.168.2.9
path: /volume1/nginx/ 我添加了一行#This is my custom config,只是为了知道我的自定义文件加载了,结果如下:
➜ keti nginx-deployment-66c5547c7c-nsfzv -- cat /etc/nginx/nginx.conf#This is my custom config
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
.....发布于 2021-02-17 08:49:33
我以社区wiki的形式编写这个答案,以提高OP解决方案的可见性,该解决方案被作为一个编辑来提问,而不是答案。
该问题的解决方案是将OP解决方案与我的回答相结合,将所有安装在singe volumeMount中的卷与我的回答结合起来,以删除卷部分中对文件的引用:
volumeMounts:
- name: nginx-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
readOnly: true
- name: letsencrypt
mountPath: /etc/letsencrypt
readOnly: true
- name: certbot
mountPath: /var/www/certbot
volumes:
- name: nginx-config
nfs:
server: 192.168.2.9
path: /volume1/nginx/
- name: letsencrypt
nfs:
server: 192.168.2.9
path: /volume1/nginx/letsencrypt
- name: certbot
nfs:
server: 192.168.2.9
path: /volume1/nginx/certbothttps://stackoverflow.com/questions/66094117
复制相似问题