Kubernetes Networking Intro & Deep Dive
Kubernetes Networking Intro & Deep Dive
- service mesh
- multi cluster networking: service discovery, load balancing, security
- api gateway
a b
a b
Overlay network
Node A Node B
A B a b
A B a b
physical network
overlay pod networking (contd..)
● VXLAN, IP-IP, GRE tunneling
● Useful when you don't want to expose pod traffic to physical network
● Cloud provider does not allow encapsulated traffic
● Pod traffic gets dropped due to anti-spoofing policies (AWS src-dst checks)
● Overhead due to encapsulation
direct routing pod networking
Pod a Pod b
a b
a b
Node A Node B
route table route table
b node B a node A
a b a b
physical network
direct routing pod networking (contd ..)
Pod a Pod b
a b
a b
Node A bgp
Node B bgp
Route advertisement
a b a b
L3 routed network
direct routing pod networking (contd ..)
● No overhead due to encapsulation
● Suitable for on-prem clusters
● Direct access to the pod from outside the cluster
● Can achieve massive scale
● Fits naturally for multi-cluster scenarios
native VPC/cloud networking
Vpc router
Node 1 pod1 pod2
subnet1
subnet2
native VPC/cloud networking (contd..)
● Pods are first class citizen
● Can use all services like ELB/ALB etc in case of AWS
● Treated same as VM instance
Network API resources
● Service, Endpoints, EndpointSlices
● Ingress
● NetworkPolicy
Lets see how in-cluster service-to-service talk
services: problem
Pod 1
Pod 2
Client
?
pod
Pod 3
Pod 1
client connects to abstract service
Pod 2
Client
pod service
Pod 3
Pod 4
my-service.default.svc.cluster.local
Service
pod proxy
Pod 3
node
Pod 4
Client
connects to Proxy
connects to Serving app
VIP
serving pod
Endpoint, endpointslices
● Represents the list of live pod IPs “behind” a Service
● Generally managed by system
● Out of band changes to achieve service reflection, VM’s etc
service: control plane
DNS
Service controller
Endpoints controller
node
● Service controller watches for service objects allocated cluster IP, Nodeport etc
● End points manager keeps endpoitns upto date
● DNS server updates records for the service
● Node proxy watches service, endpoints and configures to reflect desired state
services: nifty features
● Services without a pod selector
○ Reflect services in other clusters, or external services
○ Endpoint object should reflect the correct IP’s or service VIP
● Services without a pod selector but with ExternalName
○ Services of type ExternalName map a Service to a DNS nam
● Headless services
How external clients access in-cluster services
Service types
● ClusterIP
● NodePort
● LoadBalancer
● ExternalName
● Services with external IP configured
NodePort
Pod a Pod c
1.1.1.2 1.1.2.2
client :40001 :40001
Src: client
Dst: 10.1.1.2 (node1) Node 1 Node 2
10.1.1.2 10.1.1.2
Src: 10.1.12
Dst: 1.1.2.3
NodePort (contd...)
With externalTrafficPolicy=local
Pod a Pod c
1.1.1.2 1.1.2.2
client :40001 :40001
Src: client
Dst: 10.1.1.2 (node1) Node 1 Node 2
Src: client
10.1.1.2
Dst: 1.1.1.2 10.1.1.2
NodePort (contd...)
● No special/external infrastructure requirements
● Can’t use arbitrary/well known port
● Client has to pick a node
● Without externalTrafficPolicy=true we lose source IP
● Two hops
● With externalTrafficPolicy=true client has to pick a node with service pods
LoadBalancer with cloud provider LB
Cloud load balancer
Pod a Pod c
1.1.1.2 1.1.2.2
client VIP :40001 :40001
Node 1 Node 2
10.1.1.2 10.1.1.2
Src: 10.1.12
Dst: 1.1.2.3
Src: client Src: client
Dst: VIP:port Dst: 10.1.1.2:40001
LoadBalancer with cloud provider LB
Cloud load balancer
Pod a Pod c
1.1.1.2 1.1.2.2
client VIP :40001 :40001
Node 1 Node 2
10.1.1.2 10.1.1.2
vip vip
Pod a Pod c
Src: client 1.1.1.2 1.1.2.2
Dst: 1.1.1.2:port bgp bgp
Pod a Pod d
1.1.1.3 1.1.2.3
client L3 routers
VIP is configured on
Src: client single node that
Dst: vip:port responds to ARP
vip
Pod a Pod c
Src: client 1.1.1.2 1.1.2.2
Dst: 1.1.1.2:port
Pod a Pod d
1.1.1.3 1.1.2.3
firewall firewall
Check is made if
Check is made if pod can receive
pod can send traffic from
traffic to backend fronent pod
pod2 Change is picked up
by each node and
necessary
netfilter/bpf rules etc User applies network
API server policy with egress &
are setup
ingress rule to permit
traffic from frontend pods
to back end pods
ingress
● API object that manages external access to the services in a cluster, typically
HTTP
● exposes HTTP and HTTPS routes from outside the cluster to services within
the cluster
● Ingress does not expose arbitrary ports or protocols uses uses a service of
type Service.Type=NodePort or Service.Type=LoadBalancer
● Describes HTTP proxy and routing rules
● Targets service for each rule
ingress
API gateway
● api gateway is used for application routing, rate limiting, security, request and
response handling and other application related tasks
● Overlaps some of the functionalities with ingress controllers
● Kong, ambassador, AWS api gateway etc
service mesh
With current Kubernetes networking lacks
Istio
● Automatic load balancing for HTTP, gRPC, WebSocket, and TCP traffic.
● Fine-grained control of traffic behavior with rich routing rules, retries, failovers, and fault injection.
● A pluggable policy layer and configuration API supporting access controls, rate limits and quotas.
● Automatic metrics, logs, and traces for all traffic within a cluster, including cluster ingress and egress.
● Secure service-to-service communication in a cluster with strong identity-based authentication and authorization.
conceptual networking model - multi cluster
Multi cloud and hybrid
thanks