Support Online
Skip to main content

Adding Load Balancer to Kubernetes Clusters

Kubernetes clusters offer load balancer support along with high availability, auto-scaling, and storage integrations. It is also compatible with standard Kubernetes toolchains (kubectl, API & CLI).

Note:

The load balancer service directs traffic to all worker nodes in the cluster. However, only nodes configured to accept traffic undergo health checks.
This is normal even if other nodes seem to fail.

1. Creating or Updating a Configuration File

You can create a new service configuration file to add an external load balancer to the cluster. For example:

kind: Service
apiVersion: v1
metadata:
name: tcp-lb
spec:
type: LoadBalancer
selector:
app: nginx-example
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80

If you have an existing service file, you can define a load balancer by simply adding the following lines:

spec:
type: LoadBalancer
selector:
app: nginx-example
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80

Configuring Load Balancer Settings

When creating a load balancer, you can specify the number of nodes and firewall rules in the configuration file.

Number of Nodes

The number of nodes a load balancer has determines how many connections it can maintain simultaneously.

  • More nodes provide more connection capacity and high availability.
  • The default number of nodes is 1.
  • The number of nodes can be an integer between 1 and 200.
  • The maximum node limit on your account depends on your account settings.

You can contact the Support Team to request a higher limit.

Defining Number of Nodes

size unit annotation is used to specify the number of nodes when creating a load balancer. Example usage in the service file is as follows:

apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
type: LoadBalancer
selector:
app: nginx-example
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80

Load Balancer Firewall Rules

Once a load balancer is created, resizing can be done once per minute.

You can define firewall rules to control load balancer access.

  • You can determine which IP addresses can connect with the LoadBalancerSourceRanges field.
  • You can block unwanted IP blocks with deny-list annotation.

In the example configuration below:

  • 198.51.100.0/16 IP block blocked,
  • Connections from IP addresses 203.0.113.24 and 203.0.113.68 are allowed.
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
type: LoadBalancer
selector:
app: nginx-example
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
loadBalancerSourceRanges:
- 203.0.113.24/32
- 203.0.113.68/32

Billing begins when the load balancer creation process is completed.

You can make additional load balancer settings using the annotations in the service configuration file. For example, you can add an internal load balancer or specify health checks.

Viewing Load Balancers

After applying the configuration file to a deployment, you can see the load balancer in the Resources tab of your cluster in the control panel.

Alternatively, you can use this command to see the load balancer status:

kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 192.0.2.1 <none> 443/TCP 2h
sample-load-balancer LoadBalancer 192.0.2.167 <pending> 80:32490/TCP 6s

When the load balancer creation process is complete, the external IP address appears in the EXTERNAL-IP column instead of <pending>.
In the PORT(S) column, the first port (80) is the incoming traffic port and the second port (32490) is the node port. This is not the container port specified in the targetPort parameter.

⚠️ Warning

In addition to the Resources tab of the cluster; worker nodes, load balancers, and disks (volumes) are also listed except on the Kubernetes page.

If you rename or change these resources via the control panel:

  • They may become unusable by the cluster,
  • Or reconcilers can create new resources.

To avoid this, manage cluster resources only via the kubectl command or the control panel's Kubernetes page.

Viewing Details of a Single Load Balancer

To get detailed information about a particular load balancer, you can use the following command:

kubectl describe service <LB-İSİM>
Name: sample-load-balancer
Namespace: default
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"sample-load-balancer","namespace":"default"},"spec":{"ports":[{"name":"https",...
Selector: <none>
Type: LoadBalancer
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.245.178.117
IPs: 10.245.178.117
LoadBalancer Ingress: 203.0.113.86
Port: https 80/TCP
TargetPort: 443/TCP
NodePort: https 32490/TCP
Endpoints: <none>
Session Affinity: None
External Traffic Policy: Cluster
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal EnsuringLoadBalancer 3m (x2 over 38m) service-controller Ensuring load balancer
Normal EnsuredLoadBalancer 1m (x2 over 37m) service-controller Ensured load balancer