0
0
KubernetesConceptBeginner · 3 min read

LoadBalancer Service in Kubernetes: What It Is and How It Works

A LoadBalancer service in Kubernetes exposes your application to the internet by provisioning an external IP address that routes traffic to your pods. It acts like a traffic manager that balances incoming requests across multiple pods automatically.
⚙️

How It Works

Imagine you have a popular website and many people want to visit it at the same time. A LoadBalancer service in Kubernetes works like a receptionist who directs visitors to different rooms (pods) so no single room gets too crowded. It creates an external IP address that users can access from outside the cluster.

When a request comes to this external IP, the LoadBalancer forwards it to one of the pods running your application inside the cluster. This spreading out of requests helps keep your app fast and reliable, even when many users visit at once.

The actual external IP and routing are handled by your cloud provider (like AWS, GCP, or Azure), which creates a real load balancer outside Kubernetes and connects it to your service.

💻

Example

This example shows a simple Kubernetes service of type LoadBalancer that exposes a web app running on port 80.

yaml
apiVersion: v1
kind: Service
metadata:
  name: my-webapp-service
spec:
  type: LoadBalancer
  selector:
    app: my-webapp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
Output
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE my-webapp-service LoadBalancer 10.0.0.123 34.68.194.12 80:32456/TCP 2m
🎯

When to Use

Use a LoadBalancer service when you want to make your Kubernetes app accessible from the internet or an external network. It is perfect for web apps, APIs, or any service that needs a stable public IP address.

For example, if you deploy a website or a customer-facing API, a LoadBalancer service lets users connect easily without needing extra setup. It also helps distribute traffic evenly to keep your app responsive.

Note that this requires a cloud environment that supports external load balancers, so it is commonly used with managed Kubernetes services like Google Kubernetes Engine, Amazon EKS, or Azure AKS.

Key Points

  • LoadBalancer service creates an external IP to expose your app.
  • It balances traffic across pods automatically.
  • Depends on cloud provider support for external load balancers.
  • Ideal for public-facing applications needing stable IPs.
  • Simple to configure with a few YAML lines.

Key Takeaways

A LoadBalancer service exposes your Kubernetes app with an external IP for internet access.
It automatically distributes incoming traffic across multiple pods to keep your app stable.
Requires cloud provider support to create the external load balancer.
Best used for public-facing apps like websites and APIs needing a fixed IP.
Configuring a LoadBalancer service is simple with a few lines of YAML.