-
Couldn't load subscription status.
- Fork 2k
support namespaced upstream service #8453
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
Open
haywoodsh
wants to merge
12
commits into
main
Choose a base branch
from
feat/support-foreign-upstreams
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,125
−62
Open
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
01217bd
support namespaced upstream service
haywoodsh 3bee7d6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b1b9514
add example and fix comments
haywoodsh f23f0a4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0aa24da
update readme
haywoodsh 836e03c
handle exception
haywoodsh 3efca90
Merge branch 'main' into feat/support-foreign-upstreams
haywoodsh 2c59b84
Remove the commented-out code
haywoodsh d72e9b5
typo
haywoodsh eeddabe
Merge branch 'main' into feat/support-foreign-upstreams
haywoodsh 3c274c9
update docs
haywoodsh 4d9b240
Merge branch 'main' into feat/support-foreign-upstreams
haywoodsh 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
107 changes: 107 additions & 0 deletions
107
examples/custom-resources/foreign-namespace-upstreams/README.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,107 @@ | ||
| # Upstreams in foreign namespaces | ||
|
|
||
| In this example we use the [VirtualServer and | ||
| VirtualServerRoute](https://docs.nginx.com/nginx-ingress-controller/configuration/virtualserver-and-virtualserverroute-resources/) | ||
| resources to configure load balancing for the modified cafe application from the [Basic | ||
| Configuration](../basic-configuration/) example. We have put the load balancing configuration as well as the deployments | ||
| and services into multiple namespaces. Instead of one namespace, we now use three: `tea`, `coffee`, and `cafe`. | ||
|
|
||
| - In the tea namespace, we create the tea deployment and service. | ||
| - In the coffee namespace, we create the coffee deployment and service. | ||
| - In the cafe namespace, we create the cafe secret with the TLS certificate and key and the load-balancing configuration | ||
| for the cafe application. That configuration references the coffee and tea configurations. | ||
|
|
||
| ## 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. | ||
| 1. Save the public IP address of the Ingress Controller into a shell variable: | ||
|
|
||
| ```console | ||
| IC_IP=XXX.YYY.ZZZ.III | ||
| ``` | ||
|
|
||
| 1. Save the HTTPS port of the Ingress Controller into a shell variable: | ||
|
|
||
| ```console | ||
| IC_HTTPS_PORT=<port number> | ||
| ``` | ||
|
|
||
| ## Step 1 - Create Namespaces | ||
|
|
||
| Create the required tea, coffee, and cafe namespaces: | ||
|
|
||
| ```console | ||
| kubectl create -f namespaces.yaml | ||
| ``` | ||
|
|
||
| ## Step 2 - Deploy the Cafe Application | ||
|
|
||
| 1. Create the tea deployment and service in the tea namespace: | ||
|
|
||
| ```console | ||
| kubectl create -f tea.yaml | ||
| ``` | ||
|
|
||
| 1. Create the coffee deployment and service in the coffee namespace: | ||
|
|
||
| ```console | ||
| kubectl create -f coffee.yaml | ||
| ``` | ||
|
|
||
| ## Step 3 - Configure Load Balancing and TLS Termination | ||
|
|
||
| 1. Create the secret with the TLS certificate and key in the cafe namespace: | ||
|
|
||
| ```console | ||
| kubectl create -f cafe-secret.yaml | ||
| ``` | ||
|
|
||
| 1. Create the VirtualServer resource for the cafe app in the cafe namespace: | ||
|
|
||
| ```console | ||
| kubectl create -f cafe-virtual-server.yaml | ||
| ``` | ||
|
|
||
| ## Step 4 - Test the Configuration | ||
|
|
||
| 1. Check that the configuration has been successfully applied by inspecting the events of the VirtualServer: | ||
|
|
||
| ```console | ||
| kubectl describe virtualserver cafe -n cafe | ||
| ``` | ||
|
|
||
| ```text | ||
| . . . | ||
| Events: | ||
| Type Reason Age From Message | ||
| ---- ------ ---- ---- ------- | ||
| Normal AddedOrUpdated 1m nginx-ingress-controller Configuration for cafe/cafe was added or updated | ||
| ``` | ||
|
|
||
| 1. Access the application using curl. We'll use curl's `--insecure` option to turn off certificate verification of our | ||
| self-signed certificate and `--resolve` option to set the IP address and HTTPS port of the Ingress Controller to the | ||
| domain name of the cafe application: | ||
|
|
||
| To get coffee: | ||
|
|
||
| ```console | ||
| curl --resolve cafe.example.com:$IC_HTTPS_PORT:$IC_IP https://cafe.example.com:$IC_HTTPS_PORT/coffee --insecure | ||
| ``` | ||
|
|
||
| ```text | ||
| Server address: 10.16.1.193:80 | ||
| Server name: coffee-7dbb5795f6-mltpf | ||
| ... | ||
| ``` | ||
|
|
||
| If your prefer tea: | ||
|
|
||
| ```console | ||
| curl --resolve cafe.example.com:$IC_HTTPS_PORT:$IC_IP https://cafe.example.com:$IC_HTTPS_PORT/tea --insecure | ||
| ``` | ||
|
|
||
| ```text | ||
| Server address: 10.16.0.157:80 | ||
| Server name: tea-7d57856c44-674b8 | ||
| ... | ||
1 change: 1 addition & 0 deletions
1
examples/custom-resources/foreign-namespace-upstreams/cafe-secret.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 @@ | ||
| ../../common-secrets/cafe-secret-cafe-ns.example.com.yaml |
23 changes: 23 additions & 0 deletions
23
examples/custom-resources/foreign-namespace-upstreams/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,23 @@ | ||
| apiVersion: k8s.nginx.org/v1 | ||
| kind: VirtualServer | ||
| metadata: | ||
| name: cafe | ||
| namespace: cafe | ||
| spec: | ||
| host: cafe.example.com | ||
| tls: | ||
| secret: cafe-secret | ||
| routes: | ||
| - path: /coffee | ||
| action: | ||
| pass: coffee | ||
| - path: /tea | ||
| action: | ||
| pass: tea | ||
| upstreams: | ||
| - name: coffee | ||
| service: coffee/coffee-svc | ||
| port: 80 | ||
| - name: tea | ||
| service: tea/tea-svc | ||
| port: 80 |
70 changes: 70 additions & 0 deletions
70
examples/custom-resources/foreign-namespace-upstreams/coffee.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,70 @@ | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: coffee | ||
| namespace: coffee | ||
| spec: | ||
| replicas: 3 | ||
| 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 | ||
| namespace: coffee | ||
| spec: | ||
| ports: | ||
| - port: 80 | ||
| targetPort: 8080 | ||
| protocol: TCP | ||
| name: http | ||
| selector: | ||
| app: coffee | ||
|
|
||
| --- | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: coffee | ||
| namespace: coffee2 | ||
| spec: | ||
| replicas: 3 | ||
| 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 | ||
| namespace: coffee2 | ||
| spec: | ||
| ports: | ||
| - port: 80 | ||
| targetPort: 8080 | ||
| protocol: TCP | ||
| name: http | ||
| selector: | ||
| app: coffee |
14 changes: 14 additions & 0 deletions
14
examples/custom-resources/foreign-namespace-upstreams/namespaces.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: v1 | ||
| kind: Namespace | ||
| metadata: | ||
| name: cafe | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Namespace | ||
| metadata: | ||
| name: tea | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Namespace | ||
| metadata: | ||
| name: coffee |
34 changes: 34 additions & 0 deletions
34
examples/custom-resources/foreign-namespace-upstreams/tea.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,34 @@ | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: tea | ||
| namespace: 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 | ||
| namespace: tea | ||
| spec: | ||
| ports: | ||
| - port: 80 | ||
| targetPort: 8080 | ||
| protocol: TCP | ||
| name: http | ||
| selector: | ||
| app: tea |
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.
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.