From 359f8d94f3cf7e8e7f4f348372c02c7d725af366 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Sun, 2 Apr 2023 16:08:25 -0700 Subject: [PATCH 01/11] Custom listen ports document --- docs/content/tutorials/custom-listen-ports.md | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 docs/content/tutorials/custom-listen-ports.md diff --git a/docs/content/tutorials/custom-listen-ports.md b/docs/content/tutorials/custom-listen-ports.md new file mode 100644 index 0000000000..3dd99d5c03 --- /dev/null +++ b/docs/content/tutorials/custom-listen-ports.md @@ -0,0 +1,137 @@ +## Customizing the `listen` line in NGINX Ingress Controller. + +This document will explain how to change the default ports that NGINX Ingress Controller is configured for, as well as add additional `listen` settings. For more information, please read the [NGINX Listen documentation](http://nginx.org/en/docs/http/ngx_http_core_module.html#listen). + + +## Changing Default Ports + +By default, NGINX Ingress Controller listens on ports 80 and 443. These ports can be changed easily, but modifying the `listen` ports for your NGINX Ingress resources will require the editing of .tmpl files. + +If you are using `ingress` resource you will need to modify: +- `nginx-plus-ingress.tmpl` if using NGINX Plus +- `nginx-ingress.tmpl` if using NGINX OSS + +If you are using NGINX Ingress Controller CRDs (virtualServer): +- `nginx-plus-virtualserver.tmpl` for NGINX Plus +- `nginx-virtualserver.tmpl` if using NGINX OSS + +For this example, we are going to use the `nginx-virtualserver.tmpl` to change the port from 80 to 85. + +Here we modify `nginx-virtualserver.tmpl` to change the port setting: + +``` +server { + listen 80{{ if $s.ProxyProtocol }} proxy_protocol{{ end }}; + + server_name {{ $s.ServerName }}; + + set $resource_type "virtualserver"; + set $resource_name "{{$s.VSName}}"; + set $resource_namespace "{{$s.VSNamespace}}"; +``` +To change the listen port from `80` to `85`, we modify the `listen` line at the start of the server configuration block. + +It would then look like this: +``` +server { + listen 85{{ if $s.ProxyProtocol }} proxy_protocol{{ end }}; + + server_name {{ $s.ServerName }}; + + set $resource_type "virtualserver"; + set $resource_name "{{$s.VSName}}"; + set $resource_namespace "{{$s.VSNamespace}}"; +``` + +Edit the file you need (per the example above). In my case, I edited, `nginx-plus-virtualserver.tmpls`: + + +## Rebuild your NGINX Ingress controller image + +You will need to build your new NGINX Ingress controller image for the new port settings to take affect. +Once the image is built and pushed, make sure you update your deployment to point to the new image and deploy. +Once deployed, create a new `virtualServer` resource and then run `nginx -T` to see if the port takes affect. + +Ensure that your `deployment` and your `service` match up to the new port you configured in the templates. +Here is simple example of my `deployment` and my `service` matching to the new port that NGINX Ingress controller now listens on. + +``` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-ingress + namespace: nginx-ingress +spec: + replicas: 1 + selector: + matchLabels: + app: nginx-ingress + template: + metadata: + labels: + app: nginx-ingress + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "9113" + prometheus.io/scheme: http + spec: + serviceAccountName: nginx-ingress + containers: + - image: nginx/nginx-ingress:3.0.2 + imagePullPolicy: IfNotPresent + name: nginx-ingress + ports: + - name: http + containerPort: 85 + - name: https + containerPort: 443 + - name: readiness-port + containerPort: 8081 + - name: prometheus + containerPort: 9113 + readinessProbe: + httpGet: + path: /nginx-ready + port: readiness-port + periodSeconds: 1 + securityContext: +``` + +Notice that now, my `http` port is set to `85`, which reflects the change I made in the template file. + +Here is my `service` file: + +``` +apiVersion: v1 +kind: Service +metadata: + name: nginx-ingress + namespace: nginx-ingress +spec: + externalTrafficPolicy: Local + type: LoadBalancer + ports: + - port: 80 + targetPort: 85 + protocol: TCP + name: http + - port: 8443 + targetPort: 8443 + protocol: TCP + name: https + selector: + app: nginx-ingress +``` + +Since NGINX Ingress controller is now listening on ports 85 and 8443, we modify the `targetPort` in the NGINX Ingress controller service, to match what we have changed in our deployment, to ensure traffic will be sent to the proper port. +The key part above is the `targetPort` section. Since I change NGINX Ingress to listen on port 85, I need to match that in the service. That way, requests will be sent to NGINX Ingress controller on port 85 instead of the default value which is port 80. + + +If you view the `NGINX` configuration .conf file using `nginx -T`, you should see the port you defined in the .template file, now is set on the `listen` line. + +``` +server { + listen 85; + listen [::]:85; + listen 8011; +``` From 57810933f4abec66e8eff964f32ed4283b9c5883 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 2 Apr 2023 23:12:15 +0000 Subject: [PATCH 02/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/content/tutorials/custom-listen-ports.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/content/tutorials/custom-listen-ports.md b/docs/content/tutorials/custom-listen-ports.md index 3dd99d5c03..536478997e 100644 --- a/docs/content/tutorials/custom-listen-ports.md +++ b/docs/content/tutorials/custom-listen-ports.md @@ -6,7 +6,7 @@ This document will explain how to change the default ports that NGINX Ingress Co ## Changing Default Ports By default, NGINX Ingress Controller listens on ports 80 and 443. These ports can be changed easily, but modifying the `listen` ports for your NGINX Ingress resources will require the editing of .tmpl files. - + If you are using `ingress` resource you will need to modify: - `nginx-plus-ingress.tmpl` if using NGINX Plus - `nginx-ingress.tmpl` if using NGINX OSS @@ -15,7 +15,7 @@ If you are using NGINX Ingress Controller CRDs (virtualServer): - `nginx-plus-virtualserver.tmpl` for NGINX Plus - `nginx-virtualserver.tmpl` if using NGINX OSS -For this example, we are going to use the `nginx-virtualserver.tmpl` to change the port from 80 to 85. +For this example, we are going to use the `nginx-virtualserver.tmpl` to change the port from 80 to 85. Here we modify `nginx-virtualserver.tmpl` to change the port setting: From 6136c2d6abc2f668e728ff5bf8e9ae21613fbeec Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Wed, 5 Apr 2023 14:34:43 -0700 Subject: [PATCH 03/11] Merged updated URL --- docs/content/tutorials/custom-listen-ports.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/content/tutorials/custom-listen-ports.md b/docs/content/tutorials/custom-listen-ports.md index 536478997e..1b3c7c54ea 100644 --- a/docs/content/tutorials/custom-listen-ports.md +++ b/docs/content/tutorials/custom-listen-ports.md @@ -15,7 +15,7 @@ If you are using NGINX Ingress Controller CRDs (virtualServer): - `nginx-plus-virtualserver.tmpl` for NGINX Plus - `nginx-virtualserver.tmpl` if using NGINX OSS -For this example, we are going to use the `nginx-virtualserver.tmpl` to change the port from 80 to 85. +For this example, we are going to use the `nginx-virtualserver.tmpl` to change the port from 80 to 85. [nginx-virtualserver template files](https://github.com/nginxinc/kubernetes-ingress/tree/main/internal/configs/version2) Here we modify `nginx-virtualserver.tmpl` to change the port setting: @@ -43,7 +43,7 @@ server { set $resource_namespace "{{$s.VSNamespace}}"; ``` -Edit the file you need (per the example above). In my case, I edited, `nginx-plus-virtualserver.tmpls`: +Edit the file you need (per the example above). In my case, I edited, `nginx-plus-virtualserver.tmpl`: ## Rebuild your NGINX Ingress controller image From 11579c30368a6192e824c6cf740b68abf67868aa Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 5 Apr 2023 22:19:09 +0000 Subject: [PATCH 04/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/content/tutorials/custom-listen-ports.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/tutorials/custom-listen-ports.md b/docs/content/tutorials/custom-listen-ports.md index 1b3c7c54ea..a2f9b6ab29 100644 --- a/docs/content/tutorials/custom-listen-ports.md +++ b/docs/content/tutorials/custom-listen-ports.md @@ -15,7 +15,7 @@ If you are using NGINX Ingress Controller CRDs (virtualServer): - `nginx-plus-virtualserver.tmpl` for NGINX Plus - `nginx-virtualserver.tmpl` if using NGINX OSS -For this example, we are going to use the `nginx-virtualserver.tmpl` to change the port from 80 to 85. [nginx-virtualserver template files](https://github.com/nginxinc/kubernetes-ingress/tree/main/internal/configs/version2) +For this example, we are going to use the `nginx-virtualserver.tmpl` to change the port from 80 to 85. [nginx-virtualserver template files](https://github.com/nginxinc/kubernetes-ingress/tree/main/internal/configs/version2) Here we modify `nginx-virtualserver.tmpl` to change the port setting: From f07e17092b398d89a30826d41298e3bff9c9fa76 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Tue, 4 Apr 2023 12:44:25 -0700 Subject: [PATCH 05/11] Add DOC ID --- docs/content/tutorials/custom-listen-ports.md | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/content/tutorials/custom-listen-ports.md b/docs/content/tutorials/custom-listen-ports.md index a2f9b6ab29..9534317ff2 100644 --- a/docs/content/tutorials/custom-listen-ports.md +++ b/docs/content/tutorials/custom-listen-ports.md @@ -1,3 +1,12 @@ +--- +title: Customze ports for NGINX Ingress Controller +description: | + Customze ports for NGINX Ingress Controller +weight: 1800 +doctypes: ["concept"] +toc: true +docs: "DOCS-1191" +--- ## Customizing the `listen` line in NGINX Ingress Controller. This document will explain how to change the default ports that NGINX Ingress Controller is configured for, as well as add additional `listen` settings. For more information, please read the [NGINX Listen documentation](http://nginx.org/en/docs/http/ngx_http_core_module.html#listen). @@ -128,10 +137,21 @@ The key part above is the `targetPort` section. Since I change NGINX Ingress to If you view the `NGINX` configuration .conf file using `nginx -T`, you should see the port you defined in the .template file, now is set on the `listen` line. +Here is an example output of the `NGINX` configuration that is now generated: + +```bash +k exec -it -n nginx-ingress nginx-ingress-54bffd78d9-v7bns -- nginx -T +``` ``` server { listen 85; listen [::]:85; listen 8011; + + server_name cafe.example.com; + + set $resource_type "virtualserver"; + set $resource_name "cafe"; + set $resource_namespace "default"; ``` From 7d7722c6c0aa109963df72eefb277ccc0b0ac2bc Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Wed, 5 Apr 2023 15:25:18 -0700 Subject: [PATCH 06/11] Fix URL link typo --- docs/content/tutorials/custom-listen-ports.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/content/tutorials/custom-listen-ports.md b/docs/content/tutorials/custom-listen-ports.md index 9534317ff2..a7b71d0281 100644 --- a/docs/content/tutorials/custom-listen-ports.md +++ b/docs/content/tutorials/custom-listen-ports.md @@ -24,7 +24,11 @@ If you are using NGINX Ingress Controller CRDs (virtualServer): - `nginx-plus-virtualserver.tmpl` for NGINX Plus - `nginx-virtualserver.tmpl` if using NGINX OSS -For this example, we are going to use the `nginx-virtualserver.tmpl` to change the port from 80 to 85. [nginx-virtualserver template files](https://github.com/nginxinc/kubernetes-ingress/tree/main/internal/configs/version2) +For this example, we are going to use the `nginx-virtualserver.tmpl` to change the port from 80 to 85. +Here is a link to the directory for the `.tmpl` files: + +[nginx-virtualserver template files](https://github.com/nginxinc/kubernetes-ingress/tree/main/internal/configs/version2) + Here we modify `nginx-virtualserver.tmpl` to change the port setting: From 520e22d478dbe577dd86af0189d8c6f2b12e46e5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 5 Apr 2023 22:26:06 +0000 Subject: [PATCH 07/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/content/tutorials/custom-listen-ports.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/content/tutorials/custom-listen-ports.md b/docs/content/tutorials/custom-listen-ports.md index a7b71d0281..7502b437dd 100644 --- a/docs/content/tutorials/custom-listen-ports.md +++ b/docs/content/tutorials/custom-listen-ports.md @@ -1,7 +1,7 @@ --- -title: Customze ports for NGINX Ingress Controller +title: Customze ports for NGINX Ingress Controller description: | - Customze ports for NGINX Ingress Controller + Customze ports for NGINX Ingress Controller weight: 1800 doctypes: ["concept"] toc: true @@ -24,8 +24,8 @@ If you are using NGINX Ingress Controller CRDs (virtualServer): - `nginx-plus-virtualserver.tmpl` for NGINX Plus - `nginx-virtualserver.tmpl` if using NGINX OSS -For this example, we are going to use the `nginx-virtualserver.tmpl` to change the port from 80 to 85. -Here is a link to the directory for the `.tmpl` files: +For this example, we are going to use the `nginx-virtualserver.tmpl` to change the port from 80 to 85. +Here is a link to the directory for the `.tmpl` files: [nginx-virtualserver template files](https://github.com/nginxinc/kubernetes-ingress/tree/main/internal/configs/version2) From 72cd706c8b37122c7db8ac09a5a67a444c213a02 Mon Sep 17 00:00:00 2001 From: Alan Dooley Date: Wed, 21 Jun 2023 12:26:31 +0100 Subject: [PATCH 08/11] Apply suggestions from code review Co-authored-by: Jon Torre <78599298+Jcahilltorre@users.noreply.github.com> Signed-off-by: Alan Dooley --- docs/content/tutorials/custom-listen-ports.md | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/docs/content/tutorials/custom-listen-ports.md b/docs/content/tutorials/custom-listen-ports.md index 7502b437dd..372962070d 100644 --- a/docs/content/tutorials/custom-listen-ports.md +++ b/docs/content/tutorials/custom-listen-ports.md @@ -24,15 +24,13 @@ If you are using NGINX Ingress Controller CRDs (virtualServer): - `nginx-plus-virtualserver.tmpl` for NGINX Plus - `nginx-virtualserver.tmpl` if using NGINX OSS -For this example, we are going to use the `nginx-virtualserver.tmpl` to change the port from 80 to 85. -Here is a link to the directory for the `.tmpl` files: +For this example, we will use the `nginx-virtualserver.tmpl` template to change the port from 80 to 85. +You can find the [nginx-virtualserver template files in our repository](https://github.com/nginxinc/kubernetes-ingress/tree/main/internal/configs/version2). -[nginx-virtualserver template files](https://github.com/nginxinc/kubernetes-ingress/tree/main/internal/configs/version2) +In the following example we modify `nginx-virtualserver.tmpl` to change the port setting: -Here we modify `nginx-virtualserver.tmpl` to change the port setting: - -``` +```nginx server { listen 80{{ if $s.ProxyProtocol }} proxy_protocol{{ end }}; @@ -44,8 +42,8 @@ server { ``` To change the listen port from `80` to `85`, we modify the `listen` line at the start of the server configuration block. -It would then look like this: -``` +After modifying the line, the file looks like this: +```nginx server { listen 85{{ if $s.ProxyProtocol }} proxy_protocol{{ end }}; @@ -56,19 +54,19 @@ server { set $resource_namespace "{{$s.VSNamespace}}"; ``` -Edit the file you need (per the example above). In my case, I edited, `nginx-plus-virtualserver.tmpl`: +Modify the file you need (per the example above). In the example, we modified `nginx-plus-virtualserver.tmpl`: ## Rebuild your NGINX Ingress controller image -You will need to build your new NGINX Ingress controller image for the new port settings to take affect. +You must build your new NGINX Ingress controller image for the new port settings to take effect. Once the image is built and pushed, make sure you update your deployment to point to the new image and deploy. -Once deployed, create a new `virtualServer` resource and then run `nginx -T` to see if the port takes affect. +Once deployed, create a new `virtualServer` resource and run `nginx -T` to confirm if the port change has taken effect. Ensure that your `deployment` and your `service` match up to the new port you configured in the templates. -Here is simple example of my `deployment` and my `service` matching to the new port that NGINX Ingress controller now listens on. +Below is an example of `deployment` and `service` matching to the new port that NGINX Ingress controller now listens on. -``` +```nginx apiVersion: apps/v1 kind: Deployment metadata: @@ -110,11 +108,11 @@ spec: securityContext: ``` -Notice that now, my `http` port is set to `85`, which reflects the change I made in the template file. +Notice that now, the `http` port is set to `85`, which reflects the change we made in the template file. -Here is my `service` file: +Here is the `service` file: -``` +```nginx apiVersion: v1 kind: Service metadata: @@ -136,18 +134,18 @@ spec: app: nginx-ingress ``` -Since NGINX Ingress controller is now listening on ports 85 and 8443, we modify the `targetPort` in the NGINX Ingress controller service, to match what we have changed in our deployment, to ensure traffic will be sent to the proper port. -The key part above is the `targetPort` section. Since I change NGINX Ingress to listen on port 85, I need to match that in the service. That way, requests will be sent to NGINX Ingress controller on port 85 instead of the default value which is port 80. +Since NGINX Ingress controller is now listening on ports 85 and 8443, we modify the `targetPort` in the NGINX Ingress controller service to match what we have changed in our deployment and ensure traffic will be sent to the proper port. +The key part above is the `targetPort` section. Since we have changed NGINX Ingress to listen on port 85, we need to match that in the service: Requests will be sent to NGINX Ingress controller on port 85 instead of the default value, port 80. -If you view the `NGINX` configuration .conf file using `nginx -T`, you should see the port you defined in the .template file, now is set on the `listen` line. -Here is an example output of the `NGINX` configuration that is now generated: +If you view the `NGINX` configuration .conf file using `nginx -T`, you should see the port you defined in the .template file is now set on the `listen` line. +Here is an example output of the `NGINX` configuration that has been generated: ```bash k exec -it -n nginx-ingress nginx-ingress-54bffd78d9-v7bns -- nginx -T ``` -``` +```nginx server { listen 85; listen [::]:85; From b2e41a60a50f6e9ce6daa3fed19a410e35a33d5e Mon Sep 17 00:00:00 2001 From: Alan Dooley Date: Wed, 21 Jun 2023 12:59:57 +0100 Subject: [PATCH 09/11] Update custom listen ports document for release This commit updates many minor issues with the custom listen ports tutorial, such as the product name and certain formalities around tense and tone. It also fixes some minor formatting issues related to linebreaks to improve the readability of the page. --- docs/content/tutorials/custom-listen-ports.md | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/docs/content/tutorials/custom-listen-ports.md b/docs/content/tutorials/custom-listen-ports.md index 372962070d..1ad913fb9b 100644 --- a/docs/content/tutorials/custom-listen-ports.md +++ b/docs/content/tutorials/custom-listen-ports.md @@ -1,34 +1,31 @@ --- -title: Customze ports for NGINX Ingress Controller +title: Customizing NGINX Ingress Controller Ports description: | - Customze ports for NGINX Ingress Controller + How to customize F5 NGINX Ingress Controller ports. weight: 1800 doctypes: ["concept"] toc: true -docs: "DOCS-1191" --- -## Customizing the `listen` line in NGINX Ingress Controller. - -This document will explain how to change the default ports that NGINX Ingress Controller is configured for, as well as add additional `listen` settings. For more information, please read the [NGINX Listen documentation](http://nginx.org/en/docs/http/ngx_http_core_module.html#listen). +## Customizing NGINX Ingress Controller Ports +This document explains how to change the default ports that NGINX Ingress Controller is configured to use, as well as how to add additional `listen` settings. For more information, please read the [NGINX Listen documentation](http://nginx.org/en/docs/http/ngx_http_core_module.html#listen). ## Changing Default Ports By default, NGINX Ingress Controller listens on ports 80 and 443. These ports can be changed easily, but modifying the `listen` ports for your NGINX Ingress resources will require the editing of .tmpl files. -If you are using `ingress` resource you will need to modify: -- `nginx-plus-ingress.tmpl` if using NGINX Plus -- `nginx-ingress.tmpl` if using NGINX OSS - If you are using NGINX Ingress Controller CRDs (virtualServer): - `nginx-plus-virtualserver.tmpl` for NGINX Plus - `nginx-virtualserver.tmpl` if using NGINX OSS -For this example, we will use the `nginx-virtualserver.tmpl` template to change the port from 80 to 85. -You can find the [nginx-virtualserver template files in our repository](https://github.com/nginxinc/kubernetes-ingress/tree/main/internal/configs/version2). +If you are using `ingress` resource you will need to modify: +- `nginx-plus-ingress.tmpl` if using NGINX Plus +- `nginx-ingress.tmpl` if using NGINX OSS +In this example, we will use the `nginx-virtualserver.tmpl` template to change the port from 80 to 85. +You can find the [nginx-virtualserver template files in our repository](https://github.com/nginxinc/kubernetes-ingress/tree/main/internal/configs/version2). -In the following example we modify `nginx-virtualserver.tmpl` to change the port setting: +We start by modifying `nginx-virtualserver.tmpl` to change the port setting: ```nginx server { @@ -40,9 +37,10 @@ server { set $resource_name "{{$s.VSName}}"; set $resource_namespace "{{$s.VSNamespace}}"; ``` -To change the listen port from `80` to `85`, we modify the `listen` line at the start of the server configuration block. +To change the listen port from `80` to `85`, edit the `listen` line at the start of the server configuration block. + +After changing the number, the file looks like this: -After modifying the line, the file looks like this: ```nginx server { listen 85{{ if $s.ProxyProtocol }} proxy_protocol{{ end }}; @@ -57,14 +55,14 @@ server { Modify the file you need (per the example above). In the example, we modified `nginx-plus-virtualserver.tmpl`: -## Rebuild your NGINX Ingress controller image +## Rebuild the NGINX Ingress Controller image -You must build your new NGINX Ingress controller image for the new port settings to take effect. +You must rebuild the NGINX Ingress Controller image for the new port settings to take effect. Once the image is built and pushed, make sure you update your deployment to point to the new image and deploy. Once deployed, create a new `virtualServer` resource and run `nginx -T` to confirm if the port change has taken effect. Ensure that your `deployment` and your `service` match up to the new port you configured in the templates. -Below is an example of `deployment` and `service` matching to the new port that NGINX Ingress controller now listens on. +Below is an example of `deployment` and `service` matching to the new port that NGINX Ingress Controller now listens on. ```nginx apiVersion: apps/v1 @@ -134,11 +132,12 @@ spec: app: nginx-ingress ``` -Since NGINX Ingress controller is now listening on ports 85 and 8443, we modify the `targetPort` in the NGINX Ingress controller service to match what we have changed in our deployment and ensure traffic will be sent to the proper port. -The key part above is the `targetPort` section. Since we have changed NGINX Ingress to listen on port 85, we need to match that in the service: Requests will be sent to NGINX Ingress controller on port 85 instead of the default value, port 80. +Since NGINX Ingress Controller is now listening on ports 85 and 8443, you must modify the `targetPort` in the NGINX Ingress Controller service to match the change in the deployment to ensure traffic will be sent to the proper port. +The parameter to change above is `targetPort`. Since we have changed NGINX Ingress to listen on port 85, we need to match that in the service: requests will be sent to NGINX Ingress Controller on port 85 instead of the default value, port 80. If you view the `NGINX` configuration .conf file using `nginx -T`, you should see the port you defined in the .template file is now set on the `listen` line. + Here is an example output of the `NGINX` configuration that has been generated: ```bash From 4cbd837f73ac425369f5d79223debbab7b1da489 Mon Sep 17 00:00:00 2001 From: Alan Dooley Date: Thu, 22 Jun 2023 10:52:12 +0100 Subject: [PATCH 10/11] Apply suggestions from code review Co-authored-by: Luca Comellini Signed-off-by: Alan Dooley --- docs/content/tutorials/custom-listen-ports.md | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/content/tutorials/custom-listen-ports.md b/docs/content/tutorials/custom-listen-ports.md index 1ad913fb9b..8e0c15c419 100644 --- a/docs/content/tutorials/custom-listen-ports.md +++ b/docs/content/tutorials/custom-listen-ports.md @@ -12,13 +12,13 @@ This document explains how to change the default ports that NGINX Ingress Contro ## Changing Default Ports -By default, NGINX Ingress Controller listens on ports 80 and 443. These ports can be changed easily, but modifying the `listen` ports for your NGINX Ingress resources will require the editing of .tmpl files. +By default, NGINX Ingress Controller listens on ports 80 and 443. These ports can be changed easily, but modifying the `listen` ports for your NGINX Ingress resources will require the editing of `.tmpl` files. -If you are using NGINX Ingress Controller CRDs (virtualServer): +If you are using NGINX Ingress Controller CRDs (VirtualServer): - `nginx-plus-virtualserver.tmpl` for NGINX Plus - `nginx-virtualserver.tmpl` if using NGINX OSS -If you are using `ingress` resource you will need to modify: +If you are using `Ingress` resource you will need to modify: - `nginx-plus-ingress.tmpl` if using NGINX Plus - `nginx-ingress.tmpl` if using NGINX OSS @@ -59,12 +59,12 @@ Modify the file you need (per the example above). In the example, we modified `n You must rebuild the NGINX Ingress Controller image for the new port settings to take effect. Once the image is built and pushed, make sure you update your deployment to point to the new image and deploy. -Once deployed, create a new `virtualServer` resource and run `nginx -T` to confirm if the port change has taken effect. +Once deployed, create a new `VirtualServer` resource and run `nginx -T` to confirm if the port change has taken effect. -Ensure that your `deployment` and your `service` match up to the new port you configured in the templates. +Ensure that your `Deployment` and your `Service` match up to the new port you configured in the templates. Below is an example of `deployment` and `service` matching to the new port that NGINX Ingress Controller now listens on. -```nginx +```yaml apiVersion: apps/v1 kind: Deployment metadata: @@ -110,7 +110,7 @@ Notice that now, the `http` port is set to `85`, which reflects the change we ma Here is the `service` file: -```nginx +```yaml apiVersion: v1 kind: Service metadata: @@ -134,14 +134,14 @@ spec: Since NGINX Ingress Controller is now listening on ports 85 and 8443, you must modify the `targetPort` in the NGINX Ingress Controller service to match the change in the deployment to ensure traffic will be sent to the proper port. -The parameter to change above is `targetPort`. Since we have changed NGINX Ingress to listen on port 85, we need to match that in the service: requests will be sent to NGINX Ingress Controller on port 85 instead of the default value, port 80. +The parameter to change above is `targetPort`. Since we have changed NGINX Ingress Controller to listen on port 85, we need to match that in the service: requests will be sent to NGINX Ingress Controller on port 85 instead of the default value, port 80. If you view the `NGINX` configuration .conf file using `nginx -T`, you should see the port you defined in the .template file is now set on the `listen` line. Here is an example output of the `NGINX` configuration that has been generated: -```bash -k exec -it -n nginx-ingress nginx-ingress-54bffd78d9-v7bns -- nginx -T +```console +kubectl exec -it -n nginx-ingress nginx-ingress-54bffd78d9-v7bns -- nginx -T ``` ```nginx From 9eb89d72eef30cae4b95f45089ce0d0b45b6a35b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jason=20Williams=20-=20NGI=D0=98X?= Date: Thu, 22 Jun 2023 11:12:19 -0700 Subject: [PATCH 11/11] Update docs/content/tutorials/custom-listen-ports.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Luca Comellini Signed-off-by: Jason Williams - NGIИX --- docs/content/tutorials/custom-listen-ports.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/tutorials/custom-listen-ports.md b/docs/content/tutorials/custom-listen-ports.md index 8e0c15c419..9bf61e8077 100644 --- a/docs/content/tutorials/custom-listen-ports.md +++ b/docs/content/tutorials/custom-listen-ports.md @@ -62,7 +62,7 @@ Once the image is built and pushed, make sure you update your deployment to poin Once deployed, create a new `VirtualServer` resource and run `nginx -T` to confirm if the port change has taken effect. Ensure that your `Deployment` and your `Service` match up to the new port you configured in the templates. -Below is an example of `deployment` and `service` matching to the new port that NGINX Ingress Controller now listens on. +Below is an example of `Deployment` and `Service` matching to the new port that NGINX Ingress Controller now listens on. ```yaml apiVersion: apps/v1