Skip to content

Commit 57b87e4

Browse files
authored
Move nginx.conf to ConfigMap (#678)
To clean up the init container, the main nginx.conf is being moved to a ConfigMap and then mounted into the Pod. Also bumped container versions.
1 parent a68a33b commit 57b87e4

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

deploy/manifests/nginx-gateway.yaml

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@ roleRef:
6969
name: nginx-gateway
7070
apiGroup: rbac.authorization.k8s.io
7171
---
72+
apiVersion: v1
73+
kind: ConfigMap
74+
metadata:
75+
name: nginx-conf
76+
namespace: nginx-gateway
77+
data:
78+
nginx.conf: |
79+
load_module /usr/lib/nginx/modules/ngx_http_js_module.so;
80+
81+
events {}
82+
83+
pid /etc/nginx/nginx.pid;
84+
error_log stderr debug;
85+
86+
http {
87+
include /etc/nginx/conf.d/*.conf;
88+
js_import /usr/lib/nginx/modules/njs/httpmatches.js;
89+
server_names_hash_bucket_size 256;
90+
server_names_hash_max_size 1024;
91+
}
92+
---
7293
apiVersion: apps/v1
7394
kind: Deployment
7495
metadata:
@@ -87,26 +108,29 @@ spec:
87108
shareProcessNamespace: true
88109
serviceAccountName: nginx-gateway
89110
volumes:
90-
- name: nginx-config
111+
- name: nginx
91112
emptyDir: { }
113+
- name: nginx-conf
114+
configMap:
115+
name: nginx-conf
92116
- name: var-lib-nginx
93117
emptyDir: { }
94118
- name: njs-modules
95119
configMap:
96120
name: njs-modules
97121
initContainers:
98-
- image: busybox:1.34 # FIXME(pleshakov): use gateway container to init the Config with proper main config
99-
name: nginx-config-initializer
100-
command: [ 'sh', '-c', 'echo "load_module /usr/lib/nginx/modules/ngx_http_js_module.so; events {} pid /etc/nginx/nginx.pid; error_log stderr debug; http { include /etc/nginx/conf.d/*.conf; js_import /usr/lib/nginx/modules/njs/httpmatches.js; server_names_hash_bucket_size 256; server_names_hash_max_size 1024; }" > /etc/nginx/nginx.conf && (rm -r /etc/nginx/conf.d /etc/nginx/secrets; mkdir /etc/nginx/conf.d /etc/nginx/secrets && chown 1001:0 /etc/nginx/conf.d /etc/nginx/secrets)' ]
122+
- image: busybox:1.36
123+
name: set-permissions
124+
command: [ 'sh', '-c', 'rm -r /etc/nginx/conf.d /etc/nginx/secrets; mkdir /etc/nginx/conf.d /etc/nginx/secrets && chown 1001:0 /etc/nginx/conf.d /etc/nginx/secrets' ]
101125
volumeMounts:
102-
- name: nginx-config
126+
- name: nginx
103127
mountPath: /etc/nginx
104128
containers:
105129
- image: ghcr.io/nginxinc/nginx-kubernetes-gateway:edge
106130
imagePullPolicy: Always
107131
name: nginx-gateway
108132
volumeMounts:
109-
- name: nginx-config
133+
- name: nginx
110134
mountPath: /etc/nginx
111135
securityContext:
112136
runAsUser: 1001
@@ -133,8 +157,11 @@ spec:
133157
- name: https
134158
containerPort: 443
135159
volumeMounts:
136-
- name: nginx-config
160+
- name: nginx
137161
mountPath: /etc/nginx
162+
- name: nginx-conf
163+
mountPath: /etc/nginx/nginx.conf
164+
subPath: nginx.conf
138165
- name: var-lib-nginx
139166
mountPath: /var/lib/nginx
140167
- name: njs-modules

0 commit comments

Comments
 (0)