Skip to content

Commit 171d10b

Browse files
committed
NLB-6740 Updated the design doc
Updating the original NLK design doc to bring it in line with the latest architectural changes.
1 parent 2af7963 commit 171d10b

File tree

1 file changed

+23
-51
lines changed

1 file changed

+23
-51
lines changed

docs/DESIGN.md

Lines changed: 23 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
# Overview
22

3-
The nginx-loadbalancer-kubernetes runs in a Kubernetes Cluster and responds to changes in resources of interest, updating designated NGINX Plus hosts with the appropriate configuration.
3+
The nginx-loadbalancer-kubernetes runs in a Kubernetes cluster and responds to changes in specified services by issuing requests to the designated NGINX Plus hosts to update the appropriate upstreams.
44

55
## Basic Architecture
66

7-
The controller is deployed in a Kubernetes Cluster. Upon startup, it registers interest in changes to Service resources in the "nginx-ingress" namespace.
8-
The Handler accepts the events raised by the Cluster and calls the Translator to convert the events into event definitions that are used to update NGINX Plus hosts.
9-
Next, the Handler calls the Synchronizer with the list of translated events which are fanned-out for each NGINX host.
10-
Lastly, the Synchronizer calls the [NGINX+ Configuration API](https://docs.nginx.com/nginx/admin-guide/load-balancer/dynamic-configuration-api/) using the [NGINX Plus Go client](https://github.com/nginxinc/nginx-plus-go-client) to update the target NGINX Plus host(s).
7+
The controller is deployed in a Kubernetes cluster. Upon startup, it registers interest in changes to services with the appropriate annotation.
8+
The Watcher listens for events raised by the cluster and then adds these events to the Synchronizer's queue. The Synchronizer makes use of the Translator to transform the events into specific updates that will be sent to the NGINX Plus hosts.
9+
Lastly, the Synchronizer calls the [NGINX+ Configuration API](https://docs.nginx.com/nginx/admin-guide/load-balancer/dynamic-configuration-api/) using the [NGINX Plus Go client](https://github.com/nginxinc/nginx-plus-go-client) to update the target NGINX Plus host(s).
1110

1211
```mermaid
1312
stateDiagram-v2
1413
Controller --> Watcher
1514
Controller --> Settings
16-
Watcher --> Handler : "nlk-handler queue"
17-
Handler --> Translator
18-
Translator --> Handler
19-
Handler --> Synchronizer : "nlk-synchronizer queue"
15+
Watcher --> Synchronizer : "nlk-synchronizer queue"
16+
Synchronizer --> Translator
17+
Translator --> Synchronizer
2018
Synchronizer --> BorderClient : "HttpBorderClient | TcpBorderClient"
2119
BorderClient --> NGINXPlusLB1
2220
BorderClient --> NGINXPlusLB2
@@ -26,38 +24,31 @@ stateDiagram-v2
2624

2725
### Settings
2826

29-
The Settings module is responsible for loading the configuration settings from the "nlk-config" ConfigMap resource in the "nlk" namespace.
30-
The Settings are loaded when the controller starts and are reloaded when the "nlk-config" ConfigMap resource is updated.
27+
The Settings module is responsible for loading the configuration settings when the controller starts. Any changes made to the settings through helm at runtime will cause nginx-loadbalancer-kubernetes to be restarted.
3128

3229
### Watcher
3330

34-
The Watcher is responsible for monitoring changes to Service resources in the "nginx-ingress" namespace.
35-
It registers methods that handle each event type. Events are handled by creating a `core.Event` instance and adding it to the "nlk-handler" queue.
36-
When adding the event to the queue, the Watcher also retrieves the list of Node IPs and adds the list to the event.
37-
The master node ip is excluded from the list. (NOTE: This should be configurable.)
38-
39-
### Handler
40-
41-
The Handler is responsible for taking the `core.Event` instances from the "nlk-handler" queue and calling the Translator to convert the event into a `core.ServerUpdateEvent` instance,
42-
adding each `core.ServerUpdateEvent` to the "nlk-synchronizer" queue.
31+
The Watcher is responsible for monitoring changes to Service resources that are annotated by the user.
32+
It registers methods that handle each event type. An event is created for a particular service and is added to the "nlk-synchronizer" queue.
4333

4434
### Translator
4535

46-
The Translator is responsible for converting the `core.Event` event into an `nginxClient.UpstreamServer` event.
47-
This involves filtering out the `core.Event` instances that are not of interest to the controller by accepting only Port names starting with the NlkPrefix value (currently _nlk-_).
48-
The event is then fanned-out based on the defined Ports, one event per defined Port. Each port is then augmented with the Ingress name (the name configured in the Port definition with the NlkPrefix value removed),
49-
and the list of the Node's IP addresses.
36+
The Translator is responsible for converting a `core.Event` event into an `nginxClient.UpstreamServer` event.
5037

51-
The Translator passes the list of events to the Synchronizer by calling the `AddEvents` method.
38+
The Translator assembles a list of IP addresses for the Kubernetes service, routing traffic to the NodePorts, ClusterIPs or external load balancer, depending on the Kubernetes service type. If the service is of type NodePort, the Translator excludes the master node IP from the list of the addresses. (NOTE: This should be configurable.)
39+
40+
The Translator uses the port name to determine the protocol and the name of the user's upstream. For example, if the user has named their service port "http-tea", the translator will create an update event for the HTTP upstream named "tea".
5241

5342
**NOTE: It is important that the Port names match the name of the defined NGINX Plus Upstreams.**
5443

55-
In the following example the NGINX Plus Upstreams are named "nlk-nginx-lb-http" and "nlk-nginx-lb-https". These match the name in the NGINX Plus configuration.
44+
In the following example the service uses the `nginx.com/nginxaas: nginxaas` annotation so that NLK knows to monitor the service. NGINX Plus Upstreams are named "ingress" and "ingress-tls". These match the upstream names specified in the NGINX configuration on the NGINX Plus host.
5645

5746
```yaml
5847
apiVersion: v1
5948
kind: Service
6049
metadata:
50+
annotations:
51+
nginx.com/nginxaas: nginxaas
6152
name: nginx-ingress
6253
namespace: nginx-ingress
6354
spec:
@@ -66,48 +57,29 @@ spec:
6657
- port: 80
6758
targetPort: 80
6859
protocol: TCP
69-
name: nlk-nginx-lb-http
60+
name: http-ingress
7061
- port: 443
7162
targetPort: 443
7263
protocol: TCP
73-
name: nlk-nginx-lb-https
64+
name: http-ingress-tls
7465
selector:
7566
app: nginx-ingress
7667
```
7768
7869
### Synchronizer
7970
8071
The Synchronizer is responsible for fanning-out the given list of `core.ServerUpdateEvent` events, one for each configured NGINX Plus host.
81-
The NGINX Plus hosts are configured using a ConfigMap resource named "nlk-config" in the "nlk" namespace. An example of the ConfigMap is shown below.
72+
The NGINX Plus hosts are configured through the helm chart `nlk.config.nginxHosts` value. Use a string for a single host and a sequence for multiple hosts. See the comments in `charts/nlk/values.yaml` for details.
8273

83-
```yaml
84-
apiVersion: v1
85-
kind: ConfigMap
86-
data:
87-
nginx-hosts:
88-
"http://10.1.1.4:9000/api,http://10.1.1.5:9000/api"
89-
metadata:
90-
name: nlk-config
91-
namespace: nlk
92-
```
93-
94-
This example includes two NGINX Plus hosts to support High Availability.
95-
96-
Additionally, the Synchronizer is responsible for taking the `core.ServerUpdateEvent` instances from the "nlk-synchronizer" queue and updating the target NGINX Plus host.
9774
The Synchronizer uses the [NGINX Plus Go client](https://github.com/nginxinc/nginx-plus-go-client) to communicate with each NGINX Plus host.
9875

99-
10076
#### Retry Mechanism
10177

102-
The Synchronizer uses a retry mechanism to handle failures when updating the NGINX Plus hosts.
103-
The retry mechanism is implemented in the workqueue using the `workqueue.NewItemExponentialFailureRateLimiter`,
78+
The Synchronizer uses a retry mechanism to handle failures when updating the NGINX Plus hosts.
79+
The retry mechanism is implemented in the workqueue using the `workqueue.NewItemExponentialFailureRateLimiter`,
10480
having defaults set to a base of 2 seconds, and a maximum of 60 seconds.
10581

106-
### Jitter
107-
108-
The Synchronizer uses a jitter mechanism to avoid thrashing the NGINX Plus hosts. Each `core.ServerUpdateEvent` instance
109-
is added to the "nlk-synchronizer" queue with a random jitter value between 250 and 750 milliseconds.
110-
11182
## Authors
83+
11284
- Steve Wagner - Solutions Architect - Community and Alliances @ F5, Inc.
11385
- Chris Akker - Solutions Architect - Community and Alliances @ F5, Inc.

0 commit comments

Comments
 (0)