Skip to main content
You can expose a Kubernetes service in your Managed Service for Kubernetes cluster using a load balancer. The load balancer receives traffic on a public or private IP address, depending on how you set it up, and distributes the traffic between the service’s pods automatically.
Requirements to connect to a VM with private IP addressTo connect to a Managed Service for Kubernetes cluster from a Compute VM using a private IP address or another cluster using a private load balancer, both must be in the same region and subnet.

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, add nebius.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.
If you have created an IP address allocation (example for public IP addresses) and want to use it to allocate an IP address to a load balancer, add its ID to the service annotation nebius.com/load-balancer-allocation-id. The allocation type (public or private) must match the load balancer type. The table below explains how these two annotations work together:
Type is internalAllocation ID is setResult
YesYesLoad balancer gets a private IP address from the provided allocation
YesNoLoad balancer gets a private IP address from a new allocation
NoYesLoad balancer gets a public IP address from the provided allocation
NoNoLoad balancer gets a public IP address from a new allocation

How to set up a load balancer

  1. 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):
    apiVersion: v1
    kind: Service
    metadata:
      name: nginx
      annotations:
        nebius.com/load-balancer-type: "internal"
    spec:
      selector:
        app: nginx
      ports:
        - protocol: TCP
          port: 80
          targetPort: 80
      type: LoadBalancer
    
  2. Create the manifest for nginx deployment (we will refer to it later as deployment.yaml):
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-deployment
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:latest
            ports:
            - containerPort: 80
    
  3. Apply the configurations:
    kubectl apply -f deployment.yaml
    kubectl apply -f service.yaml
    
  4. Check the service and the allocated IP address:
    kubectl get svc nginx
    
    You will receive an output like the one below:
    NAME         TYPE           CLUSTER-IP       EXTERNAL-IP     PORT(S)        AGE
    nginx        LoadBalancer   10.158.250.188   192.168.0.112   80:30512/TCP   4s