-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build and use custom nginx container (#934)
Replace the publicly available nginx image with a custom nginx image. Problem: Using the publicly available nginx image requires users to create ConfigMaps for the nginx.conf file and the njs module and mount them to the NKG Pod as volumes. This pattern is not extensible and adds extra steps for developers and users. Additionally, an init container is required in order to set up the nginx config environment. Solution: Build and use a custom nginx container. The nginx.conf and njs module are now baked into the nginx image. This eliminates the need for ConfigMaps. The config directories /etc/nginx/conf.d and /etc/nginx/secrets are created as volumes and mounted to the Pod with a group ID 1001. This allows the control plane to write to the directories and nginx to read from them. Both the nginx and nginx-gateway processes run under group ID 1001 but have different user IDs (101 and 102). The nginx container runs as user 101 instead of root and runs with the minimum set of capabilities.
- Loading branch information
1 parent
6de0ba2
commit f820591
Showing
25 changed files
with
348 additions
and
784 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# syntax=docker/dockerfile:1.4 | ||
FROM nginx:1.25.1-alpine | ||
|
||
ARG NJS_DIR | ||
ARG NGINX_CONF_DIR | ||
|
||
RUN apk update && apk add --no-cache libcap \ | ||
&& mkdir -p /var/lib/nginx /usr/lib/nginx/modules \ | ||
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx \ | ||
&& setcap -v 'cap_net_bind_service=+ep' /usr/sbin/nginx \ | ||
&& apk del libcap | ||
|
||
COPY ${NJS_DIR}/httpmatches.js /usr/lib/nginx/modules/njs/httpmatches.js | ||
COPY ${NGINX_CONF_DIR}/nginx.conf /etc/nginx/nginx.conf | ||
|
||
RUN chown -R 101:1001 /etc/nginx /var/cache/nginx /var/lib/nginx | ||
|
||
USER 101:1001 |
Oops, something went wrong.