Skip to main content
When you expose a Kubernetes® service in your Managed Service for Kubernetes cluster by using a load balancer, the system automatically creates an allocation with a reserved public IP address and the nebius.com/managed-by: mk8s label. However, if the service is deleted, this allocation is also removed by default. To retain the allocated public IP address and reuse it in future, convert the system-managed allocation into a persistent one and manually link it to your service by using an annotation.

Prerequisites

  1. Make sure you are in a group that has at least the editor role within your tenant; for example, the default editors group. You can check this in the Administration → IAM section of the web console.
  2. Install jq to extract IDs and tokens from the JSON data returned by the Nebius AI Cloud CLI:
    sudo apt-get install jq
    
  3. Create a Managed Service for Kubernetes cluster if you have not done it before.
  4. Install kubectl and connect to the cluster.

How to convert a dynamic IP address

  1. Get the public IP address of your load balancer:
    kubectl get svc nginx
    
    Copy the IP address from the EXTERNAL-IP column.
  2. Get the ID of the allocation associated with the IP address:
    nebius vpc allocation list --format json | jq -r '
      .items[]
      | select(
          .status.details.allocated_cidr == "<external_IP>/32"
          and .metadata.labels["nebius.com/managed-by"] == "mk8s"
        )
      | .metadata.id'
    
    Specify the IP address that you copied in the previous step. Alternatively, list all allocations by using the nebius vpc allocation list command. In the output, look for a block that contains the matching IP address under status.details.allocated_cidr and a labels field containing nebius.com/managed-by: mk8s. Copy the allocation ID. It has the vpcallocation-*** format.
  3. To detach the allocation from automatic deletion, remove system-managed labels of this allocation:
    1. Open the editor to edit the allocation:
      nebius vpc allocation edit <allocation_ID>
      
      Specify the ID that you copied in the previous step. For details on using the edit command, see How to edit resources via the Nebius AI Cloud CLI.
    2. In the editor, delete all labels from the labels list:
      ...
      labels: {}
      ...
      
    3. Save the changes and close the editor.
    Now, the allocation is user-managed, so it will remain even if the associated service is deleted.
  4. Update your Kubernetes load balancer manifest (for example, service.yaml) with the following annotation:
    metadata:
      annotations:
        nebius.com/load-balancer-allocation-id: <allocation_ID>
    
  5. Apply the updated manifest:
    kubectl apply -f service.yaml
    
Now, the public IP allocation is preserved and can be reused if you re-create the service or replace it with another one. For more information, see Load balancers types.