Prerequisites
Before you start setting up a load balancer, you need to create a Managed Kubernetes cluster and connect to it using kubectl.Load balancers types
By default, load balancers are created with public IP addresses. To expose your service on a private IP address instead, addnebius.com/load-balancer-type: internal to the annotations of the service.
To retain an IP address that was automatically allocated to a load balancer and reuse it after deleting or recreating the service, follow the How to convert a dynamically assigned public IP address to a reusable allocation guide.
nebius.com/load-balancer-allocation-id. The allocation type (public or private) must match the load balancer type.
The load balancer listener is created in the control plane subnet of the cluster. The allocation that you specify in nebius.com/load-balancer-allocation-id must belong to this subnet.
The table below explains how these two annotations work together:
To allocate a public IP address from a specific IP pool, add the pool ID to the
nebius.com/load-balancer-pool-id service annotation. When this annotation is set, the IP address is allocated from the specified pool instead of the default user subnet pool. For more information about IP pools, see the Virtual Networks overview.
Limitations
-
Managed Service for Kubernetes doesn’t support load balancer services that set
externalTrafficPolicytoLocal. - Load balancers don’t support PROXY protocol v1 or v2. There is no service annotation to enable it.
How to set up a load balancer
- With a private IP address
- With a public IP address
-
Create the manifest to set up the internal load balancer service with a private IP address (we will refer to it later as
service.yaml): -
Create the manifest for nginx deployment (we will refer to it later as
deployment.yaml): -
Apply the configurations:
-
Check the service and the allocated IP address:
You will receive an output like the one below:
How to restrict access to a load balancer
To allow traffic only from selected sources, use either a security group in Virtual Networks or theloadBalancerSourceRanges parameter in the Service specification.
If you use both of them, the security group rules are applied first and take precedence. Traffic that is denied by the security group never reaches Cilium that manages networking in the cluster and is installed by default. Traffic that is allowed by the security group is then checked against loadBalancerSourceRanges.
However, to avoid conflicting allowlists, specify them in either the security group rules or in loadBalancerSourceRanges.
Using a security group
The security group rules are enforced at the network interface level of nodes before Cilium processes the traffic. To restrict access to a load balancer by using a security group:- Create a security group. The security group must belong to the same network as the cluster.
-
Add security rules. These should be stateful ingress
ALLOWrules for every protocol and port exposed by the Service. In each rule, specify the source CIDR blocks that should have access. -
Add the
nebius.com/load-balancer-security-group-idannotation to the Service manifest:You can assign only one security group to a load balancer. -
Apply the updated manifest:
Adding the loadBalancerSourceRanges parameter
TheloadBalancerSourceRanges parameter in the Service spec object defines the CIDR blocks that can access the load balancer. Cilium then applies this restriction.
To restrict access to a load balancer by using the loadBalancerSourceRanges parameter:
-
Add the allowed CIDR blocks to this parameter:
-
Apply the updated manifest: