Skip to content

Commit 28df1e4

Browse files
authored
Merge pull request #10 from nginxinc/akker
update docs
2 parents c9be800 + a66e947 commit 28df1e4

File tree

8 files changed

+142
-30
lines changed

8 files changed

+142
-30
lines changed

README.md

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,73 @@
22

33
# nginx-k8s-edge-controller
44

5+
## Welcome to the Nginx Kubernetes Load Balancer project !
6+
7+
<br/>
8+
9+
This repo contains source code and documents for a new Kubernetes Controller, that provides TCP load balancing external to a k8s cluster. It is a replacement for a Cloud Providers "Service Type Loadbalancer", that is missing from On Premises Kubernetes Clusters.
10+
11+
<br/>
12+
13+
## Overview
14+
15+
- Create a new K8s Controller, that will monitor specified k8s Service Endpoints, and then send API calls to an external NginxPlus server to manage Nginx Upstream server blocks.
16+
- This is will synchronize the K8s Service Endpoint list, with the Nginx LB server's Upstream block server list.
17+
- The primary use case is for tracking the NodePort IP:Port definitions for the Nginx Ingress Controller's `nginx-ingress Service`.
18+
- With the NginxPlus Server located external to the K8s cluster, this new controller LB function would provide an alternative TCP "Load Balancer Service" for On Premises k8s clusters, which do not have access to a Cloud providers "Service Type LoadBalancer".
19+
- Make the solution a native Kubernetes Component, configured and managed with standard K8s tools.
20+
21+
<br/>
22+
23+
## Reference Diagram
24+
25+
<br/>
26+
27+
![NGINX LB Server](docs/media/nginxlb-nklv1.png)
28+
29+
<br/>
30+
31+
## Sample Screenshots of Runtime
32+
33+
### Configuration with 2 Nginx LB Servers defined (HA):
34+
35+
![NGINX LB ConfigMap](docs/media/nkl-pod-configmap.png)
36+
37+
<br/>
38+
39+
### Nginx LB Server Dashboard and Logging
40+
41+
![NGINX LB Create Nodeport](docs/media/nkl-create-nodeport.png)
42+
43+
Legend:
44+
- Red - kubectl commands
45+
- Blue - nodeport and upstreams for http traffic
46+
- Indigo - nodeport and upstreams for https traffic
47+
- Green - logs for api calls to LB Server #1
48+
- Orange - Nginx LB Server upstream dashboard details
49+
- Kubernetes nodes are 10.1.1.8 and 10.1.1.10
50+
51+
<br/>
52+
553
## Requirements
654

55+
Please see the /docs folder for detailed documentation.
756

857
## Installation
958

59+
Please see the /docs folder for detailed documentation.
1060

11-
## Usage
12-
61+
<br/>
1362

1463
## Development
1564

65+
No contributions are being accepted at this time.
1666
Read the [`CONTRIBUTING.md`](https://github.com/nginxinc/nginx-k8s-edge-controller/blob/main/CONTRIBUTING.md) file.
1767

68+
<br/>
69+
1870
## License
1971

2072
[Apache License, Version 2.0](https://github.com/nginxinc/nginx-k8s-edge-controller/blob/main/LICENSE)
2173

22-
&copy; [F5 Networks, Inc.](https://www.f5.com/) 2022
74+
&copy; [F5 Networks, Inc.](https://www.f5.com/) 2023

docs/NginxKubernetesLoadbalancer.md

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- This is will synchronize the K8s Service Endpoint list, with the Nginx LB server's Upstream block server list.
1616
- The primary use case is for tracking the NodePort IP:Port definitions for the Nginx Ingress Controller's `nginx-ingress Service`.
1717
- With the NginxPlus Server located external to the K8s cluster, this new controller LB function would provide an alternative TCP "Load Balancer Service" for On Premises k8s clusters, which do not have access to a Cloud providers "Service Type LoadBalancer".
18+
- Make the solution a native Kubernetes Component, configured and managed with standard K8s tools.
1819

1920
<br/>
2021

@@ -34,7 +35,7 @@ This is often called "NLB", a term used in AWS for Network Load Balancer, but fu
3435

3536
>**This Solution uses NGINX to provide an alternative to #3, the TCP loadbalancing from PublicIP to k8s NodePort.**
3637
37-
Note: This solution is not for Cloud-based K8s clusters, only On Premises K8s clusters.
38+
Note: This solution is not for Cloud-based K8s clusters, it is only for On Premises K8s clusters.
3839

3940
<br/>
4041

@@ -62,8 +63,12 @@ Alternatives:
6263

6364
However, most of these alternatives are proprietary, open source / unsupported, competitive, or have other customer concerns.
6465

66+
<br/>
67+
6568
>**`NGINX PLUS is a viable alternative for most customers.`**
6669
70+
<br/>
71+
6772
Why not Nginx OpenSource? Nginx Open Source does not have the API endpoint and service for managing Upstream Server block configurations.
6873

6974
<br/>
@@ -81,6 +86,7 @@ Why not Nginx OpenSource? Nginx Open Source does not have the API endpoint and
8186
- Plus API - the standard Nginx Plus API service that is running on the Nginx LB Server
8287
- Nginx Plus Go Client - software that communicates with the Nginx LB Server
8388
- Upstream - the IP:Port list of servers that Nginx will Load Balance traffic to at Layer 4 TCP using the stream configuration
89+
- Fan-out support - the ability to run 2 or more Nginx LB servers external to the cluster for High Availability
8490

8591
<br/>
8692

@@ -89,50 +95,54 @@ Why not Nginx OpenSource? Nginx Open Source does not have the API endpoint and
8995
<br/>
9096

9197
Preface - Define access parameters for NKL Controller to communicate with NginxPlus instance:
92-
- IP address:port or FQDN of the target Nginx LB Server
98+
- IP address:port of the target Nginx LB Server(s)
9399
- Optional auth: SSL certificate/key
94100
- Optional auth: IP allow list
95101
- Optional auth: HTTP Auth userid/password
96102
- Optional auth: JWT Token
97103

98104
1. Initialization:
105+
99106
- Define the name of the target Upstream Server Block
100107
- "nginx-lb-http" or "nginx-lb-https" should be the default server block names, returns error if these do not exist
101108
- Using the Nginx Plus Go Client library, make an API query to NginxPlus LB server for current Upstream list
102109
- API query to K8s apiserver for list of Ingress Controller Endpoints
103110
- Reconcile the two lists, making changes to Nginx Upstreams to match the Ingress Endpoints ( add / delete Upstreams as needed to converge the two lists )
104111

105-
2. Runtime:
106-
- Periodic check - API query for the list of Servers in the Upstream block, using the NginxPlus API ( query interval TBD )
107-
- IP:port definition
108-
- other possible metadata: status, connections, response_time, etc
109-
- Keep a copy of this list in memory, if state is required
112+
2. Configuration Requirements:
113+
114+
- List of Nginx LB server IP:Ports, comma separated
115+
- List of K8s worker nodes
116+
- List of Nginx LB server upstream block names, current defaults are "nginx-lb-http" and "nginx-lb-https" - `nginxlb.conf` for examples
117+
- Nodeport Definition file, port names MUST match the upstream block names in the correct format, prefixed with `nkl-`, as in `nkl-nginx-lb-http` and `nkl-nginx-lb-https`
118+
119+
3. Runtime:
110120

111-
3. Register the LB Controller with the K8s watcher Service, subscribe to Notifications for changes to the nginx-ingress Service Endpoints.
121+
- Register the LB Controller with the K8s watcher Service, subscribe to Notifications for changes to the nginx-ingress Service Endpoints.
112122
- Using the Nginx Plus Go Client libraries, modify Upstream server entries, based on K8s NodePort Service endpoint "Notification" changes
113123
- Add new Endpoint to Upstream Server list on k8s Notify
114-
- Remove deleted Endpoints to Upstream list, using the Nginx Plus "Drain" function, leaving existing TCP connections to close gracefully on K8s Notify delete.
115-
- Create and Set Drain_wait timer on Draining Upstream servers
116-
- Remove Draining Upstream servers after Drain_wait timer expires
117-
- Log changes to debug, nginx error.log, or custom access.log as appropriate
124+
- Remove deleted Endpoints to Upstream list on k8s Notify
125+
- Log changes to debug, nginx error.log, custom access.log and controller log as appropriate
118126

119-
4. Query the K8s api server, for the list of Endpoints for the "nginx-ingress" Service object. This is the list of NodePorts where the Nginx Ingress Controller is listening.
120-
- Keep a copy of this list in memory, if state is desired
127+
4. Main program
121128

122-
5. Main program
123129
- Compare the list of Upstream servers from the Nginx API call, with the list nginx-ingress Service Endpoints from the K8s API call
124130
- Calculate the difference in the list, and create new Nginx API calls to update the Upstream list, adding or removing the changes needed to mirror the nginx-ingress Service Endpoints list
131+
- Periodic check - API query for the list of Servers in the Upstream block, using the NginxPlus API ( query interval TBD )
132+
- IP:port definition
133+
- other possible metadata collection: status, connections, response_time, etc
134+
- Register the LB Controller for liveness probes, so K8s has and endpoint to query for up/down status.
125135
- Log these changes
126136

127-
6. Optional: Make Nginx API calls to update the entire Upstream list, regardless of what the existing list contains. *Nginx will allow for the addition of duplicate server to the upstream block using the API, so at some point a process to "clean up and verify" the upstream list should be considered. It is possible that the Nginx-Plus-Go_Client already does this function.*
137+
6. Optional: Add additional features/functions here, beyond MVP.
128138

129139
<br/>
130140

131-
## PM/PD Suggestion - to build this new Controller, use the existing Nginx Ingress Controller framework/code, to create this new k8s LB Controller, leveraging the Enterprise class, supportable code Nginx already has on hand. Or perhaps, add this Loadbalancer solution as a new Feature to the exising Ingress Controller ( NIC, after all, is already watching the nginx-ingress namespace and services ).
141+
## PM/PD Suggestion - to build this new Controller, use the existing Nginx Ingress Controller framework/code, to create this new k8s LB Controller, leveraging the Enterprise class, supportable code Nginx already has on hand. Or perhaps, add this Loadbalancer solution as a new Feature to the exising Ingress Controller ( NIC, after all, it is already watching the nginx-ingress namespace and services ).
132142

133143
<br/>
134144

135-
## Example Nginx Plus API requests for Upstream block changes
145+
### Example Nginx Plus API requests for Upstream block changes
136146

137147
<br/>
138148

docs/media/nginxlb-nklv1.png

28.7 KB
Loading

docs/media/nkl-create-nodeport.png

390 KB
Loading

docs/media/nkl-pod-configmap.png

53.7 KB
Loading

docs/nginxk8slb.conf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# NginxK8sLB Stream configuration, for L4 load balancing
2+
# Chris Akker, Jan 2023
3+
# TCP Proxy and load balancing block
4+
# Nginx Kubernetes Loadbalancer
5+
# State File for persistent reloads/restarts
6+
# Health Check Match example for cafe.example.com
7+
#
8+
#### nginxk8slb.conf
9+
10+
upstream nginx-lb-http {
11+
zone nginx-lb-http 256k;
12+
state /var/lib/nginx/state/nginx-lb-http.state;
13+
}
14+
15+
upstream nginx-lb-https {
16+
zone nginx-lb-https 256k;
17+
state /var/lib/nginx/state/nginx-lb-https.state;
18+
}
19+
20+
server {
21+
listen 80;
22+
status_zone nginx-lb-http;
23+
proxy_pass nginx-lb-http;
24+
health_check match=cafe;
25+
}
26+
27+
server {
28+
listen 443;
29+
status_zone nginx-lb-https;
30+
proxy_pass nginx-lb-https;
31+
health_check match=cafe;
32+
}
33+
34+
match cafe {
35+
send "GET cafe.example.com/ HTTP/1.0\r\n";
36+
expect ~ "30*";
37+
}
38+
39+
40+
# Nginx State Files Required for Upstreams
41+
# state file /var/lib/nginx/state/nginx-lb-http.state
42+
43+
# state file /var/lib/nginx/state/nginx-lb-https.state
44+

docs/nginxlb.conf

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
1-
# NginxLB Stream configuration, for TCP load balancing
1+
# NginxK8sLB Stream configuration, for L4 load balancing
22
# Chris Akker, Jan 2023
33
# TCP Proxy and load balancing block
44
# Nginx Kubernetes Loadbalancer
5-
### backup servers allow Nginx to start
6-
# State file used to preserve config across restarts
5+
# Example health check match for cafe.example.com
76
#
8-
#### nginxlb.conf
7+
#### nginxk8slb.conf
98

109
upstream nginx-lb-http {
1110
zone nginx-lb-http 256k;
12-
#placeholder
13-
#server 1.1.1.1:32080 backup;
1411
state /var/lib/nginx/state/nginx-lb-http.state;
1512
}
1613

1714
upstream nginx-lb-https {
1815
zone nginx-lb-https 256k;
19-
#placeholder
20-
#server 1.1.1.1:32443 backup;
2116
state /var/lib/nginx/state/nginx-lb-https.state;
2217
}
2318

2419
server {
2520
listen 80;
2621
status_zone nginx-lb-http;
2722
proxy_pass nginx-lb-http;
23+
health_check match=cafe;
2824
}
29-
25+
3026
server {
3127
listen 443;
3228
status_zone nginx-lb-https;
3329
proxy_pass nginx-lb-https;
30+
health_check match=cafe;
31+
}
32+
33+
match cafe {
34+
send "GET cafe.example.com/ HTTP/1.0\r\n";
35+
expect ~ "30*";
3436
}
3537

3638

docs/nodeport.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# This the default nodeport.yaml manifest for nginx-ingress.
2+
#The port name MUST be changed to match the new LB Controller.
3+
# See the new nodeport-nkl.yaml file example.
4+
#
15
apiVersion: v1
26
kind: Service
37
metadata:

0 commit comments

Comments
 (0)