Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration file and runtime management of NGINX #77

Merged
merged 6 commits into from
Mar 31, 2022

Conversation

pleshakov
Copy link
Contributor

Problem:
(1) Add/update/delete NGINX configuration files to/from the file system.
(2) Reload NGINX to apply changes in the configuration files.

Solution:
For (1): Add a new component - file.Manager - that allows writing and removing configuration files for a server.
The Manager writes server configuration files to /etc/nginx/conf.d folder. This folder is available to both gateway and NGINX containers as part of the shared volume /etc/nginx

For (2): Add a new component - runtime.Manager - that allows reload NGINX. The Manager reloads NGINX by sending a HUP signal to the NGINX master process.
Because the gateway process is running under user 1001 (rather than root), during the image build we add the CAP_KILL capability to the gateway binary.

Notes to the reviewers:

(a) both file.Manager and runtime.Manager use OS dependencies. Some unit tests were added, but the coverage is not full. If you think it makes sense to extend the coverage, please share some advice.

(b) With configuration file and runtime management implemented, we now are able to pass traffic through the NGINX!

cd examples/cafe-example
kubectl apply -f cafe.yaml

Wait until all pods are running. endpoints changes are not handled right now by the Gateway

kubectl get pods
NAME                      READY   STATUS    RESTARTS   AGE
coffee-6f4b79b975-llpcx   1/1     Running   0          7s
tea-6fb46d899f-cb4cs      1/1     Running   0          7s
kubectl apply -f cafe-routes.yaml
kubectl -n nginx-gateway port-forward <nginx-gateway-pod-name> 8080:80
curl localhost:8080/coffee -H "host: cafe.example.com"
Server address: 10.244.0.6:8080
Server name: coffee-6f4b79b975-llpcx
Date: 25/Mar/2022:21:26:19 +0000
URI: /coffee
Request ID: 0ffc7aeb436065df432170ce0cf4a932
curl localhost:8080/tea -H "host: cafe.example.com"
Server address: 10.244.0.7:8080
Server name: tea-6fb46d899f-cb4cs
Date: 25/Mar/2022:21:26:25 +0000
URI: /tea
Request ID: 2c4227432a5ee9f699e96f704183db8

Copy link
Contributor

@kate-osborn kate-osborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just a couple small comments/suggestions.

internal/events/loop_test.go Show resolved Hide resolved
internal/nginx/file/manager.go Outdated Show resolved Hide resolved
internal/nginx/file/manager_test.go Show resolved Hide resolved
internal/nginx/runtime/manager.go Outdated Show resolved Hide resolved
internal/nginx/runtime/manager.go Outdated Show resolved Hide resolved
Problem:
(1) Add/update/delete NGINX configuration files to/from the file system.
(2) Reload NGINX to apply changes in the configuration files.

Solution:
For (1): Add a new component - file.Manager - that allows writing and
removing configuration files for a server.
The Manager writes server configuration files to /etc/nginx/conf.d folder.
This folder is available to both gateway and NGINX containers as part of
the shared volume /etc/nginx

For (2): Add a new component - runtime.Manager - that allows reload NGINX.
The Manager reloads NGINX by sending a HUP signal to the NGINX master
process.
Because the gateway process is running under user 1001 (rather than root),
during the image build we add the CAP_KILL capability to the gateway binary.
Copy link
Contributor

@kate-osborn kate-osborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@pleshakov pleshakov merged commit a8b3199 into main Mar 31, 2022
@pleshakov pleshakov deleted the nginx-file-and-runtime-management branch March 31, 2022 18:42
@pammecrandall pammecrandall added the enhancement New feature or request label Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants