Last active
June 22, 2022 03:23
-
-
Save chenweienn/e92e256418ce3c0c5c6871193a05385b to your computer and use it in GitHub Desktop.
Test NSX native support for k8s ingress.
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 sample app is from NCP (NSX Container Plug-in) project. | |
| ## https://gitlab.eng.vmware.com/core-build/nsx-ujo/-/tree/master/doc/source/devref/samples/ingress | |
| ## NCP ingress Doc: | |
| ## https://docs.vmware.com/en/VMware-NSX-T-Data-Center/3.2/ncp-kubernetes/GUID-E03D6EE5-9C6C-457F-AD81-25CF2056F4D8.html | |
| (1) tea app | |
| cat > tea-svc.yaml << EOF | |
| apiVersion: v1 | |
| kind: Service | |
| metadata: | |
| name: tea-svc | |
| labels: | |
| app: tea | |
| spec: | |
| ports: | |
| - port: 80 | |
| targetPort: 80 | |
| protocol: TCP | |
| name: http | |
| selector: | |
| app: tea | |
| EOF | |
| cat > tea-deployment.yml << EOF | |
| apiVersion: apps/v1 | |
| kind: Deployment | |
| metadata: | |
| name: tea-deployment | |
| spec: | |
| selector: | |
| matchLabels: | |
| app: tea | |
| replicas: 2 | |
| template: | |
| metadata: | |
| labels: | |
| app: tea | |
| spec: | |
| containers: | |
| - name: tea | |
| image: projects.registry.vmware.com/ncp/nginxdemos/hello:plain-text | |
| ports: | |
| - containerPort: 80 | |
| EOF | |
| (2) coffee app | |
| cat > coffee-svc.yml << EOF | |
| apiVersion: v1 | |
| kind: Service | |
| metadata: | |
| name: coffee-svc | |
| labels: | |
| app: coffee | |
| spec: | |
| ports: | |
| - port: 80 | |
| targetPort: 80 | |
| protocol: TCP | |
| name: http | |
| selector: | |
| app: coffee | |
| EOF | |
| cat > coffee-deployment.yml << EOF | |
| apiVersion: apps/v1 | |
| kind: Deployment | |
| metadata: | |
| name: coffee-deployment | |
| spec: | |
| selector: | |
| matchLabels: | |
| app: coffee | |
| replicas: 2 | |
| template: | |
| metadata: | |
| labels: | |
| app: coffee | |
| spec: | |
| containers: | |
| - name: coffee | |
| image: projects.registry.vmware.com/ncp/nginxdemos/hello:plain-text | |
| ports: | |
| - containerPort: 80 | |
| EOF | |
| (3) samlpe ingress | |
| cat > cafe-ingress-nsx.yml << EOF | |
| apiVersion: networking.k8s.io/v1 | |
| kind: Ingress | |
| metadata: | |
| name: cafe-ingress | |
| #Ingress will be handled by native nsx ingress controller | |
| annotations: | |
| kubernetes.io/ingress.class: "nsx" | |
| spec: | |
| rules: | |
| - host: cafe.example.com | |
| http: | |
| paths: | |
| - path: /tea | |
| pathType: ImplementationSpecific | |
| backend: | |
| service: | |
| name: tea-svc | |
| port: | |
| number: 80 | |
| - path: /coffee | |
| pathType: ImplementationSpecific | |
| backend: | |
| service: | |
| name: coffee-svc | |
| port: | |
| number: 80 | |
| EOF | |
| (4) rewrite url ingress | |
| cat > cafe-ingress-rewrite.yml << EOF | |
| apiVersion: networking.k8s.io/v1 | |
| kind: Ingress | |
| metadata: | |
| name: cafe-ingress-rewrite | |
| annotations: | |
| kubernetes.io/ingress.class: "nsx" | |
| ncp/use-regex: "True" | |
| #/tea/cup will be rewritten to /cup before sending request to tea-svc:80 | |
| ingress.kubernetes.io/rewrite-target: /\$1 | |
| spec: | |
| rules: | |
| - host: cafe-rewrite.example.com | |
| http: | |
| paths: | |
| - path: /tea/(.*) | |
| pathType: ImplementationSpecific | |
| backend: | |
| service: | |
| name: tea-svc | |
| port: | |
| number: 80 | |
| - path: /coffee/(.*) | |
| pathType: ImplementationSpecific | |
| backend: | |
| service: | |
| name: coffee-svc | |
| port: | |
| number: 80 | |
| EOF | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment