-
Notifications
You must be signed in to change notification settings - Fork 2k
Add tutorial doc for VirtualServer configuration with Custom Listener Ports #4294
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 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d5016f6
Add tutorial doc for VirtualServer configuration with Custom Listener…
shaun-nx 6c621bf
Fix typo
shaun-nx 23af953
Merge branch 'main' into docs/vs-and-gc
shaun-nx 7e468df
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3f05765
Change console to shell. Update listener description
shaun-nx 480535d
Merge branch 'main' into docs/vs-and-gc
shaun-nx a173ca2
Update tutorial document
shaun-nx 38ed07a
Fix typo
shaun-nx 7661f77
docs: Add parallel instructions to tabs, update text for consistency
ADubhlaoich 9515357
Merge branch 'docs/vs-and-gc' of github.com:nginxinc/kubernetes-ingre…
ADubhlaoich 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
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
171 changes: 171 additions & 0 deletions
171
docs/content/tutorials/virtual-server-with-custom-listener-ports.md
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,171 @@ | ||
| --- | ||
| title: VirtualServer with Custom listener ports | ||
shaun-nx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| description: | | ||
| How to configure a VirtualServer with custom HTTP and HTTPS listener ports. | ||
| weight: 1800 | ||
| doctypes: ["concept"] | ||
| toc: true | ||
| --- | ||
| ## Configuring a VirtualServer with custom HTTP and HTTPS listener ports. | ||
|
|
||
| This tutorial outlines how to configure and deploy a VirtualServer resource to with custom HTTP and HTTPS listener ports. | ||
shaun-nx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Previously this was task had to be performed manually as documented in [Customizing NGINX Ingress Controller Ports](/nginx-ingress-controller/tutorials/custom-listen-ports/). | ||
shaun-nx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| VirtualServer now explicitly defines custom HTTP and HTTPS listener ports using the `spec.listener.http` and `spec.listener.https` fields. | ||
shaun-nx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Each field must reference a valid listener defined by in a [GlobalConfiguration](/nginx-ingress-controller/configuration/global-configuration/globalconfiguration-resource/) resource. | ||
|
|
||
| ## Deploy GlobalConfiguration | ||
|
|
||
| 1. Create a yaml file called `nginx-configuration.yaml` with the below content: | ||
| ```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 | ||
| ``` | ||
| 2. Deploy `nginx-configuration.yaml` file: | ||
| ```console | ||
shaun-nx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| kubectl apply -f nginx-configuration.yaml | ||
| ``` | ||
|
|
||
| ## Deploying NGINX Ingress Controller with GlobalConfiguration resource | ||
|
|
||
| ### Manifest | ||
|
|
||
| 1. Add the below argument to the manifest file of the NGINX Ingress Controller: | ||
| ```yaml | ||
| args: | ||
| - -$(POD_NAMESPACE)/nginx-configuration | ||
| ``` | ||
|
|
||
| 2. Follow the [installation](/nginx-ingress-controller/installation/installation-with-manifests/) instructions to deploy the NGINX Ingress Controller with custom resources enabled. | ||
|
|
||
| 3. If you have a NodePort service or Loabalancer service deployed, these will need to be configured to expose the custom listener ports. Below is an example yaml using NodePort. This same configuration will also apply to a Loadbalancer service: | ||
| ```yaml | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: nginx-ingress | ||
| namespace: nginx-ingress | ||
| spec: | ||
| type: NodePort | ||
| ports: | ||
| - port: 8083 | ||
| targetPort: 8083 # Custom HTTP listener port | ||
| protocol: TCP | ||
| name: http-8083 | ||
| - port: 8443 | ||
| targetPort: 8443 # Custom HTTPS listener port | ||
| protocol: TCP | ||
| name: https-8443 | ||
| selector: | ||
| app: nginx-ingress | ||
| ``` | ||
|
|
||
| ### HELM | ||
| 1. Add the below content to your `values.yaml` file in `controller.globalConfiguration`: | ||
| ```yaml | ||
| spec: | ||
| listeners: | ||
| - name: http-8083 | ||
| port: 8083 | ||
| protocol: HTTP | ||
| - name: https-8443 | ||
| port: 8443 | ||
| protocol: HTTP | ||
| ssl: true | ||
| ``` | ||
|
|
||
| 2. Ensure your NodePort or Loadbalancer service is configured to expose the custom listener ports. This is set in the `customPorts` section under `controller.service.customPorts` | ||
| ```yaml | ||
| customPorts: | ||
| - name: http-8083 | ||
| port: 8083 | ||
| protocol: TCP | ||
| targetPort: 8083 | ||
| - name: https-8443 | ||
| port: 8443 | ||
| protocol: TCP | ||
| targetPort: 8443 | ||
| ``` | ||
|
|
||
| 3. Follow the [HELM installation](/nginx-ingress-controller/installation/installation-with-helm/) instructions to deploy the NGINX Ingress Controller with custom resources enabled. | ||
|
|
||
| ## Deploying VirtualServer with custom listeners | ||
| Deploy the example resources in the [custom listeners](/examples/custom-resources/custom-listeners/) folder. This will deploy all the required resources, including the VirtualServer. | ||
|
|
||
| Below is a snippet of the VirtualServer resource that will be deployed: | ||
| ```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: | ||
| ... | ||
| ``` | ||
|
|
||
| Below is a snippet of the NGINX configuration for this VirtualServer. | ||
|
|
||
| ```nginx | ||
| server { | ||
| listen 8083; | ||
| listen [::]:8083; | ||
| server_name cafe.example.com; | ||
| set $resource_type "virtualserver"; | ||
| set $resource_name "cafe"; | ||
| set $resource_namespace "default"; | ||
| listen 8443 ssl; | ||
| listen [::]:8443 ssl; | ||
| ssl_certificate /etc/nginx/secrets/default-cafe-secret; | ||
| ssl_certificate_key /etc/nginx/secrets/default-cafe-secret; | ||
| } | ||
| ``` | ||
|
|
||
| ## Testing custom listener ports | ||
|
|
||
| Since the VirtualServer resource is deployed with non-default ports, these ports must be explicitly specified when sending requests. | ||
|
|
||
| `curl` using port `8443`: | ||
| ```console | ||
| curl -k https://cafe.example.com:8443/coffee | ||
| Server address: 10.32.0.40:8080 | ||
| Server name: coffee-7dd75bc79b-qmhmv | ||
| ... | ||
| URI: /coffee | ||
| ... | ||
| ``` | ||
|
|
||
| `curl` using port `8083`: | ||
| ```console | ||
| curl -k http://cafe.example.com:8083/coffee | ||
| Server address: 10.32.0.40:8080 | ||
| Server name: coffee-7dd75bc79b-qmhmv | ||
| ... | ||
| URI: /coffee | ||
| ... | ||
| ``` | ||
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.