I create a deployment which results in 4 pods existing across 2 nodes.
I then expose these pods via a service which results in the following cluster IP and pod endpoints:
Name: s-flask ...... IP: 10.110.201.8 Port: <unset> 9080/TCP TargetPort: 5000/TCP NodePort: <unset> 30817/TCP Endpoints: 192.168.251.131:5000,192.168.251.132:5000,192.168.251.134:5000 + 1 more...
If accessing the service internally via the cluster IP, the requests are balanced across both nodes and all pods, not just the pods on a single node (e.g. like access via a nodePort).
I know kubernetes uses IP tables to balance requests across pods on a single node, but I can't find any documentation which explains how kubernetes balances internal service requests across multiple nodes (we are don't use load balancers or ingress for internal service load balancing).
The cluster IP itself is virtual, the only way I think this can work, is if the cluster IP is round robin mapped to a service endpoint IP address, where the client would have to look up the cluster IP / service and select an endpoint IP?
This kind of algorithm works by monitoring changes in response latency as the load adjusts based on server capacity. The Kubernetes load balancer sends connections to the first server in the pool until it is at capacity, and then sends new connections to the next available server.
The ClusterIP provides a load-balanced IP address. One or more pods that match a label selector can forward traffic to the IP address. The ClusterIP service must define one or more ports to listen on with target ports to forward TCP/UDP traffic to containers.
Kubernetes gives Pods their own IP addresses and a single DNS name for a set of Pods, and can load-balance across them.
The Kubernetes Service interworks with a group of pods in the downlink direction to implement load balancing among the pods. This provides a central endpoint for service discovery and enables access to the external network and access among different pods through the same address.
The clusterIp value must be a valid IP address within the range configured for your cluster. This is defined by the service-cluster-ip-range setting in the Kubernetes API server. A NodePort publicly exposes a service on a fixed port number. It lets you access the service from outside your cluster.
In a Kubernetes cluster you may need to use the following network scenarios: connections from Pod to a Service — is provided by the Service abstraction, for example — ClusterIP connections from the world to pods in a cluster — is provided by the Service abstraction, with an external resource, for example — AWS Load Balancer
Internal Load Balancing to balance the traffic across the containers having the same. In Kubernetes, the most basic Load Balancing is for load distribution which can be done at the dispatch level. This can be done by kube-proxy, which manages the virtual IPs assigned to services.
It lets you access the service from outside your cluster. You’ll need to use the cluster’s IP address and the NodePort number—e.g. 123.123.123.123:30000. Creating a NodePort will open that port on every node in your cluster. Kubernetes will automatically route port traffic to the service it’s linked to.
Everything you need is explained in second paragraph "Virtual IPs and service proxies" of this documentation: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service
In nutshell: currently, depending on the proxy mode, for ClusterIP it's just round robin/random. It's done by kube-proxy, which runs on each nodes, proxies UDP and TCP and provides load balancing.
It's better to think of kubernetes as a whole rather than specific nodes. Abstraction does its thing here.
Hope it answers your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With