Skip to content

Instantly share code, notes, and snippets.

@nginx-gists
Last active November 11, 2022 00:21
Show Gist options
  • Save nginx-gists/00ae3b715c657e5b8891a3837438748a to your computer and use it in GitHub Desktop.
Save nginx-gists/00ae3b715c657e5b8891a3837438748a to your computer and use it in GitHub Desktop.
Enabling Multi-Tenancy and Namespace Isolation in Kubernetes with NGINX
apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
name: bookinfo
namespace: A
spec:
host: a.bookinfo.com
upstreams:
- name: productpageA
service: productpageA
port: 9080
routes:
- path: /
action:
pass: productpageA
apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
name: bookinfo
namespace: B
spec:
host: b.bookinfo.com
upstreams:
- name: productpageB
service: productpageB
port: 9080
routes:
- path: /
action:
pass: productpageB
apiVersion: k8s.nginx.org/v1
kind: Policy
metadata:
name: okta-oidc-policy
spec:
oidc:
clientID: <client_id>
clientSecret: okta-oidc-secret
authEndpoint: https://<your_okta_domain>/oauth2/v1/authorize
tokenEndpoint: https://<your_okta_domain>/oauth2/v1/token
jwksURI: https://<your_okta_domain>/oauth2/v1/keys
apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
name: bookinfo-vs
spec:
host: bookinfo.example.com
tls:
secret: bookinfo-secret
upstreams:
- name: backend
service: productpage
port: 9080
routes:
- path: /
policies:
- name: okta-oidc-policy
action:
pass: backend
apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
name: example
spec:
host: bookinfo.example.com
routes:
- path: /productpage-A
route: A/ingress
- path: /productpage-B
route: B/ingress
apiVersion: k8s.nginx.org/v1
kind: VirtualServerRoute
metadata:
name: ingress
namespace: A
spec:
host: bookinfo.example.com
upstreams:
- name: productpageA
service: productpageA-svc
port: 9080
subroutes:
- path: /productpage-A
action:
pass: productpageA
apiVersion: k8s.nginx.org/v1
kind: VirtualServerRoute
metadata:
name: ingress
namespace: B
spec:
host: bookinfo.example.com
upstreams:
- name: productpageB
service: productpageB-svc
port: 9080
subroutes:
- path: /productpage-B
action:
pass: productpageB
@nginx-gists
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment