liveBook · Manning

Loadbalancer service

As explained in Kubernetes in Action, Second Edition

The LoadBalancer service type requests an externally accessible load balancer for a Kubernetes Service from the cluster's cloud infrastructure.

A LoadBalancer service makes an application reachable through an external load balancer. Kubernetes creates the Service, but the cluster’s infrastructure must provide the load balancer. Once provisioned, its address appears as the Service’s EXTERNAL-IP. The Service still has an internal cluster IP. section 3.3.2 section 3.4

Expose a Deployment

Run `kubectl expose deployment kiada --type=LoadBalancer --port 8080`, then check `kubectl get svc kiada`. EXTERNAL-IP may initially show `<pending>` while provisioning takes place. When an address appears, a client can request the application at that address and port—for example, `curl 35.246.179.22:8080`. section 3.3.2

A LoadBalancer service extends NodePort: the external load balancer sends connections to a node port on a healthy node, and the Service routes them to its backing pods. Unlike a ClusterIP service, it can serve clients outside the cluster without requiring you to set up that load balancer manually. Support depends on the environment: cloud clusters commonly provide it, while on-premises clusters may need an add-on such as MetalLB. Without support, the Service can still exist but remains accessible only through its node ports. section 11.2 section 11.2.2

Listing 11.4 A LoadBalancer-type service
apiVersion: v1
kind: Service
metadata:
  name: kiada
spec:
  type: LoadBalancer     #1
  selector:
    app: kiada
  ports:
  - name: http
    port: 80
    nodePort: 30080
    targetPort: 8080
  - name: https
    port: 443
    nodePort: 30443
    targetPort: 8443

A Service manifest selects the application’s pods and sets `type: LoadBalancer`. Its `nodePort` values are explicit here, but they can be omitted if their exact numbers do not matter. section 11.2.2

To change an existing Service, apply an updated manifest rather than deleting and recreating it; this preserves its internal cluster IP. Where supported, additional fields can select a load-balancer class, request an IP, restrict client source ranges, or control node-port allocation. section 11.2.2

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains provisioning, node-port routing, a Service manifest, and configuration fields, while leaving load-balancer implementation to the infrastructure.
Examples
Shows a kubectl exposure command, pending and assigned EXTERNAL-IP output, a curl request, and a YAML Service manifest.
What it assumes
Builds on the distinction between ClusterIP and NodePort services while explaining how LoadBalancer extends NodePort.
What you can do after
Operate/configure it with kubectl or a Service manifest, inspect EXTERNAL-IP, and connect through the assigned address.
How it connects
Connects LoadBalancer services to ClusterIP, NodePort, pods, cloud infrastructure, and MetalLB.

Also explained in

Compare how 5 books explain loadbalancer service →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.