-
Notifications
You must be signed in to change notification settings - Fork 2k
Add custom listener controls to VirtualServer #4271
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
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
3d4db9c
Update CRDS and types
shaun-nx 85f41d5
Add custom HTTP and HTTPs listeners
shaun-nx 1218590
Add configuration problems for listeners
shaun-nx 11cc3bf
Update calls to vs listener function
shaun-nx 637c77c
Update `addProblemsForVSListeners` function
shaun-nx 1cd1328
Ensure VirtualServer config is updated when changes are made to Globa…
shaun-nx b068954
Report correct warnings for missconfigured listeners
shaun-nx 3e9f651
Remove unused function
shaun-nx 222654a
Add new unit tests for configuration.go
shaun-nx f79e6c4
Move validateListenerProtocol function to validation/globalconfigurat…
shaun-nx 3105884
Add unit tests for virtual server when using custom listeners
shaun-nx b45c503
Add additional unit test. Create map of listener name to listener struct
shaun-nx e98d171
Add unit test for empty http and https listeners
shaun-nx 8b412d6
Refactor test to use mustInitGlobalConfiguration()
shaun-nx 90d3f2d
Add additional unit tests
shaun-nx 553ac36
Add test for Deleted GlobalConfiguration with default VirtualSErver d…
shaun-nx dee1fa2
Update VirtualServer template for nginx plus
shaun-nx f43bb81
Add example files for custom listeners
shaun-nx 692ed7f
Add sample README file
shaun-nx 004f183
Update GlobalConfiguration to ensure VS and TS can't listen on the sa…
shaun-nx 45606fa
add template tests
haywoodsh 8f2738d
add initial functional test
vepatel db1dc8a
Remove debug lines
shaun-nx 5df07bb
Merge branch 'main' into exp-vs-custom-listeners
shaun-nx d39ac81
Add test for deleting gc
shaun-nx 9d7557f
Revert "Add test for deleting gc"
shaun-nx a3f1109
Revert "add initial functional test"
shaun-nx 91522fe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 791e9b1
Fix linter error. Refactor configuration tests
shaun-nx e4fa635
Merge branch 'main' into feat/custom-listeners
shaun-nx 5a9c98c
Remove webapp vs and secret from example directory
shaun-nx 1c8578b
Fix CRDs and README
shaun-nx d445d70
Merge branch 'main' into feat/custom-listeners
shaun-nx 87ed313
Update README to include NodePort/Loadbalancer update examples.
shaun-nx 336bd86
Merge branch 'main' into feat/custom-listeners
shaun-nx 772d3c6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -45,5 +45,7 @@ spec: | |
type: integer | ||
protocol: | ||
type: string | ||
ssl: | ||
type: boolean | ||
served: true | ||
storage: true |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -45,5 +45,7 @@ spec: | |
type: integer | ||
protocol: | ||
type: string | ||
ssl: | ||
type: boolean | ||
served: true | ||
storage: true |
This file contains hidden or 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 hidden or 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,181 @@ | ||
# Custom HTTP Listeners | ||
|
||
In this example, we will configure a VirtualServer resource with custom HTTP listeners. | ||
This will allow HTTP and/or HTTPs based requests to be made on non-default ports. | ||
|
||
## Prerequisites | ||
|
||
1. Follow the [installation](https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-manifests/) | ||
instructions to deploy the Ingress Controller with custom resources enabled. | ||
2. Ensure the Ingress Controller is configured with the `-global-configuration` argument: | ||
```console | ||
args: | ||
- -global-configuration=$(POD_NAMESPACE)/nginx-configuration | ||
``` | ||
|
||
3. Save the public IP address of the Ingress Controller into a shell variable: | ||
```console | ||
IC_IP=XXX.YYY.ZZZ.III | ||
``` | ||
|
||
4. If you have a NodePort or Loadbalancer service deployed, ensure they are updated to include the custom listener ports. | ||
Example YAML for a LoadBalancer: | ||
```yaml | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: nginx-ingress | ||
namespace: nginx-ingress | ||
spec: | ||
type: LoadBalancer | ||
ports: | ||
- port: 8083 | ||
targetPort: 8083 | ||
protocol: TCP | ||
name: http-8083 | ||
- port: 8443 | ||
targetPort: 8443 | ||
protocol: TCP | ||
name: https-8443 | ||
selector: | ||
app: nginx-ingress | ||
``` | ||
## Step 1 - Deploy the GlobalConfiguration resource | ||
Similar to how listeners are configured in our [basic-tcp-udp](../../examples/custom-resource/basic-tcp-udp) examples, | ||
here we deploy a GlobalConfiguration resource with the listeners we want to use in our VirtualServer. | ||
```yaml | ||
apiVersion: k8s.nginx.org/v1alpha1 | ||
kind: GlobalConfiguration | ||
metadata: | ||
name: nginx-configuration | ||
namespace: nginx-ingress | ||
spec: | ||
listeners: | ||
- name: http-8083 | ||
port: 8083 | ||
protocol: HTTP | ||
- name: https-8443 | ||
port: 8443 | ||
protocol: HTTP | ||
ssl: true | ||
``` | ||
|
||
```console | ||
kubectl create -f global-configuration.yaml | ||
``` | ||
|
||
## Step 2 - Save the custom port numbers | ||
Save the custom HTTP and/or HTTPS ports into a shell variables for later: | ||
|
||
```console | ||
IC_HTTP_PORT=8083 | ||
IC_HTTPS_PORT=8443 | ||
``` | ||
|
||
## Step 3 - Deploy the Cafe Application | ||
|
||
Create the coffee and the tea deployments and services: | ||
|
||
```console | ||
kubectl create -f cafe.yaml | ||
``` | ||
|
||
## Step 4 - Deploy the VirtualServer with custom listeners | ||
The VirtualServer in this example is set to use the listeners defined in the GlobalConfiguration resource | ||
that was deployed in Step 1. Below is the yaml of this example VirtualServer: | ||
|
||
```yaml | ||
apiVersion: k8s.nginx.org/v1 | ||
kind: VirtualServer | ||
metadata: | ||
name: cafe | ||
spec: | ||
listener: | ||
http: http-8083 | ||
https: https-8443 | ||
host: cafe.example.com | ||
tls: | ||
secret: cafe-secret | ||
upstreams: | ||
- name: tea | ||
service: tea-svc | ||
port: 80 | ||
- name: coffee | ||
service: coffee-svc | ||
port: 80 | ||
routes: | ||
- path: /tea | ||
action: | ||
pass: tea | ||
- path: /coffee | ||
action: | ||
pass: coffee | ||
``` | ||
|
||
1. Create the secret with the TLS certificate and key: | ||
|
||
```console | ||
kubectl create -f cafe-secret.yaml | ||
``` | ||
|
||
2. Create the VirtualServer resource: | ||
|
||
```console | ||
kubectl create -f cafe-virtual-server.yaml | ||
``` | ||
|
||
## Step 5 - Test the Configuration | ||
|
||
1. Check that the configuration has been successfully applied by inspecting the events of the VirtualServer: | ||
|
||
```console | ||
kubectl describe virtualserver cafe | ||
``` | ||
|
||
Below you will see the events as well as the new `Listeners` field | ||
```console | ||
. . . | ||
Spec: | ||
Host: cafe.example.com | ||
Listener: | ||
Http: http-8083 | ||
Https: https-8443 | ||
. . . | ||
Routes: | ||
. . . | ||
Events: | ||
Type Reason Age From Message | ||
---- ------ ---- ---- ------- | ||
Normal AddedOrUpdated 7s nginx-ingress-controller Configuration for default/cafe was added or updated | ||
``` | ||
|
||
2. Since the deployed VirtualServer is using ports `8083` and 8443` in this example. you must explicitly specify these ports | ||
when sending requests to the endpoints of this VirtualServer: | ||
|
||
For `/coffee` on `8443`: | ||
|
||
```console | ||
curl -k https://cafe.example.com:8443/coffee | ||
``` | ||
|
||
```text | ||
Server address: 10.32.0.40:8080 | ||
Server name: coffee-7dd75bc79b-qmhmv | ||
... | ||
URI: /coffee | ||
... | ||
``` | ||
|
||
For `/coffee` on `8083`: | ||
|
||
```console | ||
curl -k https://cafe.example.com:8083/coffee | ||
``` | ||
|
||
```text | ||
Server address: 10.32.0.40:8080 | ||
Server name: coffee-7dd75bc79b-qmhmv | ||
... | ||
URI: /coffee | ||
... | ||
``` |
This file contains hidden or 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,8 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: cafe-secret | ||
type: kubernetes.io/tls | ||
data: | ||
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURMakNDQWhZQ0NRREFPRjl0THNhWFdqQU5CZ2txaGtpRzl3MEJBUXNGQURCYU1Rc3dDUVlEVlFRR0V3SlYKVXpFTE1Ba0dBMVVFQ0F3Q1EwRXhJVEFmQmdOVkJBb01HRWx1ZEdWeWJtVjBJRmRwWkdkcGRITWdVSFI1SUV4MApaREViTUJrR0ExVUVBd3dTWTJGbVpTNWxlR0Z0Y0d4bExtTnZiU0FnTUI0WERURTRNRGt4TWpFMk1UVXpOVm9YCkRUSXpNRGt4TVRFMk1UVXpOVm93V0RFTE1Ba0dBMVVFQmhNQ1ZWTXhDekFKQmdOVkJBZ01Ba05CTVNFd0h3WUQKVlFRS0RCaEpiblJsY201bGRDQlhhV1JuYVhSeklGQjBlU0JNZEdReEdUQVhCZ05WQkFNTUVHTmhabVV1WlhoaApiWEJzWlM1amIyMHdnZ0VpTUEwR0NTcUdTSWIzRFFFQkFRVUFBNElCRHdBd2dnRUtBb0lCQVFDcDZLbjdzeTgxCnAwanVKL2N5ayt2Q0FtbHNmanRGTTJtdVpOSzBLdGVjcUcyZmpXUWI1NXhRMVlGQTJYT1N3SEFZdlNkd0kyaloKcnVXOHFYWENMMnJiNENaQ0Z4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RjZneGJYQW9HQkFNWk8KMHA2SGJCbWNQMHRqRlhmY0tFNzdJbUxtMHNBRzR1SG9VeDBlUGovMnFyblRuT0JCTkU0TXZnRHVUSnp5K2NhVQprOFJxbWRIQ2JIelRlNmZ6WXEvOWl0OHNaNzdLVk4xcWtiSWN1YytSVHhBOW5OaDFUanNSbmU3NFowajFGQ0xrCmhIY3FIMHJpN1BZU0tIVEU4RnZGQ3haWWRidUI4NENtWmlodnhicFJBb0dBSWJqcWFNWVBUWXVrbENkYTVTNzkKWVNGSjFKelplMUtqYS8vdER3MXpGY2dWQ0thMzFqQXdjaXowZi9sU1JxM0hTMUdHR21lemhQVlRpcUxmZVpxYwpSMGlLYmhnYk9jVlZrSkozSzB5QXlLd1BUdW14S0haNnpJbVpTMGMwYW0rUlk5WUdxNVQ3WXJ6cHpjZnZwaU9VCmZmZTNSeUZUN2NmQ21mb09oREN0enVrQ2dZQjMwb0xDMVJMRk9ycW40M3ZDUzUxemM1em9ZNDR1QnpzcHd3WU4KVHd2UC9FeFdNZjNWSnJEakJDSCtULzZzeXNlUGJKRUltbHpNK0l3eXRGcEFOZmlJWEV0LzQ4WGY2ME54OGdXTQp1SHl4Wlp4L05LdER3MFY4dlgxUE9ucTJBNWVpS2ErOGpSQVJZS0pMWU5kZkR1d29seHZHNmJaaGtQaS80RXRUCjNZMThzUUtCZ0h0S2JrKzdsTkpWZXN3WEU1Y1VHNkVEVXNEZS8yVWE3ZlhwN0ZjanFCRW9hcDFMU3crNlRYcDAKWmdybUtFOEFSek00NytFSkhVdmlpcS9udXBFMTVnMGtKVzNzeWhwVTl6WkxPN2x0QjBLSWtPOVpSY21Vam84UQpjcExsSE1BcWJMSjhXWUdKQ2toaVd4eWFsNmhZVHlXWTRjVmtDMHh0VGwvaFVFOUllTktvCi0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg== |
25 changes: 25 additions & 0 deletions
25
examples/custom-resources/custom-listeners/cafe-virtual-server.yaml
This file contains hidden or 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,25 @@ | ||
apiVersion: k8s.nginx.org/v1 | ||
kind: VirtualServer | ||
metadata: | ||
name: cafe | ||
spec: | ||
listener: | ||
http: http-8083 | ||
https: https-8443 | ||
host: cafe.example.com | ||
tls: | ||
secret: cafe-secret | ||
upstreams: | ||
- name: tea | ||
service: tea-svc | ||
port: 80 | ||
- name: coffee | ||
service: coffee-svc | ||
port: 80 | ||
routes: | ||
- path: /tea | ||
action: | ||
pass: tea | ||
- path: /coffee | ||
action: | ||
pass: coffee |
This file contains hidden or 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,65 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: coffee | ||
spec: | ||
replicas: 2 | ||
selector: | ||
matchLabels: | ||
app: coffee | ||
template: | ||
metadata: | ||
labels: | ||
app: coffee | ||
spec: | ||
containers: | ||
- name: coffee | ||
image: nginxdemos/nginx-hello:plain-text | ||
ports: | ||
- containerPort: 8080 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: coffee-svc | ||
spec: | ||
ports: | ||
- port: 80 | ||
targetPort: 8080 | ||
protocol: TCP | ||
name: http | ||
selector: | ||
app: coffee | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: tea | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: tea | ||
template: | ||
metadata: | ||
labels: | ||
app: tea | ||
spec: | ||
containers: | ||
- name: tea | ||
image: nginxdemos/nginx-hello:plain-text | ||
ports: | ||
- containerPort: 8080 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: tea-svc | ||
spec: | ||
ports: | ||
- port: 80 | ||
targetPort: 8080 | ||
protocol: TCP | ||
name: http | ||
selector: | ||
app: tea |
14 changes: 14 additions & 0 deletions
14
examples/custom-resources/custom-listeners/global-configuration.yaml
This file contains hidden or 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,14 @@ | ||
apiVersion: k8s.nginx.org/v1alpha1 | ||
kind: GlobalConfiguration | ||
metadata: | ||
name: nginx-configuration | ||
namespace: nginx-ingress | ||
spec: | ||
listeners: | ||
- name: http-8083 | ||
port: 8083 | ||
protocol: HTTP | ||
- name: https-8443 | ||
port: 8443 | ||
protocol: HTTP | ||
ssl: true |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.