SlideShare a Scribd company logo
Creating an Advanced Load Balancing
Solution for Kubernetes with NGINX
Andrew Hutchings — Technical Product Manager, NGINX, Inc., @LinuxJedi
About LinuxJedi
• Kubernetes user for 4 days
• Worked at HP on OpenStack LBaaS and ATG
• Worked on several Open Source DBs
• Alopecia sufferer
Goals
• Basic and advanced load balancing
• Current load balancing options in Kubernetes
• Ingress resource
• Implementing an Ingress controller for NGINX
• Load balancing demo: exposing Kubernetes services to the Internet
Basic Load Balancing
A load balancer
distributes request
among healthy servers
LB
Server 1 Server 2 Server 3
Basic Load Balancing
HTTPHTTP
Layer 7
TCPTCP UDPUDP
Layer 4
Advanced Load Balancing
• SSL termination
• Active health checks
• Security
• Bandwidth limits
• Logging
• Real-time statistics
• Session Persistence
• Content-based routing
• and more…
Load Balancing in Kubernetes
Internal
• kube-proxy
External
• NodePort
• LoadBalancer
• External IPs
• Service loadbalancer
• Ingress
Internal: Kube-proxy
apiVersion: v1
kind: Service
metadata:
name: backend-service
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: backend
apiVersion: v1
kind: Service
metadata:
name: backend-service
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: backend
# env | grep -i backend
BACKEND_SERVICE_SERVICE_HOST=10.3.246.245
BACKEND_SERVICE_SERVICE_PORT=80
…
# env | grep -i backend
BACKEND_SERVICE_SERVICE_HOST=10.3.246.245
BACKEND_SERVICE_SERVICE_PORT=80
…
# nslookup backend-service
…
Name: backend-service
Address 1: 10.3.246.245
# nslookup backend-service
…
Name: backend-service
Address 1: 10.3.246.245
$ kubectl get svc
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
backend-service 10.3.246.245 <none> 80/TCP app=backend 6m
$ kubectl get svc
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
backend-service 10.3.246.245 <none> 80/TCP app=backend 6m
Internal: Kube-proxy
kube-proxykube-proxy
BB
kube-proxykube-proxy
BB
kube-proxykube-proxy
BB
Features
• TCP/UDP
• Health checks
• Client IP session affinity
External: NodePort
apiVersion: v1
kind: Service
metadata:
name: backend-service
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: backend
apiVersion: v1
kind: Service
metadata:
name: backend-service
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: backend
$ kubectl create -f backend-service-nodeport.yaml
You have exposed your service on an external port on all
nodes in your
cluster. If you want to expose this service to the
external internet, you may
need to set up firewall rules for the service port(s)
(tcp:31107) to serve traffic.
$ kubectl create -f backend-service-nodeport.yaml
You have exposed your service on an external port on all
nodes in your
cluster. If you want to expose this service to the
external internet, you may
need to set up firewall rules for the service port(s)
(tcp:31107) to serve traffic.
External: NodePort
Features
• TCP/UDP
• Health checks
kube-proxykube-proxykube-proxykube-proxy
BB
kube-proxykube-proxy
BB
NodePortNodePort NodePortNodePort NodePortNodePort
BB
External: LoadBalancer
apiVersion: v1
kind: Service
metadata:
name: backend-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: backend
apiVersion: v1
kind: Service
metadata:
name: backend-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: backend
$ kubectl describe svc backend-service
Name: backend-service
Namespace: default
Labels: <none>
Selector: app=backend
Type: LoadBalancer
IP: 10.3.249.155
LoadBalancer Ingress: XXX.YYY.ZZZ.III
Port: <unnamed> 80/TCP
NodePort: <unnamed> 32074/TCP
Endpoints: <none>
Session Affinity: None
$ kubectl describe svc backend-service
Name: backend-service
Namespace: default
Labels: <none>
Selector: app=backend
Type: LoadBalancer
IP: 10.3.249.155
LoadBalancer Ingress: XXX.YYY.ZZZ.III
Port: <unnamed> 80/TCP
NodePort: <unnamed> 32074/TCP
Endpoints: <none>
Session Affinity: None
External: LoadBalancer
Features
• TCP
• Health checks
• Client IP session affinity
(GCE)
kube-proxykube-proxykube-proxykube-proxy
BB
kube-proxykube-proxy
BB
NodePortNodePort NodePortNodePort NodePortNodePort
BB
Cloud
LB
Cloud
LB
External: External IPs
apiVersion: v1
kind: Service
metadata:
name: backend-service
spec:
externalIPs:
- 10.240.0.2
- 10.240.0.3
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: backend
apiVersion: v1
kind: Service
metadata:
name: backend-service
spec:
externalIPs:
- 10.240.0.2
- 10.240.0.3
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: backend
$ kubectl get nodes -o json | grep -A 1 "InternalIP"
"type": "InternalIP",
"address": "10.240.0.2"
--
"type": "InternalIP",
"address": "10.240.0.3"
--
"type": "InternalIP",
"address": "10.240.0.4"
$ kubectl get nodes -o json | grep -A 1 "InternalIP"
"type": "InternalIP",
"address": "10.240.0.2"
--
"type": "InternalIP",
"address": "10.240.0.3"
--
"type": "InternalIP",
"address": "10.240.0.4"
External: External IPs
Features
• TCP/UDP
• Health checks
kube-proxykube-proxykube-proxykube-proxy
BB
kube-proxykube-proxy
BB BB
8080
10.240.0.2 10.240.0.3 10.240.0.4
8080
External: service LoadBalancer
https://github.com/kubernetes/contrib/tree/master/service-loadbalancer
1 or more HAProxy, each deployed
in a pod
Services -> HAProxy configuration
svcA-> /svcA
svcB -> /svcB
Features
• TCP/UDP, HTTP
• URL Mapping
• SSL Termination (via Annotations)
• Session Persistence (via Annotations)
• Multiple algorithms (via Annotations)
External: Ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: hello-ingress
spec:
rules:
- host: hello.example.com
http:
paths:
- path: /a
backend:
serviceName: backend-a
servicePort: 80
- path: /b
backend:
serviceName: backend-b
servicePort: 8080
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: hello-ingress
spec:
rules:
- host: hello.example.com
http:
paths:
- path: /a
backend:
serviceName: backend-a
servicePort: 80
- path: /b
backend:
serviceName: backend-b
servicePort: 8080
• hello.example/a -> backend-a:80
• hello.example/b -> backend-b:8080
External: Ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: hello-ingress
spec:
tls:
- hosts:
- hello.example.com
secretName: hello-secret
rules:
- host: hello.example.com
. . .
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: hello-ingress
spec:
tls:
- hosts:
- hello.example.com
secretName: hello-secret
rules:
- host: hello.example.com
. . .
apiVersion: v1
kind: Secret
metadata:
name: hello-secret
type: Opaque
data:
tls.crt: <base-64 encoded crt>
tls.key: <base-64 encoded key>
apiVersion: v1
kind: Secret
metadata:
name: hello-secret
type: Opaque
data:
tls.crt: <base-64 encoded crt>
tls.key: <base-64 encoded key>
New in 1.2: TLS support
External: Ingress
Features
• HTTP Load Balancing
• SSL Termination
• Content-based routing
How to use it
Ingress Controller must be deployed
External: Ingress
Ingress
Controller
Ingress
Controller
Ingress
Resources
Ingress
Resources
Load BalancerLoad Balancer
watches configures
External: Ingress
Cloud Load Balancers
• GCE HTTP Load Balancer
Software Load Balancers
• NGINX
https://github.com/kubernetes/contrib/tree/master/ingress/controllers
NGINX
• Layer 4/Layer 7 Load Balancer
• Advanced algorithms
• SSL termination
• Content-based routing
• Limits
• HTTP/2 gateway
• Logging
• Security
• Real-time statistics*
• Layer 7 Session Persistence*
• Dynamic reconfiguration*
* NGINX Plus
Also a webserver and cache
NGINX Ingress Controller
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: hello-ingress
spec:
rules:
- host: hello.example.com
http:
paths:
- path: /a
backend:
serviceName: backend-a
servicePort: 80
- path: /b
backend:
serviceName: backend-b
servicePort: 8080
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: hello-ingress
spec:
rules:
- host: hello.example.com
http:
paths:
- path: /a
backend:
serviceName: backend-a
servicePort: 80
- path: /b
backend:
serviceName: backend-b
servicePort: 8080
upstream backend-a {
server 10.3.246.245:80;
}
upstream backend-b {
server 10.3.246.249:8080;
}
server {
listen 80;
server_name hello.example.com;
location /a {
proxy_pass http://backend-a;
}
location /b {
proxy_pass http://backend-b;
}
}
upstream backend-a {
server 10.3.246.245:80;
}
upstream backend-b {
server 10.3.246.249:8080;
}
server {
listen 80;
server_name hello.example.com;
location /a {
proxy_pass http://backend-a;
}
location /b {
proxy_pass http://backend-b;
}
}
NGINX Ingress Controller
1. Watch for Ingress resources
2. Watch for Services and Endpoints: to get IP address of a service or its
endpoints in case of a headless service
3. Watch for Secrets
NGINX Ingress Controller
IngressIngress
EndpointsEndpoints
ServiceService
SecretSecret
IngressIngress
affects
Changes in
1. Regenerate configuration for the
Ingress
2. Reload NGINX
NGINX Ingress Controller
• NGINX Plus supports re-resolving DNS names in runtime every X
seconds
• Doesn’t fail when a name can’t be resolved
• Simplifies implementation: no need to watch for Services and
Endpoints
NGINX Ingress Controller
• As an example we took the GCE HTTP Load Balancer Ingress Controller
—
https://github.com/kubernetes/contrib/tree/master/ingress/controllers/
gce
• Written in Go
• Different implementations for NGINX and NGINX Plus
• Deployed in the same container as NGINX. the Controller starts first and
then launches NGINX.
NGINX Ingress Controller
• HTTP Load Balancing
• SSL Termination
• Content-based routing
Features
• Advanced algorithms
• Limits
• Access Control
• Logging
• Limits Real-time statistics (NGINX Plus)
• Layer 7 Session Persistence (NGINX Plus)
• Dynamic reconfiguration (NGINX Plus)
• and more
Features, supported by changing
NGINX templates
Demo
kube-proxykube-proxykube-proxykube-proxy
TT
kube-proxykube-proxy
CC
80, 44380, 443
BBCC TT
Demo
• tea-rc and tea-svc
• coffee-rc and headless coffee-svc
• Ingress resource cafe-ingress with TLS
• Secret cafe-secret
• NGINX Plus Ingress Controller nginx-plus-ingress-rc
NGINX Ingress Controller
• Expose more NGINX features via
Kubernetes resources (Annotations
and Config Maps)
• Make it production-ready
• Improve it based on your feedback
Wishlist
The End
● Resources: http://tiny.cc/nginx-ingress
● NGINX: https://www.nginx.com/
● My site: http://linuxjedi.co.uk/
● Twitter: @LinuxJedi
● Freenode: LinuxJedi
● Email: linuxjedi@nginx.com

More Related Content

PDF
Load Balancing Applications with NGINX in a CoreOS Cluster
PPTX
Installation Openstack Swift
PDF
KubeCon EU 2016: Kubernetes and the Potential for Higher Level Interfaces
PDF
Kubernetes internals (Kubernetes 해부하기)
KEY
Apache httpd 2.4 Reverse Proxy
ODP
Apache httpd 2.4: The Cloud Killer App
PDF
Kubernetes: Beyond Baby Steps
PDF
Docker 對傳統 DevOps 工具鏈的衝擊 (Docker's Impact on traditional DevOps toolchain)
Load Balancing Applications with NGINX in a CoreOS Cluster
Installation Openstack Swift
KubeCon EU 2016: Kubernetes and the Potential for Higher Level Interfaces
Kubernetes internals (Kubernetes 해부하기)
Apache httpd 2.4 Reverse Proxy
Apache httpd 2.4: The Cloud Killer App
Kubernetes: Beyond Baby Steps
Docker 對傳統 DevOps 工具鏈的衝擊 (Docker's Impact on traditional DevOps toolchain)

What's hot (20)

PDF
Kubernetes the Very Hard Way. Lisa Portland 2019
PPTX
OWASP ZAP Workshop for QA Testers
PPTX
DCUS17 : Docker networking deep dive
PDF
青云虚拟机部署私有Docker Registry
PDF
Web scale infrastructures with kubernetes and flannel
PDF
Kubernetes Networking
PDF
Load Balancing 101
PPTX
Service Discovery using etcd, Consul and Kubernetes
PDF
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
PDF
Head First to Container&Kubernetes
PDF
Heart of the SwarmKit: Store, Topology & Object Model
PDF
Content Caching with NGINX and NGINX Plus
PPTX
KubeCon EU 2016: Multi-Tenant Kubernetes
PPTX
Packet Walk(s) In Kubernetes
PPTX
Monitoring, Logging and Tracing on Kubernetes
PDF
Service Discovery & Load-Balancing under Docker 1.12.0 @ Docker Meetup #22
PDF
From pets to cattle - powered by CoreOS, docker, Mesos & nginx
PPTX
Docker network Present in VietNam DockerDay 2015
PPTX
Docker Networking - Current Status and goals of Experimental Networking
PDF
AstriCon 2017 - Docker Swarm & Asterisk
Kubernetes the Very Hard Way. Lisa Portland 2019
OWASP ZAP Workshop for QA Testers
DCUS17 : Docker networking deep dive
青云虚拟机部署私有Docker Registry
Web scale infrastructures with kubernetes and flannel
Kubernetes Networking
Load Balancing 101
Service Discovery using etcd, Consul and Kubernetes
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
Head First to Container&Kubernetes
Heart of the SwarmKit: Store, Topology & Object Model
Content Caching with NGINX and NGINX Plus
KubeCon EU 2016: Multi-Tenant Kubernetes
Packet Walk(s) In Kubernetes
Monitoring, Logging and Tracing on Kubernetes
Service Discovery & Load-Balancing under Docker 1.12.0 @ Docker Meetup #22
From pets to cattle - powered by CoreOS, docker, Mesos & nginx
Docker network Present in VietNam DockerDay 2015
Docker Networking - Current Status and goals of Experimental Networking
AstriCon 2017 - Docker Swarm & Asterisk
Ad

Viewers also liked (20)

PDF
Kubernetes Mesos Architecture
PPTX
Kubernetes Architecture v1.x
PPTX
Tectonic Summit 2016: Multitenant Data Architectures with Kubernetes
PDF
Kubernetes Workshop
PPTX
Tectonic Summit 2016: Networking for Kubernetes
PDF
Container Network Interface: Network Plugins for Kubernetes and beyond
PDF
Rancher による社内向けテナントサービス基盤
PDF
Load Balancing in the Cloud using Nginx & Kubernetes
PPTX
RancherのWindowsサポートと事始め
PDF
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
PDF
Kubernetes Day 2017 - Build, Ship and Run Your APP, Production !!
PPTX
ICAS 2015 - Rule out the negative side of brain drain - YU Yau Hing
DOCX
Agriculture growth and poverty redection (1)
PPTX
United Arab Emirates, A developed Country
PPTX
31Mar14 - Understanding wellbeing in old age across the world: lessons from a...
PDF
Fisconti tax consulting Netherlands - New Transfer Pricing Documentation Req...
PPTX
Comparative Public Administration ”Discussion on Various Aspects of Develo...
PPTX
India vision 2020
PPTX
India vision 2020 ppt
PPTX
5 Characteristics Of Developing Countries
Kubernetes Mesos Architecture
Kubernetes Architecture v1.x
Tectonic Summit 2016: Multitenant Data Architectures with Kubernetes
Kubernetes Workshop
Tectonic Summit 2016: Networking for Kubernetes
Container Network Interface: Network Plugins for Kubernetes and beyond
Rancher による社内向けテナントサービス基盤
Load Balancing in the Cloud using Nginx & Kubernetes
RancherのWindowsサポートと事始め
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
Kubernetes Day 2017 - Build, Ship and Run Your APP, Production !!
ICAS 2015 - Rule out the negative side of brain drain - YU Yau Hing
Agriculture growth and poverty redection (1)
United Arab Emirates, A developed Country
31Mar14 - Understanding wellbeing in old age across the world: lessons from a...
Fisconti tax consulting Netherlands - New Transfer Pricing Documentation Req...
Comparative Public Administration ”Discussion on Various Aspects of Develo...
India vision 2020
India vision 2020 ppt
5 Characteristics Of Developing Countries
Ad

Similar to KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes with NGINX (20)

PDF
Kuberntes Ingress with Kong
PDF
Extending kubernetes
PPTX
Introduction to Kubernetes
PDF
ОЛЕКСАНДР ЛИПКО «Graceful Shutdown Node.js + k8s» Online WDDay 2021
PDF
Canadian CNCF: "Emissary-ingress 101: An introduction to the CNCF incubation-...
PDF
Ports, pods and proxies
PPTX
Orchestration with Kubernetes
PPTX
Scaling Kubernetes to Support 50000 Services.pptx
PDF
Load Balancing Applications on Kubernetes with NGINX
PPTX
What’s New in NGINX Ingress Controller for Kubernetes Release 1.5.0
PPTX
F5 Meetup presentation automation 2017
PDF
Istio Playground
PDF
Kubernetes on AWS
PDF
Kubernetes on AWS
PPTX
NGINX Plus R20 Webinar
PDF
Scale Kubernetes to support 50000 services
PDF
Evolution of kube-proxy (Brussels, Fosdem 2020)
PPTX
What’s New in NGINX Plus R16?
PPTX
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
PPTX
Harmonia open iris_basic_v0.1
Kuberntes Ingress with Kong
Extending kubernetes
Introduction to Kubernetes
ОЛЕКСАНДР ЛИПКО «Graceful Shutdown Node.js + k8s» Online WDDay 2021
Canadian CNCF: "Emissary-ingress 101: An introduction to the CNCF incubation-...
Ports, pods and proxies
Orchestration with Kubernetes
Scaling Kubernetes to Support 50000 Services.pptx
Load Balancing Applications on Kubernetes with NGINX
What’s New in NGINX Ingress Controller for Kubernetes Release 1.5.0
F5 Meetup presentation automation 2017
Istio Playground
Kubernetes on AWS
Kubernetes on AWS
NGINX Plus R20 Webinar
Scale Kubernetes to support 50000 services
Evolution of kube-proxy (Brussels, Fosdem 2020)
What’s New in NGINX Plus R16?
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
Harmonia open iris_basic_v0.1

More from KubeAcademy (20)

PDF
KubeCon EU 2016: Distributed containers in the physical world
PDF
KubeCon EU 2016:
PDF
KubeCon EU 2016: ChatOps and Automatic Deployment on Kubernetes
PDF
KubeCon EU 2016: A Practical Guide to Container Scheduling
PDF
KubeCon EU 2016: Trading in the Kube
ODP
KubeCon EU 2016: Integrated trusted computing in Kubernetes
PDF
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
PPTX
KubeCon EU 2016: Secure, Cloud-Native Networking with Project Calico
PDF
KubeCon EU 2016: Heroku to Kubernetes
PPTX
KubeCon EU 2016: Transforming the Government
PDF
KubeCon EU 2016: Getting the Jobs Done With Kubernetes
PDF
KubeCon EU 2016: Kubernetes Storage 101
PDF
KubeCon EU 2016: Using Traffic Control to Test Apps in Kubernetes
PDF
KubeCon EU 2016: Kubernetes in Production in The New York Times newsroom
PDF
KubeCon EU 2016: ITNW (If This Now What): Orchestrating an Enterprise
PDF
KubeCon EU 2016: SmartCity IoT on Kubernetes
PDF
KubeCon EU 2016: Templatized Application Configuration on OpenShift and Kuber...
PDF
KubeCon EU 2016 Keynote: Pushing Kubernetes Forward
PDF
KubeCon EU 2016: Killing containers to make weather beautiful
PDF
KubeCon EU 2016: Bringing an open source Containerized Container Platform to ...
KubeCon EU 2016: Distributed containers in the physical world
KubeCon EU 2016:
KubeCon EU 2016: ChatOps and Automatic Deployment on Kubernetes
KubeCon EU 2016: A Practical Guide to Container Scheduling
KubeCon EU 2016: Trading in the Kube
KubeCon EU 2016: Integrated trusted computing in Kubernetes
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
KubeCon EU 2016: Secure, Cloud-Native Networking with Project Calico
KubeCon EU 2016: Heroku to Kubernetes
KubeCon EU 2016: Transforming the Government
KubeCon EU 2016: Getting the Jobs Done With Kubernetes
KubeCon EU 2016: Kubernetes Storage 101
KubeCon EU 2016: Using Traffic Control to Test Apps in Kubernetes
KubeCon EU 2016: Kubernetes in Production in The New York Times newsroom
KubeCon EU 2016: ITNW (If This Now What): Orchestrating an Enterprise
KubeCon EU 2016: SmartCity IoT on Kubernetes
KubeCon EU 2016: Templatized Application Configuration on OpenShift and Kuber...
KubeCon EU 2016 Keynote: Pushing Kubernetes Forward
KubeCon EU 2016: Killing containers to make weather beautiful
KubeCon EU 2016: Bringing an open source Containerized Container Platform to ...

Recently uploaded (20)

DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
KodekX | Application Modernization Development
PDF
Advanced IT Governance
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
cuic standard and advanced reporting.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
The AUB Centre for AI in Media Proposal.docx
Review of recent advances in non-invasive hemoglobin estimation
NewMind AI Monthly Chronicles - July 2025
KodekX | Application Modernization Development
Advanced IT Governance
Chapter 3 Spatial Domain Image Processing.pdf
Advanced Soft Computing BINUS July 2025.pdf
Empathic Computing: Creating Shared Understanding
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
cuic standard and advanced reporting.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Reach Out and Touch Someone: Haptics and Empathic Computing
MYSQL Presentation for SQL database connectivity
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Advanced methodologies resolving dimensionality complications for autism neur...
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
20250228 LYD VKU AI Blended-Learning.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...

KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes with NGINX

  • 1. Creating an Advanced Load Balancing Solution for Kubernetes with NGINX Andrew Hutchings — Technical Product Manager, NGINX, Inc., @LinuxJedi
  • 2. About LinuxJedi • Kubernetes user for 4 days • Worked at HP on OpenStack LBaaS and ATG • Worked on several Open Source DBs • Alopecia sufferer
  • 3. Goals • Basic and advanced load balancing • Current load balancing options in Kubernetes • Ingress resource • Implementing an Ingress controller for NGINX • Load balancing demo: exposing Kubernetes services to the Internet
  • 4. Basic Load Balancing A load balancer distributes request among healthy servers LB Server 1 Server 2 Server 3
  • 5. Basic Load Balancing HTTPHTTP Layer 7 TCPTCP UDPUDP Layer 4
  • 6. Advanced Load Balancing • SSL termination • Active health checks • Security • Bandwidth limits • Logging • Real-time statistics • Session Persistence • Content-based routing • and more…
  • 7. Load Balancing in Kubernetes Internal • kube-proxy External • NodePort • LoadBalancer • External IPs • Service loadbalancer • Ingress
  • 8. Internal: Kube-proxy apiVersion: v1 kind: Service metadata: name: backend-service spec: ports: - port: 80 targetPort: 80 protocol: TCP selector: app: backend apiVersion: v1 kind: Service metadata: name: backend-service spec: ports: - port: 80 targetPort: 80 protocol: TCP selector: app: backend # env | grep -i backend BACKEND_SERVICE_SERVICE_HOST=10.3.246.245 BACKEND_SERVICE_SERVICE_PORT=80 … # env | grep -i backend BACKEND_SERVICE_SERVICE_HOST=10.3.246.245 BACKEND_SERVICE_SERVICE_PORT=80 … # nslookup backend-service … Name: backend-service Address 1: 10.3.246.245 # nslookup backend-service … Name: backend-service Address 1: 10.3.246.245 $ kubectl get svc NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE backend-service 10.3.246.245 <none> 80/TCP app=backend 6m $ kubectl get svc NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE backend-service 10.3.246.245 <none> 80/TCP app=backend 6m
  • 10. External: NodePort apiVersion: v1 kind: Service metadata: name: backend-service spec: type: NodePort ports: - port: 80 targetPort: 80 protocol: TCP selector: app: backend apiVersion: v1 kind: Service metadata: name: backend-service spec: type: NodePort ports: - port: 80 targetPort: 80 protocol: TCP selector: app: backend $ kubectl create -f backend-service-nodeport.yaml You have exposed your service on an external port on all nodes in your cluster. If you want to expose this service to the external internet, you may need to set up firewall rules for the service port(s) (tcp:31107) to serve traffic. $ kubectl create -f backend-service-nodeport.yaml You have exposed your service on an external port on all nodes in your cluster. If you want to expose this service to the external internet, you may need to set up firewall rules for the service port(s) (tcp:31107) to serve traffic.
  • 11. External: NodePort Features • TCP/UDP • Health checks kube-proxykube-proxykube-proxykube-proxy BB kube-proxykube-proxy BB NodePortNodePort NodePortNodePort NodePortNodePort BB
  • 12. External: LoadBalancer apiVersion: v1 kind: Service metadata: name: backend-service spec: type: LoadBalancer ports: - port: 80 targetPort: 80 protocol: TCP selector: app: backend apiVersion: v1 kind: Service metadata: name: backend-service spec: type: LoadBalancer ports: - port: 80 targetPort: 80 protocol: TCP selector: app: backend $ kubectl describe svc backend-service Name: backend-service Namespace: default Labels: <none> Selector: app=backend Type: LoadBalancer IP: 10.3.249.155 LoadBalancer Ingress: XXX.YYY.ZZZ.III Port: <unnamed> 80/TCP NodePort: <unnamed> 32074/TCP Endpoints: <none> Session Affinity: None $ kubectl describe svc backend-service Name: backend-service Namespace: default Labels: <none> Selector: app=backend Type: LoadBalancer IP: 10.3.249.155 LoadBalancer Ingress: XXX.YYY.ZZZ.III Port: <unnamed> 80/TCP NodePort: <unnamed> 32074/TCP Endpoints: <none> Session Affinity: None
  • 13. External: LoadBalancer Features • TCP • Health checks • Client IP session affinity (GCE) kube-proxykube-proxykube-proxykube-proxy BB kube-proxykube-proxy BB NodePortNodePort NodePortNodePort NodePortNodePort BB Cloud LB Cloud LB
  • 14. External: External IPs apiVersion: v1 kind: Service metadata: name: backend-service spec: externalIPs: - 10.240.0.2 - 10.240.0.3 ports: - port: 80 targetPort: 80 protocol: TCP selector: app: backend apiVersion: v1 kind: Service metadata: name: backend-service spec: externalIPs: - 10.240.0.2 - 10.240.0.3 ports: - port: 80 targetPort: 80 protocol: TCP selector: app: backend $ kubectl get nodes -o json | grep -A 1 "InternalIP" "type": "InternalIP", "address": "10.240.0.2" -- "type": "InternalIP", "address": "10.240.0.3" -- "type": "InternalIP", "address": "10.240.0.4" $ kubectl get nodes -o json | grep -A 1 "InternalIP" "type": "InternalIP", "address": "10.240.0.2" -- "type": "InternalIP", "address": "10.240.0.3" -- "type": "InternalIP", "address": "10.240.0.4"
  • 15. External: External IPs Features • TCP/UDP • Health checks kube-proxykube-proxykube-proxykube-proxy BB kube-proxykube-proxy BB BB 8080 10.240.0.2 10.240.0.3 10.240.0.4 8080
  • 16. External: service LoadBalancer https://github.com/kubernetes/contrib/tree/master/service-loadbalancer 1 or more HAProxy, each deployed in a pod Services -> HAProxy configuration svcA-> /svcA svcB -> /svcB Features • TCP/UDP, HTTP • URL Mapping • SSL Termination (via Annotations) • Session Persistence (via Annotations) • Multiple algorithms (via Annotations)
  • 17. External: Ingress apiVersion: extensions/v1beta1 kind: Ingress metadata: name: hello-ingress spec: rules: - host: hello.example.com http: paths: - path: /a backend: serviceName: backend-a servicePort: 80 - path: /b backend: serviceName: backend-b servicePort: 8080 apiVersion: extensions/v1beta1 kind: Ingress metadata: name: hello-ingress spec: rules: - host: hello.example.com http: paths: - path: /a backend: serviceName: backend-a servicePort: 80 - path: /b backend: serviceName: backend-b servicePort: 8080 • hello.example/a -> backend-a:80 • hello.example/b -> backend-b:8080
  • 18. External: Ingress apiVersion: extensions/v1beta1 kind: Ingress metadata: name: hello-ingress spec: tls: - hosts: - hello.example.com secretName: hello-secret rules: - host: hello.example.com . . . apiVersion: extensions/v1beta1 kind: Ingress metadata: name: hello-ingress spec: tls: - hosts: - hello.example.com secretName: hello-secret rules: - host: hello.example.com . . . apiVersion: v1 kind: Secret metadata: name: hello-secret type: Opaque data: tls.crt: <base-64 encoded crt> tls.key: <base-64 encoded key> apiVersion: v1 kind: Secret metadata: name: hello-secret type: Opaque data: tls.crt: <base-64 encoded crt> tls.key: <base-64 encoded key> New in 1.2: TLS support
  • 19. External: Ingress Features • HTTP Load Balancing • SSL Termination • Content-based routing How to use it Ingress Controller must be deployed
  • 21. External: Ingress Cloud Load Balancers • GCE HTTP Load Balancer Software Load Balancers • NGINX https://github.com/kubernetes/contrib/tree/master/ingress/controllers
  • 22. NGINX • Layer 4/Layer 7 Load Balancer • Advanced algorithms • SSL termination • Content-based routing • Limits • HTTP/2 gateway • Logging • Security • Real-time statistics* • Layer 7 Session Persistence* • Dynamic reconfiguration* * NGINX Plus Also a webserver and cache
  • 23. NGINX Ingress Controller apiVersion: extensions/v1beta1 kind: Ingress metadata: name: hello-ingress spec: rules: - host: hello.example.com http: paths: - path: /a backend: serviceName: backend-a servicePort: 80 - path: /b backend: serviceName: backend-b servicePort: 8080 apiVersion: extensions/v1beta1 kind: Ingress metadata: name: hello-ingress spec: rules: - host: hello.example.com http: paths: - path: /a backend: serviceName: backend-a servicePort: 80 - path: /b backend: serviceName: backend-b servicePort: 8080 upstream backend-a { server 10.3.246.245:80; } upstream backend-b { server 10.3.246.249:8080; } server { listen 80; server_name hello.example.com; location /a { proxy_pass http://backend-a; } location /b { proxy_pass http://backend-b; } } upstream backend-a { server 10.3.246.245:80; } upstream backend-b { server 10.3.246.249:8080; } server { listen 80; server_name hello.example.com; location /a { proxy_pass http://backend-a; } location /b { proxy_pass http://backend-b; } }
  • 24. NGINX Ingress Controller 1. Watch for Ingress resources 2. Watch for Services and Endpoints: to get IP address of a service or its endpoints in case of a headless service 3. Watch for Secrets
  • 26. NGINX Ingress Controller • NGINX Plus supports re-resolving DNS names in runtime every X seconds • Doesn’t fail when a name can’t be resolved • Simplifies implementation: no need to watch for Services and Endpoints
  • 27. NGINX Ingress Controller • As an example we took the GCE HTTP Load Balancer Ingress Controller — https://github.com/kubernetes/contrib/tree/master/ingress/controllers/ gce • Written in Go • Different implementations for NGINX and NGINX Plus • Deployed in the same container as NGINX. the Controller starts first and then launches NGINX.
  • 28. NGINX Ingress Controller • HTTP Load Balancing • SSL Termination • Content-based routing Features • Advanced algorithms • Limits • Access Control • Logging • Limits Real-time statistics (NGINX Plus) • Layer 7 Session Persistence (NGINX Plus) • Dynamic reconfiguration (NGINX Plus) • and more Features, supported by changing NGINX templates
  • 30. Demo • tea-rc and tea-svc • coffee-rc and headless coffee-svc • Ingress resource cafe-ingress with TLS • Secret cafe-secret • NGINX Plus Ingress Controller nginx-plus-ingress-rc
  • 31. NGINX Ingress Controller • Expose more NGINX features via Kubernetes resources (Annotations and Config Maps) • Make it production-ready • Improve it based on your feedback Wishlist
  • 32. The End ● Resources: http://tiny.cc/nginx-ingress ● NGINX: https://www.nginx.com/ ● My site: http://linuxjedi.co.uk/ ● Twitter: @LinuxJedi ● Freenode: LinuxJedi ● Email: [email protected]