Skip to content

Commit ba01bc1

Browse files
jjngxADubhlaoichvepatelshaun-nx
authored
Add support for backup directive for VS and TS (#4653)
Co-authored-by: Alan Dooley <[email protected]> Co-authored-by: Venktesh Shivam Patel <[email protected]> Co-authored-by: shaun-nx <[email protected]>
1 parent 5e0bd5c commit ba01bc1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4260
-120
lines changed

config/crd/bases/k8s.nginx.org_transportservers.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ spec:
103103
items:
104104
description: TransportServerUpstream defines an upstream.
105105
properties:
106+
backup:
107+
type: string
108+
backupPort:
109+
type: integer
106110
failTimeout:
107111
type: string
108112
healthCheck:
@@ -251,6 +255,10 @@ spec:
251255
items:
252256
description: TransportServerUpstream defines an upstream.
253257
properties:
258+
backup:
259+
type: string
260+
backupPort:
261+
type: integer
254262
failTimeout:
255263
type: string
256264
healthCheck:

config/crd/bases/k8s.nginx.org_virtualserverroutes.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ spec:
498498
items:
499499
description: Upstream defines an upstream.
500500
properties:
501+
backup:
502+
type: string
503+
backupPort:
504+
type: integer
501505
buffer-size:
502506
type: string
503507
buffering:

config/crd/bases/k8s.nginx.org_virtualservers.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,10 @@ spec:
599599
items:
600600
description: Upstream defines an upstream.
601601
properties:
602+
backup:
603+
type: string
604+
backupPort:
605+
type: integer
602606
buffer-size:
603607
type: string
604608
buffering:

deploy/crds.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,10 @@ spec:
612612
items:
613613
description: TransportServerUpstream defines an upstream.
614614
properties:
615+
backup:
616+
type: string
617+
backupPort:
618+
type: integer
615619
failTimeout:
616620
type: string
617621
healthCheck:
@@ -760,6 +764,10 @@ spec:
760764
items:
761765
description: TransportServerUpstream defines an upstream.
762766
properties:
767+
backup:
768+
type: string
769+
backupPort:
770+
type: integer
763771
failTimeout:
764772
type: string
765773
healthCheck:
@@ -1321,6 +1329,10 @@ spec:
13211329
items:
13221330
description: Upstream defines an upstream.
13231331
properties:
1332+
backup:
1333+
type: string
1334+
backupPort:
1335+
type: integer
13241336
buffer-size:
13251337
type: string
13261338
buffering:
@@ -2102,6 +2114,10 @@ spec:
21022114
items:
21032115
description: Upstream defines an upstream.
21042116
properties:
2117+
backup:
2118+
type: string
2119+
backupPort:
2120+
type: integer
21052121
buffer-size:
21062122
type: string
21072123
buffering:

docs/content/configuration/transportserver-resource.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ loadBalancingMethod: least_conn
158158
|``failTimeout`` | Sets the [time](https://nginx.org/en/docs/stream/ngx_stream_upstream_module.html#fail_timeout) during which the specified number of unsuccessful attempts to communicate with the server should happen to consider the server unavailable and the period of time the server will be considered unavailable. The default is ``10s``. | ``string`` | No |
159159
|``healthCheck`` | The health check configuration for the Upstream. See the [health_check](https://nginx.org/en/docs/stream/ngx_stream_upstream_hc_module.html#health_check) directive. Note: this feature is supported only in NGINX Plus. | [healthcheck](#upstreamhealthcheck) | No |
160160
|``loadBalancingMethod`` | The method used to load balance the upstream servers. By default, connections are distributed between the servers using a weighted round-robin balancing method. See the [upstream](http://nginx.org/en/docs/stream/ngx_stream_upstream_module.html#upstream) section for available methods and their details. | ``string`` | No |
161+
|``backup`` | The name of the backup service of type [ExternalName](https://kubernetes.io/docs/concepts/services-networking/service/#externalname). This will be used when the primary servers are unavailable. Note: The parameter cannot be used along with the ``random`` , ``hash`` or ``ip_hash`` load balancing methods. | ``string`` | No |
162+
|``backupPort`` | The port of the backup service. The backup port is required if the backup service name is provided. The port must fall into the range ``1..65535``. | ``uint16`` | No |
161163
{{% /table %}}
162164

163165
### Upstream.Healthcheck

docs/content/configuration/virtualserver-and-virtualserverroute-resources.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ tls:
372372
|``buffer-size`` | Sets the size of the buffer used for reading the first part of a response received from the upstream server. See the [proxy_buffer_size](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size) directive. The default is set in the ``proxy-buffer-size`` ConfigMap key. | ``string`` | No |
373373
|``ntlm`` | Allows proxying requests with NTLM Authentication. See the [ntlm](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#ntlm) directive. In order for NTLM authentication to work, it is necessary to enable keepalive connections to upstream servers using the ``keepalive`` field. Note: this feature is supported only in NGINX Plus.| ``boolean`` | No |
374374
|``type`` |The type of the upstream. Supported values are ``http`` and ``grpc``. The default is ``http``. For gRPC, it is necessary to enable HTTP/2 in the [ConfigMap](/nginx-ingress-controller/configuration/global-configuration/configmap-resource/#listeners) and configure TLS termination in the VirtualServer. | ``string`` | No |
375+
|``backup`` | The name of the backup service of type [ExternalName](https://kubernetes.io/docs/concepts/services-networking/service/#externalname). This will be used when the primary servers are unavailable. Note: The parameter cannot be used along with the ``random`` , ``hash`` or ``ip_hash`` load balancing methods. | ``string`` | No |
376+
|``backupPort`` | The port of the backup service. The backup port is required if the backup service name is provided. The port must fall into the range ``1..65535``. | ``uint16`` | No |
375377
{{% /table %}}
376378

377379
### Upstream.Buffers
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Support for Backup Directive in Transport Server
2+
3+
F5 NGINX Ingress Controller supports routing requests to a service called `backup`.
4+
`backup` is an [ExternalName](https://kubernetes.io/docs/concepts/services-networking/service/#externalname) service.
5+
6+
> [!NOTE]
7+
> The [ExternalName](https://kubernetes.io/docs/concepts/services-networking/service/#externalname) service is only
8+
available with NGINX Plus.
9+
10+
For this example, we will use two [tls-passthrough](/examples/custom-resources/tls-passthrough) configurations.
11+
One will be deployed in the `default` namespace, and the other in the `external-ns` namespace.
12+
13+
The application in the `external-ns` namespace will respond to our requests when main application is unavailable.
14+
15+
## Prerequisites
16+
17+
1. Configure the F5 NGINX Ingress Controller deployment with the following flags:
18+
19+
```shell
20+
-enable-custom-resources
21+
-enable-tls-passthrough
22+
-watch-namespace=nginx-ingress,default
23+
```
24+
25+
We configure the `-watch-namespace` flag to only watch the `nginx-ingress` and `default` namespaces.
26+
This ensures that NGINX Ingress Controller will treat our service in the `external-ns` namespace
27+
as an external service.
28+
29+
2. Follow the [installation](https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-manifests/)
30+
instructions to deploy NGINX Ingress Controller.
31+
32+
3. Save the public IP address of the F5 NGINX Ingress Controller into a shell variable:
33+
34+
```shell
35+
IC_IP=XXX.YYY.ZZZ.III
36+
```
37+
38+
4. Save the HTTPS port of NGINX Ingress Controller into a shell variable:
39+
40+
```shell
41+
IC_HTTPS_PORT=<port number>
42+
```
43+
44+
## Deployment
45+
46+
### 1. Deploy ConfigMap with defined resolver
47+
48+
```shell
49+
kubectl create -f nginx-config.yaml
50+
```
51+
52+
### 2. Deploy Backup ExternalName service
53+
54+
```shell
55+
kubectl create -f backup-svc.yaml
56+
```
57+
58+
### 3. Deploy the tls-passthrough application
59+
60+
```shell
61+
kubectl create -f secure-app.yaml
62+
```
63+
64+
### 4. Deploy TransportServer
65+
66+
```shell
67+
kubectl create -f transport-server-passthrough.yaml
68+
```
69+
70+
### 5. Test the Configuration
71+
72+
Run the below curl command to get a response from your application:
73+
74+
```shell
75+
curl --resolve app.example.com:$IC_HTTPS_PORT:$IC_IP https://app.example.com:$IC_HTTPS_PORT --insecure
76+
```
77+
78+
```shell
79+
hello from pod secure-app-694bc784b-qh8ng
80+
```
81+
82+
### 6. Deploy the second tls-passthrough application to the external namespace
83+
84+
```shell
85+
kubectl apply -f external-secure-app.yaml
86+
```
87+
88+
### 7. Test the configuration using the backup service
89+
90+
1. Scale down `secure-app` deployment to 0.
91+
This is done to ensure that the external `backup` service will respond to our requests.
92+
93+
```shell
94+
kubectl scale deployment secure-app --replicas=0
95+
```
96+
97+
2. Verify if the application is working by sending a request and check if the response is coming from the "external
98+
backend pod"
99+
100+
```shell
101+
curl --resolve app.example.com:$IC_HTTPS_PORT:$IC_IP https://app.example.com:$IC_HTTPS_PORT --insecure
102+
```
103+
104+
3. Check response from the backup service
105+
106+
```shell
107+
HELLO FROM EXTERNAL APP pod secure-app-backup-7d98dd8d78-p8q7d
108+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: Service
2+
apiVersion: v1
3+
metadata:
4+
name: backup-svc-ts
5+
spec:
6+
type: ExternalName
7+
externalName: secure-app-backup.external-ns.svc.cluster.local
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: external-ns
5+
namespace: external-ns
6+
---
7+
apiVersion: apps/v1
8+
kind: Deployment
9+
metadata:
10+
name: secure-app-backup
11+
namespace: external-ns
12+
spec:
13+
replicas: 1
14+
selector:
15+
matchLabels:
16+
app: secure-app-backup
17+
template:
18+
metadata:
19+
labels:
20+
app: secure-app-backup
21+
spec:
22+
containers:
23+
- name: secure-app-backup
24+
image: nginxdemos/nginx-hello:plain-text
25+
ports:
26+
- containerPort: 8443
27+
volumeMounts:
28+
- name: secret
29+
mountPath: /etc/nginx/ssl
30+
readOnly: true
31+
- name: config-volume
32+
mountPath: /etc/nginx/conf.d
33+
volumes:
34+
- name: secret
35+
secret:
36+
secretName: app-tls-secret
37+
- name: config-volume
38+
configMap:
39+
name: secure-config
40+
---
41+
apiVersion: v1
42+
kind: Service
43+
metadata:
44+
name: secure-app-backup
45+
namespace: external-ns
46+
spec:
47+
ports:
48+
- port: 8443
49+
targetPort: 8443
50+
protocol: TCP
51+
name: https
52+
selector:
53+
app: secure-app-backup
54+
---
55+
apiVersion: v1
56+
kind: ConfigMap
57+
metadata:
58+
name: secure-config
59+
namespace: external-ns
60+
data:
61+
app.conf: |-
62+
server {
63+
listen 8443 ssl;
64+
listen [::]:8443 ssl;
65+
66+
server_name app.example.com;
67+
68+
ssl_certificate /etc/nginx/ssl/tls.crt;
69+
ssl_certificate_key /etc/nginx/ssl/tls.key;
70+
71+
default_type text/plain;
72+
73+
location / {
74+
return 200 "HELLO FROM EXTERNAL APP pod $hostname\n";
75+
}
76+
}
77+
---
78+
apiVersion: v1
79+
kind: Secret
80+
metadata:
81+
name: app-tls-secret
82+
namespace: external-ns
83+
data:
84+
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURGRENDQWZ3Q0NRQ3EzQWxhdnJiaWpqQU5CZ2txaGtpRzl3MEJBUXNGQURCTU1Rc3dDUVlEVlFRR0V3SlYKVXpFTE1Ba0dBMVVFQ0F3Q1EwRXhGakFVQmdOVkJBY01EVk5oYmlCR2NtRnVZMmx6WTI4eEdEQVdCZ05WQkFNTQpEMkZ3Y0M1bGVHRnRjR3hsTG1OdmJUQWVGdzB5TURBek1qTXlNekl3TkROYUZ3MHlNekF6TWpNeU16SXdORE5hCk1Fd3hDekFKQmdOVkJBWVRBbFZUTVFzd0NRWURWUVFJREFKRFFURVdNQlFHQTFVRUJ3d05VMkZ1SUVaeVlXNWoKYVhOamJ6RVlNQllHQTFVRUF3d1BZWEJ3TG1WNFlXMXdiR1V1WTI5dE1JSUJJakFOQmdrcWhraUc5dzBCQVFFRgpBQU9DQVE4QU1JSUJDZ0tDQVFFQTJCRXhZR1JPRkhoN2VPMVlxeCtWRHMzRzMrVEhyTEZULzdEUFFEQlkza3pDCi9oZlprWCt3OW1NNkQ1RU9uK2lpVlNhUWlQMm1aNFA3N29pR0dmd3JrNjJ0eEQ5cHphODM5NC9aSjF5Q0dXZ1QKK2NWUEVZbkxjQktzSTRMcktJZ21oWVIwUjNzWWRjR1JkSXJWUFZlNUVUQlk1Z1U0RGhhMDZOUEIraitmK0krWgphWGIvMlRBekJhNHozMWpIQzg2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S1NsOTBIU2VWVGx3czdqSnNxcC9yWFY2aHF0eUdEaTg4aTFZekthcEF6dXl3b0U3TnEKMUJpd2ZYSURQeTlPNUdGNXFYNXFUeENzSWNIcmo2Z21XMEZVQWhoS1lQcDRxd1JMdzFMZkJsd3U1VmhuN3I3ego0SkZBTEFpdlp4a0NnWUJicnpuKzVvZjdFSmtqQTdDYWlYTHlDczVLUzkrTi8rcGl6NktNMkNSOWFKRVNHZkhwClp3bTErNXRyRXIwYVgxajE0bGRxWTlKdjBrM3ZxVWs2a2h5bThUUk1mbThjeG5GVkdTMzF3SVpMaWpmOWlndkkKd0paQnBFaEkvaE83enVBWmJGYWhwR1hMVUJSUFJyalNxQ01IQ1UwcEpWTWtIZUtCNVhqcXRPNm5VUUtCZ0NJUAp6VHlzYm44TW9XQVZpSEJ4Uk91dFVKa1BxNmJZYUU3N0JSQkIwd1BlSkFRM1VjdERqaVh2RzFYWFBXQkR4VEFrCnNZdFNGZ214eEprTXJNWnJqaHVEbDNFLy9xckZOb1VYcmtxS2l4Tk4wcWMreXdDOWJPSVpHcXJUWG5jOHIzRkcKRFZlZWI5QWlrTU0ya3BkYTFOaHJnaS8xMVphb1lmVE0vQmRrNi9IUkFvR0JBSnFzTmFZYzE2clVzYzAzUEwybApXUGNzRnZxZGI3SEJyakVSRkhFdzQ0Vkt2MVlxK0ZWYnNNN1FTQVZ1V1llcGxGQUpDYzcrSEt1YjRsa1hRM1RkCndSajJLK2pOUzJtUXp1Y2hOQnlBZ1hXVnYveHhMZEE3NnpuWmJYdjl5cXhnTVVjTVZwZGRuSkxVZm9QVVZ1dTcKS0tlVVU3TTNIblRKUStrcldtbUxraUlSCi0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0K
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: ConfigMap
2+
apiVersion: v1
3+
metadata:
4+
name: nginx-config
5+
namespace: nginx-ingress
6+
data:
7+
resolver-addresses: "kube-dns.kube-system.svc.cluster.local"

0 commit comments

Comments
 (0)