advanced ingress for your kubernetes apps with nginx · ingress load balancing on kubernetes nginx...

39
Advanced Ingress for Your Kubernetes Apps with NGINX by Michael Pleshakov Software Engineer, F5 Networks

Upload: others

Post on 04-Jun-2020

62 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Advanced Ingress for Your Kubernetes Apps with NGINX

by Michael Pleshakov

Software Engineer, F5 Networks

Page 2: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Agenda

Ingress load balancing on Kubernetes

NGINX Ingress Controller

Kubernetes Ingress resource

NGINX Ingress resources

Demos

Page 3: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Running a Web Application on Kubernetes

3

Run 2 replicas of application pod

Deployment

Make app pods

discoverable

Service

Expose service to clients via L7 load balancer (proxy)

Ingress

L7 LB

app

app app

app

app

service app

app app

pods app app

L7 load balancer (proxy)

L7 LB

Clients

app service

Page 4: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Ingress Resource

4

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: cafe-ingress spec: rules: - host: webapp.example.com http: paths: - path: / backend: serviceName: webapp servicePort: 80

app app

app

L7 LB

Page 5: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

L7 LB

app app

app IC

Ingress Controller

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: cafe-ingress . . .

k8s API

1. Get Ingress from Kubernetes API

1

2. Configure L7 Load Balancer

2

3. Repeat (go to Step 1)

Page 6: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

NGINX Ingress Controller

IC

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: cafe-ingress . . .

app app

app

k8s API

L3/L4 LB

IC

Page 7: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Ingress Controller Purpose

Ingress Controller General Purpose

Provide external HTTP load balancing for applications running in a cluster

NGINX Ingress Controller Purpose

Provide external HTTP load balancing for applications running in a cluster…

…securely, reliably and with high performance through NGINX/NGINX Plus

To be 'k8s-native', integrating well with the ecosystem and using familiar configuration and processes

Page 9: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Demo 1

Ingress resource

Page 10: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Limitations of Ingress

• Ingress features

• Cross-namespace configuration

Page 11: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Limitations of Ingress – Features

11

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: webapp spec: tls: - hosts: - webapp.example.com secretName: webapp-secret rules: - host: webapp.example.com http: paths: - path: / backend: serviceName: webapp servicePort: 80

- host-based routing

Features

- TLS termination

- path-based routing

Page 12: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Ingress Annotations

12

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: webapp annotations: nginx.org/lb-method: "ip_hash" spec: rules: - host: webapp.example.com http: paths: - path: / backend: serviceName: webapp servicePort: 80

Page 13: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Good/Bad Things about Annotations

13

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: webapp annotations: nginx.org/lb-method: "ip_hash" spec: rules: - host: webapp.example.com http: paths: - path: / backend: serviceName: webapp servicePort: 80

Implement features missing in the Ingress spec

Good Things:

Page 14: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Good/Bad Things about Annotations

14

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: webapp annotations: nginx.org/lb-method: "ip_hash" nginx.org/ssl-services: "webapp" nginx.org/proxy-connect-timeout: "10s" nginx.org/proxy-read-timeout: "10s" nginx.org/proxy-send-timeout: "10s" nginx.org/rewrites: "serviceName=webapp rewrite=/v1" nginx.com/jwt-key: "webapp-jwk" nginx.com/jwt-realm: "Webb App" nginx.com/jwt-token: "$cookie_auth_token" nginx.com/jwt-login-url: "https://login.example.com"" spec: rules: - host: webapp.example.com . . .

Implement features missing in Ingress spec

Lack validation

Not suited for granular configuration

Good Things:

Can quickly grow bigger than the spec

Bad Things:

Not portable

Page 15: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Limitations of Ingress

• Ingress features

• Cross-namespace configuration

Page 16: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Limitations of Ingress – Cross-namespace Configuration

16

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: cafe-ingress spec: rules: - host: cafe.example.com http: paths: - path: /coffee backend: serviceName: coffee servicePort: 80 - path: /tea backend: serviceName: tea servicePort: 80

coffee

coffee

tea

coffee

tea

tea

tea

Namespace coffee

Namespace tea

Page 17: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Mergeable Ingresses for Cross-namespace Configuration

17

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: cafe-ingress spec: rules: - host: cafe.example.com http: paths: - path: /coffee backend: serviceName: coffee servicePort: 80 - path: /tea backend: serviceName: tea servicePort: 80

coffee

coffee

tea

coffee

tea

tea

tea

Namespace coffee

Namespace tea

Page 18: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Mergeable Master

18

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: cafe-ingress spec: rules: - host: cafe.example.com http: paths: - path: /coffee backend: serviceName: coffee servicePort: 80 - path: /tea backend: serviceName: tea servicePort: 80

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: cafe-ingress-master namespace: cafe annotations: nginx.org/mergeable-ingress-type: "master" spec: rules: - host: cafe.example.com

Page 19: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Mergeable Minion

19

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: cafe-ingress spec: rules: - host: cafe.example.com http: paths: - path: /coffee backend: serviceName: coffee servicePort: 80 - path: /tea backend: serviceName: tea servicePort: 80

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: cafe-ingress-coffee-minion namespace: coffee annotations: nginx.org/mergeable-ingress-type: "minion" spec: rules: - host: cafe.example.com http: paths: - path: /coffee backend: serviceName: coffee-svc servicePort: 80

Page 20: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Mergeable Minion

20

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: cafe-ingress spec: rules: - host: cafe.example.com http: paths: - path: /coffee backend: serviceName: coffee servicePort: 80 - path: /tea backend: serviceName: tea servicePort: 80

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: cafe-ingress-tea-minion namespace: tea annotations: nginx.org/mergeable-ingress-type: "minion" spec: rules: - host: cafe.example.com http: paths: - path: /tea backend: serviceName: tea-svc servicePort: 80

Page 21: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Mergeable Ingresses for Cross-namespace Configuration

21

Master ingress for cafe.example.com in ns cafe

coffee coffee

tea

coffee

tea

tea

tea

Namespace coffee

Namespace tea Minion ingress for cafe.example.com/tea

in ns tea

Minion ingress for cafe.example.com/coffee in ns coffee

Namespace cafe

Page 22: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Limitations of Ingress

• Ingress features

• Cross-namespace configuration

Page 23: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Can We do Better?

23

Then Ingress resource with a lot of annotations

Provide external HTTP load balancing for applications running in a cluster…

…securely, reliably and with high performance through NGINX/NGINX Plus

To be 'k8s-native', integrating well with the ecosystem and using familiar configuration and processes

Page 24: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Goals for the NGINX Ingress Resources

24

Provide features without relying on annotations

Support cross-namespace configuration

Page 25: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

VirtualServer Resource

25

apiVersion: k8s.nginx.org/v1 kind: VirtualServer metadata: name: webapp spec: host: webapp.example.com tls: secret: webapp-secret upstreams: - name: webapp service: webapp port: 80 routes: - path: / action: pass: webapp

Page 26: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

VirtualServer / Ingress Resources

26

apiVersion: k8s.nginx.org/v1 kind: VirtualServer metadata: name: webapp spec: host: webapp.example.com tls: secret: webapp-secret upstreams: - name: webapp service: webapp port: 80 routes: - path: / action: path: webapp

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: webapp spec: tls: - hosts: - webapp.example.com secretName: webapp-secret rules: - host: webapp.example.com http: paths: - path: / backend: serviceName: webapp servicePort: 80

Page 27: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Demo 3

VirtualServer Resource

Page 28: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Load Balancing

28

upstreams: - name: webapp service: webapp port: 80 lb-method: ip_hash - name: coffee service: coffee-svc port: 80 lb-method: least_conn

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: webapp annotations: nginx.org/lb-method: "ip_hash" spec: rules: - host: webapp.example.com http: paths: - path: / backend: serviceName: webapp servicePort: 80

Page 29: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Traffic Splitting

29

upstreams: - name: webapp-v1 service: webapp-v1 port: 80 - name: webapp-v2 service: webapp-v2 port: 80 routes: - path: / splits: - weight: 90 action: pass: webapp-v1 - weight: 10 action: pass: webapp-v2

v1

v2

90%

10%

Page 30: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Advanced Routing

30

upstreams: - name: webapp-v1 service: webapp-v1 port: 80 - name: webapp-v2 service: webapp-v2 port: 80 routes: - path: / matches: - conditions: - cookie: version value: v2 action: pass: webapp-v2 action: pass: webapp-v1

v1

v2

Cookie: version=v2

Page 31: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Demo 4

VirtualServer with traffic shifting and advanced request routing

Page 32: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Cross-namespace Configuration

32

apiVersion: k8s.nginx.org/v1 kind: VirtualServer metadata: name: cafe namespace: cafe spec: host: cafe.example.com tls: secret: cafe-secret routes: - path: /coffee route: coffee/coffee - path: /tea route: tea/tea

coffee coffee

tea

coffee

tea

tea

tea

Namespace coffee

Namespace tea

Namespace cafe

Page 33: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Cross-namespace Configuration - VirtualServerRoute

33

apiVersion: k8s.nginx.org/v1 kind: VirtualServerRoute metadata: name: coffee namespace: coffee spec: host: cafe.example.com upstreams: - name: coffee service: coffee-svc port: 80 subroutes: - path: /coffee action: pass: coffee

coffee coffee

coffee

Namespace coffee

Page 34: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Cross-namespace Configuration - VirtualServerRoute

34

apiVersion: k8s.nginx.org/v1 kind: VirtualServerRoute metadata: name: tea namespace: tea spec: host: cafe.example.com upstreams: - name: tea service: tea-svc port: 80 subroutes: - path: /tea action: pass: tea

tea

tea

tea

tea

Namespace tea

Page 35: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Cross-namespace Configuration

35

VirtualServer for cafe.example.com in ns café, /coffee -> VSR coffee in ns coffee /tea -> VSR tea in ns tea

coffee coffee

tea

coffee

tea

tea

tea

Namespace coffee

Namespace tea VirtualServerRoute for cafe.example.com/tea

in ns tea

VirtualServerRoute for cafe.example.com/coffee in ns tea

Namespace cafe

Page 36: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Summary of NGINX Ingress Resources

36

Based on Custom resources

Supports advanced features missing in the Kubernetes Ingress resource

Supports cross-namespace configuration missing in the Kubernetes Ingress resource

Page 37: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Multiple Protocols

apiVersion: k8s.nginx.org/v1alpha1 kind: TCPServer metadata: name: simple-tcp spec: port: 1234 upstreams: - name: tcp-app service: tcp-app-svc port: 2001 action: pass: tcp-app

apiVersion: k8s.nginx.org/v1alpha1 kind: TLSPassthroughServer metadata: name: example spec: host: myapp.example.com upstreams: - name: my-tls-app service: my-tls-app-svc port: 443 action: pass: my-tls-app

TCP TLS Passthrough

Page 38: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

Next for NGINX Ingress Resources

• Support TCP/UDP and TLS Passthrough

• Support Polices – request/response manipulations, auth, rate-limiting, WAF

Page 39: Advanced Ingress for Your Kubernetes Apps with NGINX · Ingress load balancing on Kubernetes NGINX Ingress Controller Kubernetes Ingress resource NGINX Ingress resources Demos . Running

The End

Try out NGINX Ingress Controller

NGINX Ingress Controller: https://github.com/nginxinc/kubernetes-ingress

Examples:

https://github.com/nginxinc/kubernetes-ingress/tree/master/examples-of-custom-resources