I’m trying to create a Nginx server using Kubernetes and the official docker image. Unfortunately, when I’m trying to mount a custom config file, nothing happen. My container works just fine but with it’s default configuration file. Moreover the another mount on /etc (the lets encrypt folder) doesn’t work too. Nevertheless the certbot mount works just fine…
(If I check inside the container /etc/nginx/nginx.conf it’s not the file I’m trying to mount, and /etc/letsencrypt doesn’t exist)
I link my deployment file just below..
If someone has an idea and want to help it would be delightful !
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
Edit :
To solve this problem I had to put all my volume mount inside a single volumeMount section and to remove the reference to file in the volume section, like this :
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
2
Answers
This is not working because you are incorrectly referencing your
Volumes
. There is no need to reference the file name at theVolumes
mount stage:Once I applied your config my pod was in
CreateContainerConfigError
status withfailed to prepare subPath for volumeMount "nginx-config" of container "nginx"
error.The correct yaml should in this case look like this:
I have added a line
#This is my custom config
just to know that my custom file was load and there are the results of that:I’m writing this answer as community wiki for better visibility of OP solution which was placed as an edit to question instead of answer.
The solution for the problem was combination of OP solution to putt all the volumes mount inside singe
volumeMount
with my answer to remove the reference to a file in the volume section: