> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nebius.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuring a Managed Service for Kubernetes® cluster to work in NVIDIA® Run:ai

To optimize your AI and ML workloads, you can use the [Run:ai](https://www.nvidia.com/en-us/software/run-ai/) management platform. It dynamically allocates GPU resources, prevents idle GPUs, and enables GPU sharing across multiple workloads and users to make full use of available resources. In this tutorial, you will install Run:ai on a Managed Service for Kubernetes cluster and configure the deployment by using the NVIDIA Run:ai installer.

> [!TIP]
>
> You can also [deploy Run:ai from the Applications marketplace](https://console.eu-north1.nebius.com/applications/nvidia-run-ai) to get started with minimal manual setup. The application provides a Nebius public endpoint, so you don't need to configure your own domain, DNS, ingress controller, or TLS certificates. Follow this tutorial if you need to configure these manually.

This tutorial is based on Run:ai installer version `3.0.20`. This version is open-source and doesn't require registry credentials. For NVIDIA's paid Support-Entitled Release, see its [registry credentials instructions](https://docs.nvidia.com/run-ai/self-hosted/documentation/installation-and-configuration/install/guided-installation/connected-installation/preparations#registry-credentials).

## Costs

Nebius AI Cloud charges you for the following billing items:

* [Managed Kubernetes cluster](https://docs.nebius.com/kubernetes/resources/pricing.md).
* [Shared filesystem](https://docs.nebius.com/compute/resources/pricing.md#shared-filesystems).
* [Object Storage bucket](https://docs.nebius.com/object-storage/resources/pricing.md) for Terraform state.
* [Managed Service for PostgreSQL® cluster](https://docs.nebius.com/postgresql/resources/pricing.md) if you use it instead of the PostgreSQL 16 database that the Run:ai installer deploys.

## Prerequisites

1. Make sure that you are in a [group](https://docs.nebius.com/iam/authorization/groups/index.md) that has at least the `admin` role within your tenant
   ; for example, the default `admins` group.
   You can check this in the [Administration → IAM](https://console.nebius.com/iam) section of the web console.

2. Install and configure the tools:

   1. [Install and configure](https://docs.nebius.com/cli/install.md) the Nebius AI Cloud CLI.

   2. [Install Terraform](https://developer.hashicorp.com/terraform/install).

   3. [Install kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl) and [Helm](https://helm.sh/docs/intro/install/) version 3.14 or higher.

   4. Install [jq](https://jqlang.github.io/jq/), which the k8s-training solution's environment script uses to parse JSON data returned by the Nebius AI Cloud CLI:

      ```bash Ubuntu theme={null}
      sudo apt-get install jq
      ```

      ```bash macOS theme={null}
      brew install jq
      ```

3. Prepare a domain name you control with access to its public DNS records.

## Steps

### Set up a Managed Kubernetes cluster

Use the [k8s-training solution](https://github.com/nebius/nebius-solution-library/tree/main/k8s-training) for Terraform to create a Managed Kubernetes cluster with:

* A CPU node group with three nodes, each with 8 vCPUs and 32 GiB of RAM.
* A GPU node group with one node. The solution selects the GPU platform and preset for your region.
* A shared filesystem mounted on the nodes.
* NVIDIA GPU Operator.
* NVIDIA Network Operator.

The nodes use private IP addresses.

1. Clone the solution repository and go to the `k8s-training` directory:

   ```bash theme={null}
   git clone https://github.com/nebius/nebius-solution-library.git
   cd nebius-solution-library/k8s-training
   ```

2. Generate an [SSH key pair](https://docs.nebius.com/compute/virtual-machines/ssh-keys.md).

3. Create `terraform.tfvars` with the following configuration:

   ```hcl theme={null}
   cluster_name  = "k8s-training"
   ssh_user_name = "ubuntu"
   ssh_public_key = {
     path = "~/.ssh/id_ed25519.pub"
   }

   cpu_nodes_fixed_count = 3
   cpu_nodes_preset      = "8vcpu-32gb"

   gpu_node_groups                 = 1
   gpu_nodes_fixed_count_per_group = 1
   gpu_nodes_driverfull_image      = false

   enable_filestore              = true
   filestore_disk_size_gibibytes = 100

   enable_grafana    = false
   enable_prometheus = false
   loki = {
     enabled = false
   }
   ```

   This configuration creates three CPU nodes with 8 vCPUs and 32 GiB of RAM each, one GPU node, and a mounted 100 GiB shared filesystem. It also enables GPU Operator to manage the GPU driver and Container Toolkit.

4. Create `runai_override.tf` in the same directory:

   ```hcl theme={null}
   module "gpu-operator" {
     enable_dcgm_exporter = true
   }
   ```

   This [Terraform override file](https://developer.hashicorp.com/terraform/language/files/override) enables the NVIDIA Data Center GPU Manager (DCGM) exporter in the solution's existing GPU Operator module.

5. Set the following environment variables for the solution and your Run:ai deployment:

   ```bash theme={null}
   export NEBIUS_TENANT_ID="<tenant_ID>"
   export NEBIUS_PROJECT_ID="<project_ID>"
   export NEBIUS_REGION="<region>"
   export DOMAIN_NAME="<domain_name>"
   # export NEBIUS_VPC_SUBNET_ID="<subnet_ID>"
   ```

   * `NEBIUS_TENANT_ID`: [Tenant ID](https://docs.nebius.com/iam/get-tenants.md).
   * `NEBIUS_PROJECT_ID`: [Project ID](https://docs.nebius.com/iam/manage-projects.md#how-to-get-a-project-id).
   * `NEBIUS_REGION`: Project [region](https://docs.nebius.com/overview/regions.md), as displayed in the list of projects in the web console.

     You can [configure a Managed Service for PostgreSQL cluster](#optional-configure-a-managed-postgresql-cluster) if you don't want to use the PostgreSQL database the Run:ai installer deploys in your Kubernetes cluster. In that case, choose a project in a [supported region](https://docs.nebius.com/postgresql/index.md) and use that region.
   * `DOMAIN_NAME`: Domain for the Run:ai web interface and workload subdomains.
   * `NEBIUS_VPC_SUBNET_ID` (optional): [Subnet ID](https://docs.nebius.com/vpc/networking/resources.md#how-to-get-a-subnet-id) for the cluster nodes. If you don't set it, the solution's environment script selects the default subnet in the project's default network.

   The `NEBIUS_*` variables configure the solution's Terraform environment. `DOMAIN_NAME` specifies the domain for Run:ai DNS and TLS configuration.

6. Load the Terraform environment:

   ```bash theme={null}
   source ./environment.sh
   ```

   The script uses the subnet from `NEBIUS_VPC_SUBNET_ID` or, if the variable isn't set, selects the default subnet. It then prepares an Object Storage bucket for Terraform state and creates the `k8s-training-sa` service account. It adds the service account to the `editors` group in the tenant and sets the Terraform inputs from the environment variables.

7. Initialize Terraform in the working directory:
   ```bash theme={null}
   terraform init
   ```

8. Apply the changes:
   ```bash theme={null}
   terraform apply
   ```

9. Connect to the `k8s-training` cluster:

   ```bash theme={null}
   export K8S_CLUSTER_ID=$(nebius mk8s cluster get-by-name \
     --parent-id "$NEBIUS_PROJECT_ID" \
     --name "k8s-training" --format jsonpath='{.metadata.id}')
   nebius mk8s cluster get-credentials \
     --id "$K8S_CLUSTER_ID" \
     --external
   kubectl cluster-info
   ```

   The command adds the cluster to your kubeconfig and selects it as the current context. The `kubectl`, `helm`, and `runai-installer` commands in the rest of this tutorial run against this cluster.

### Install an ingress controller and configure DNS

Run:ai requires an ingress controller. This tutorial uses HAProxy Kubernetes Ingress Controller, following [NVIDIA's networking setup](https://docs.nvidia.com/run-ai/self-hosted/documentation/installation-and-configuration/system-requirements/networking-setup).

1. Install HAProxy with a Service of type `LoadBalancer`:

   ```bash theme={null}
   helm repo add haproxytech https://haproxytech.github.io/helm-charts
   helm repo update
   helm install haproxy-kubernetes-ingress haproxytech/kubernetes-ingress \
    --create-namespace \
    --namespace haproxy-controller \
    --set controller.service.type=LoadBalancer \
    --set-string controller.config.ssl-redirect-port=443
   ```

   Managed Kubernetes allocates a public IP address for the load balancer. The ingress class is `haproxy`; you will reference it in the installer configuration.

2. Get the load balancer's IP address from the `EXTERNAL-IP` column:

   ```bash theme={null}
   kubectl get svc -n haproxy-controller
   ```

   Wait until an address appears.

3. In your DNS provider, create public DNS records pointing to this IP address for both your domain (`<domain_name>`) and its wildcard (`*.<domain_name>`).

   If you want to [enable Knative inference endpoints](#knative-inference) to let applications outside the cluster send requests to your models, also configure a wildcard inference domain, for example `*.runai-inference.<domain_name>`, pointing to the same address.

   Allow time for the DNS changes to propagate before running the installer.

### Prepare TLS certificates

The installer reads local PEM files and creates TLS Secrets for Run:ai. The certificate must cover both your domain (`<domain_name>`) and its wildcard (`*.<domain_name>`). The example [installer configuration](#prepare-the-installer-configuration) in this tutorial uses this certificate for both the control plane and cluster, including host-based workload routing.

For details, see [NVIDIA's domain and certificate requirements](https://docs.nvidia.com/run-ai/self-hosted/v3.0/documentation/installation-and-configuration/install/guided-installation/connected-installation/preparations#domains-and-tls-certificates).

To prepare the certificate files:

1. Get the certificate chain and matching private key files in PEM format. Use existing certificate files, or [obtain them with cert-manager](#optional-obtain-certificate-files-with-cert-manager).

   > [accordion] (Optional) Obtain certificate files with cert-manager
   >
   > 1. [Install cert-manager with Helm](https://cert-manager.io/docs/installation/helm/).
   >
   > 2. Configure a [DNS-01 solver for your DNS provider](https://cert-manager.io/docs/configuration/acme/dns01/) and [request a certificate](https://cert-manager.io/docs/usage/certificate/) covering both `<domain_name>` and `*.<domain_name>`. HTTP-01 validation can't issue wildcard certificates.
   >
   > 3. Wait until the certificate is ready, then export its certificate chain and private key from the secret to local PEM files:
   >
   >    ```bash theme={null}
   >    kubectl get secret "<certificate_secret_name>" --namespace "<namespace>" \
   >      -o jsonpath='{.data.tls\.crt}' | base64 -d > fullchain.pem
   >    kubectl get secret "<certificate_secret_name>" --namespace "<namespace>" \
   >      -o jsonpath='{.data.tls\.key}' | base64 -d > private.pem
   >    chmod 600 private.pem
   >    ```
   >
   >    Replace `<certificate_secret_name>` with the certificate's `spec.secretName` and `<namespace>` with its namespace.

2. Save the files on the local machine where you will run the Run:ai installer. If a private certificate authority signed your certificates, also save its certificate authority chain file.

3. (Optional) If you [enable Knative inference endpoints](#knative-inference) for access from outside the cluster, also obtain a certificate covering the wildcard inference domain.

### (Optional) Configure a Managed PostgreSQL cluster

By default, the Run:ai installer deploys a PostgreSQL 16 database inside the Kubernetes cluster for the Run:ai control plane. Alternatively, you can create your own Nebius Managed PostgreSQL cluster.

> [!WARNING]
>
> Create the Managed PostgreSQL cluster in the same region and network as the [Managed Kubernetes cluster](#set-up-a-managed-kubernetes-cluster).

To deploy a Managed PostgreSQL cluster and prepare its credentials for Run:ai:

1. [Install the postgresql package](https://docs.nebius.com/postgresql/quickstart.md#install-postgresql-package).

2. Get the ID of the network that includes the Managed Kubernetes cluster's subnet:

   ```bash theme={null}
   nebius vpc subnet get --id "$NEBIUS_VPC_SUBNET_ID" --format jsonpath='{.spec.network_id}'
   ```

3. Create a Managed PostgreSQL cluster in the same network. In the command, set `<network_ID>` to the ID you received in the previous step:

   ```bash theme={null}
   export PG_PASSWORD="<PostgreSQL_password>"
   nebius msp postgresql v1alpha1 cluster create \
       --name runai-backend-postgres \
       --network-id <network_ID> \
       --backup-backup-window-start "01:00:00" \
       --backup-retention-policy "7d" \
       --bootstrap-user-name "runai" \
       --bootstrap-user-password "$PG_PASSWORD" \
       --bootstrap-db-name "runai" \
       --config-version 16 \
       --config-pooler-config-pooling-mode "session" \
       --config-template-disk-type "network-ssd" \
       --config-template-disk-size-gibibytes 20 \
       --config-template-hosts-count 2 \
       --config-template-resources-platform "cpu-e2" \
       --config-template-resources-preset "4vcpu-16gb" \
       --config-postgresql-config-16-max-connections 320
   ```

   The command creates a PostgreSQL 16 cluster, the only version Run:ai supports, with the `runai` database and user for Run:ai.

4. Get the private read-write endpoint and save it to `PG_ENDPOINT`:

   ```bash theme={null}
   export PG_ENDPOINT=$(nebius msp postgresql v1alpha1 cluster get-by-name --name runai-backend-postgres --format jsonpath='{.status.connection_endpoints.private_read_write}')
   ```

5. Create a namespace and a Secret with the password that the cluster creation command saved to `PG_PASSWORD`:

   ```bash theme={null}
   kubectl create namespace runai-backend
   kubectl create secret generic postgresql-credentials -n runai-backend \
       --from-literal=postgres-password=$PG_PASSWORD \
       --from-literal=password=$PG_PASSWORD
   ```

In the next step, you also need to [disable the bundled PostgreSQL database](#use-managed-postgresql) and configure Run:ai to connect to your Managed PostgreSQL cluster.

### Install Run:ai

#### Download the installer

In the `k8s-training` directory, [download the Run:ai installer](https://docs.nvidia.com/run-ai/self-hosted/v3.0/documentation/installation-and-configuration/install/guided-installation/connected-installation/preparations#download-the-installer) for your operating system and architecture.

To follow the commands in this tutorial, rename the downloaded binary to `runai-installer`:

```bash theme={null}
mv "runai-installer-<os>-<arch>" runai-installer
```

Replace `<os>` with `linux` or `darwin`, and `<arch>` with `amd64` or `arm64`, matching the filename you downloaded.

#### Prepare the installer configuration

Create a configuration that installs Run:ai on the Managed Kubernetes cluster, uses your TLS certificates, and installs Prometheus. GPU Operator is already installed by the k8s-training solution.

> [!NOTE]
>
> To use GPU fractions, the installed GPU Operator, driver, and Container Toolkit must meet [NVIDIA's GPU fractions requirements](https://docs.nvidia.com/run-ai/self-hosted/v3.0/documentation/platform-management/runai-scheduler/resource-optimization/gpu-fractions/memory-fractions). Check that your configuration meets the requirements separately from the basic setup for workloads that use whole GPUs.

Create `config.yaml`:

> [accordion] config.yaml
>
> ```yaml theme={null}
> install:
>   mode: full_installation
>   connectivity: connected
>
> registry:
>   type: ngc
>
> tls:
>   certPath: <absolute_path_to_certificate_chain>
>   keyPath: <absolute_path_to_private_key>
>
> controlPlane:
>   enabled: true
>   domain: <domain_name>
>   customHelmValues: {}
>
> cluster:
>   enabled: true
>   name: k8s-training
>   workloadRouting: host
>
> prerequisites:
>   gpuOperator:
>     mode: skip
>   prometheus:
>     mode: install
>   networkOperator:
>     mode: skip
>
> features:
>   skip: true
>
> externalConnection:
>   type: ingress
>   ingress:
>     className: haproxy
> ```

In the configuration, set the following:

* `controlPlane.domain`: Domain name you saved to `DOMAIN_NAME` in [Set up a Managed Kubernetes cluster](#set-up-a-managed-kubernetes-cluster).
* `tls.certPath`: Absolute path to the certificate chain file from [Prepare TLS certificates](#prepare-tls-certificates).
* `tls.keyPath`: Absolute path to the matching private key file from [Prepare TLS certificates](#prepare-tls-certificates).
* `tls.caChainPath` : If a private certificate authority issued your certificate, add this parameter and set it to the absolute path to the certificate authority chain file from [Prepare TLS certificates](#prepare-tls-certificates).

If you use Managed PostgreSQL or want to enable Knative inference endpoints, apply the additional configuration below:

> [accordion] (Optional) Use Managed PostgreSQL
>
> If you created a Managed PostgreSQL cluster, replace `controlPlane.customHelmValues: {}` with the following map under `controlPlane`. Replace `<postgresql_endpoint>` with the value of `PG_ENDPOINT`:
>
> ```yaml theme={null}
> customHelmValues:
>   postgresql.enabled: false
>   global.postgresql.auth.host: <postgresql_endpoint>
>   global.postgresql.auth.database: runai
>   global.postgresql.auth.username: runai
>   global.postgresql.auth.existingSecret: postgresql-credentials
> ```
>
> `postgresql.enabled: false` disables the bundled PostgreSQL database. The `global.postgresql.auth.*` settings connect Run:ai to the Managed PostgreSQL cluster. For SSL configuration, see [NVIDIA's PostgreSQL configuration reference](https://docs.nvidia.com/run-ai/self-hosted/documentation/installation-and-configuration/system-requirements/third-party-services/standard-third-party-services#configuring-external-postgresql). Run:ai doesn't support PostgreSQL SSL mode `prefer`.

> [accordion] (Optional) Enable inference endpoints with Knative
>
> Knative Serving enables standard single-node inference workloads. To expose these workloads externally, replace the `features` block with:
>
> ```yaml theme={null}
> features:
>   knative:
>     mode: install
> ```
>
> Add the following `inference` block under `cluster`, by using the wildcard inference domain you configured in DNS and the absolute paths to its certificate and key:
>
> ```yaml theme={null}
> inference:
>   wildcardDomain: "*.runai-inference.<domain_name>"
>   wildcardTls:
>     certPath: <absolute_path_to_inference_certificate_chain>
>     keyPath: <absolute_path_to_inference_private_key>
> ```
>
> For details, see [NVIDIA's networking setup](https://docs.nvidia.com/run-ai/self-hosted/documentation/installation-and-configuration/system-requirements/networking-setup).

#### Run the installer

Run the following commands from the directory containing `runai-installer` and `config.yaml`.

1. Validate the configuration against the cluster and run preflight checks:

   ```bash theme={null}
   ./runai-installer install --config config.yaml --preflight-only
   ```

2. Review the installation plan without applying changes:

   ```bash theme={null}
   ./runai-installer install --config config.yaml --dry-run
   ```

3. Run the installation:

   ```bash theme={null}
   ./runai-installer install --config config.yaml --logs-dir ./logs
   ```

   The installer deploys Run:ai into the Managed Kubernetes cluster you [connected to](#set-up-a-managed-kubernetes-cluster) earlier. It installs prerequisites, enabled features, the control plane, and cluster components, and registers the `k8s-training` cluster with the control plane. During installation, it generates the credentials that are required to [log in to Run:ai](#log-in-to-runai).

4. Check the Pods:

   ```bash theme={null}
   kubectl get pods -n runai-backend
   kubectl get pods -n runai
   ```

   Wait until each Pod is `Running` with a complete `READY` count or has finished with status `Completed`.

For installer parameters and troubleshooting, see [NVIDIA's command reference](https://docs.nvidia.com/run-ai/self-hosted/documentation/installation-and-configuration/install/guided-installation/command-reference-and-troubleshooting).

### Log in to Run:ai

1. Retrieve the administrator username and password the Run:ai installer generated:

   ```bash theme={null}
   printf 'Username: '
   kubectl get configmap runai-backend-tenants-manager -n runai-backend -o jsonpath='{.data.ADMIN_USERNAME}{"\n"}'
   printf 'Password: '
   kubectl get secret runai-backend-gen-tenants-manager -n runai-backend -o jsonpath='{.data.ADMIN_PASSWORD}' | base64 -d
   printf '\n'
   ```

2. Open `https://<domain_name>` in your browser, replacing `<domain_name>` with your domain.

   The UI can take up to 15 minutes to become reachable.

3. Log in with the credentials and change the password.

4. Verify that the `k8s-training` cluster shows **Connected** in the control plane. If it doesn't, see [NVIDIA's cluster troubleshooting guide](https://docs.nvidia.com/run-ai/self-hosted/documentation/installation-and-configuration/operate/clusters#troubleshooting-scenarios).

You can now manage workloads in the Run:ai UI.

## How to delete the created resources

Some of the created resources are chargeable. If you don't need them, delete these resources, so Nebius AI Cloud doesn't charge for them.

The `terraform destroy` command deletes only the resources that Terraform created: the Managed Kubernetes cluster, its node groups, and the shared filesystem. The `environment.sh` script creates the bucket by using the Nebius AI Cloud CLI, and the cluster creates disks for Run:ai persistent volumes. The following steps delete all of these resources:

1. Uninstall HAProxy:

   ```bash theme={null}
   helm uninstall haproxy-kubernetes-ingress -n haproxy-controller \
     --cascade foreground --wait
   ```

   Wait for the command to complete before continuing. It deletes the HAProxy `LoadBalancer` Service so that Managed Kubernetes can remove the load balancer and its automatically managed public IP allocation.

2. Go to the `k8s-training` directory of the cloned repository and run the `environment.sh` script again:

   ```bash theme={null}
   export NEBIUS_TENANT_ID="<tenant_ID>"
   export NEBIUS_PROJECT_ID="<project_ID>"
   export NEBIUS_REGION="<region>"
   source ./environment.sh
   ```

   Terraform reads the project and subnet IDs, the IAM access token, and the access key to the bucket with the Terraform state from environment variables that the script sets. These variables exist only in the terminal session where you ran the script, and the token and the key expire. The script sets the variables again.

3. Get the ID of the Managed Kubernetes cluster:

   ```bash theme={null}
   nebius mk8s cluster get-by-name \
     --name k8s-training \
     --format jsonpath='{.metadata.id}'
   ```

   Save the received ID. The disks of the Run:ai persistent volumes have the cluster ID in their labels. After Terraform deletes the cluster, use this ID to find these disks.

4. Delete the resources that Terraform created:

   ```bash theme={null}
   terraform destroy
   ```

   If the command fails while uninstalling a Helm release, run it again.

5. Get the IDs of the disks that the cluster created for Run:ai persistent volumes:

   ```bash theme={null}
   nebius compute disk list \
     --format json \
     | jq -r --arg CLUSTER_ID "<cluster_ID>" '.items[]?
       | select(.metadata.labels["compute.csi.nebius.com/cluster-id"] == $CLUSTER_ID)
       | .metadata.id'
   ```

6. [Delete the disks](https://docs.nebius.com/compute/storage/manage.md#how-to-delete-a-volume) with these IDs.

7. [Delete the Managed PostgreSQL cluster](https://docs.nebius.com/postgresql/clusters/manage.md#how-to-delete-clusters) if you used it.

8. [Delete the bucket](https://docs.nebius.com/object-storage/buckets/manage.md#how-to-delete-buckets) that stores the Terraform state. Its name starts with `tfstate-k8s-training-`.

***

*Postgres, PostgreSQL and the Slonik Logo are trademarks or registered trademarks of the PostgreSQL Community Association of Canada, and used with their permission.*
