Skip to navigation

NIM Operator Deployment

View as MarkdownOpen in Claude

The NVIDIA NIM Operator is a Kubernetes operator that manages the lifecycle of NIMs in Kubernetes environments, including deployment, scaling, model caching, and health monitoring.

Deploy NIM LLM and VLM with the NVIDIA NIM Operator through these Kubernetes-native custom resources:

  • NIMCache — Manages model artifact caching on persistent storage, so models are downloaded during the initial cache population and reused across pod restarts and scaling events.
  • NIMService — Manages the NIM deployment lifecycle, including pod creation, health probes, service exposure, and GPU resource scheduling.

Using the NIM Operator simplifies NIM deployment on Kubernetes by handling common concerns such as image pull secrets, NGC authentication, persistent storage provisioning, and probe configuration.

For operator source code and issue tracking, refer to the NIM Operator GitHub repository.

Prerequisites

Before you start, complete the following prerequisites:

  1. Provision a Kubernetes 1.26 or later cluster with kubectl access.
  2. Install the NVIDIA GPU Operator in the cluster.
  3. Install a persistent storage provisioner in the cluster for model caching.
  4. Obtain an NGC API key for pulling NIM container images and downloading model artifacts.
  5. Install NVIDIA NIM Operator version 3.0.2 or later. Refer to the NVIDIA NIM Operator installation guide.

Create a Namespace

Create a dedicated Kubernetes namespace for NIM. A namespace is a logical partition within a cluster. It isolates resources such as pods, services, and secrets from other workloads. Creating a dedicated namespace for NIM keeps resources organized and helps avoid naming conflicts with other applications in the cluster.

kubectl create ns nim-service

Create Secrets

To create the secrets for image pulls and model downloads, complete the following steps:

  1. Create an image pull secret for NGC container registry access:

    export NGC_API_KEY=${YOUR_NGC_API_KEY}
    kubectl create secret -n nim-service docker-registry ngc-secret \
    --docker-server=nvcr.io \
    --docker-username='$oauthtoken' \
    --docker-password=${NGC_API_KEY}
  2. Create a secret with the NGC API key for model downloads:

    kubectl create secret -n nim-service generic ngc-api-secret \
    --from-literal=NGC_API_KEY=${NGC_API_KEY}

Cache Model Artifacts

To create a NIMCache and wait for the model artifacts to be cached, complete the following steps. Caching avoids re-downloading the model every time a pod starts.

If the cluster reaches NGC through a corporate proxy or an endpoint signed by a private certificate authority (CA), add the settings from Trust Custom CA Certificates to the NIMCache when you create it.

  1. Create a NIMCache custom resource to pre-download model artifacts to persistent storage:

    kubectl create -n nim-service -f - <<'EOF'
    apiVersion: apps.nvidia.com/v1alpha1
    kind: NIMCache
    metadata:
    name: meta-llama3-8b-instruct
    spec:
    source:
    ngc:
    modelPuller: <NIM_LLM_MODEL_SPECIFIC_IMAGE>:2.1.6
    pullSecret: ngc-secret
    authSecret: ngc-api-secret
    model:
    engine: "vllm"
    tensorParallelism: "1"
    storage:
    pvc:
    create: true
    size: "80Gi"
    volumeAccessMode: ReadWriteOnce
    EOF

    Set engine to vllm for a vLLM image or sglang for an SGLang image. The Operator uses it to select profiles whose llm_engine tag matches. Leave engine empty if you set model.profiles explicitly.

  2. Monitor the caching progress:

    kubectl get nimcache -n nim-service -w
  3. Wait until the NIMCache status shows Ready before you continue.

Create a NIMService

After the cache is ready, create a NIMService custom resource to deploy the NIM service:

kubectl create -n nim-service -f - <<'EOF'
apiVersion: apps.nvidia.com/v1alpha1
kind: NIMService
metadata:
name: meta-llama3-8b-instruct
spec:
image:
repository: <NIM_LLM_MODEL_SPECIFIC_IMAGE>
tag: "2.1.6"
pullPolicy: IfNotPresent
pullSecrets:
- ngc-secret
authSecret: ngc-api-secret
storage:
nimCache:
name: meta-llama3-8b-instruct
profile: ''
resources:
limits:
nvidia.com/gpu: 1
expose:
service:
type: ClusterIP
port: 8000
EOF

Verify the Deployment

To verify that the NIMService and pod are ready, complete the following steps:

  1. Check the NIMService status:

    kubectl get nimservice -n nim-service
  2. Check that the pod is running:

    kubectl get pods -n nim-service
  3. After the NIMService is ready, test inference with port forwarding:

    kubectl port-forward -n nim-service svc/meta-llama3-8b-instruct 8000:8000
  4. Query the /v1/models endpoint to discover the model name to use in inference requests:

    curl -s http://localhost:8000/v1/models
  5. Send a chat completion request using the model name returned by /v1/models:

    curl -s http://localhost:8000/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
    "model": "meta/llama-3.1-8b-instruct",
    "messages": [{"role": "user", "content": "Hello!"}],
    "max_tokens": 64
    }'

Configure the NIMService

Use the NIMService env field for NIM environment variables. For a NIMService that does not set spec.multiNode, use spec.args for backend arguments. The Operator maps spec.args to the NIM container’s Kubernetes arguments, which preserve any NIM_PASSTHROUGH_ARGS value provided by the image and resolve at the higher CLI priority. Do not use spec.args for a multi-node NIMService; the current LeaderWorkerSet path does not propagate it to the leader or worker NIM containers.

For the full list of supported environment variables, refer to Environment Variables. For available API endpoints (inference and management), refer to the API Reference.

The following examples are independent options. Each snippet shows a standalone configuration that you can add to your NIMService spec. Apply only the options that are relevant to your deployment. They are not sequential steps.

For a NIMService that does not set spec.multiNode, pass additional backend arguments through spec.args. Specify each option and value as a separate list item. Argument names and supported values must match the backend version in the image. Canonical NIM flags such as --tensor-parallel-size and --enable-prefix-caching are accepted on both images and translated to the engine’s native flag. A flag the engine does not recognize stops startup. The following example shows arguments for each engine:

spec:
args:
- "--enable-prefix-caching"
- "--max-num-batched-tokens"
- "8192"

Do not set NIM_PASSTHROUGH_ARGS in spec.env to only your custom arguments. Kubernetes replaces any value supplied by the image instead of appending to it. If NIM_STRICT_ARG_PROCESSING=true, the NIM exits when a direct argument conflicts with an image-provided passthrough value. For the environment-only fallback and configuration provenance, refer to Advanced Configuration.

For logging configuration details, refer to Logging and Observability.

Trust Custom CA Certificates

If the NIM must reach endpoints whose TLS certificates are signed by a private certificate authority (CA), such as a corporate proxy or an internal model registry, provide the CA certificates through the NIM Operator spec.proxy.certConfigMap field. Set it on both the NIMCache, which downloads the model, and the NIMService.

  1. Create a ConfigMap that holds the PEM-encoded CA certificates. Give each key a .crt or .pem extension; the operator ignores other keys:

    kubectl create configmap custom-ca -n nim-service --from-file=corporate-ca.crt
  2. Add the following to the spec of the NIMCache:

    spec:
    proxy:
    certConfigMap: custom-ca
    env:
    - name: SSL_CERT_FILE
    value: /etc/ssl/certs/ca-certificates.crt
    - name: REQUESTS_CA_BUNDLE
    value: /etc/ssl/certs/ca-certificates.crt

    The two env entries point Python-based downloads at the trust store that contains your certificates.

    Add these settings when you create the NIMCache. The operator reads them only when it creates the caching Job. If the NIMCache already exists and has not reached Ready, delete its Job so that the operator creates a new one with these settings:

    kubectl delete job -n nim-service meta-llama3-8b-instruct-job
  3. Add the following to the spec of the NIMService:

    spec:
    proxy:
    certConfigMap: custom-ca
  4. If the cluster reaches external endpoints through an HTTP proxy, set the proxy in the same spec.proxy block of both resources:

    spec:
    proxy:
    certConfigMap: custom-ca
    httpProxy: http://proxy.example.com:3128
    httpsProxy: http://proxy.example.com:3128
    noProxy: localhost,127.0.0.1,.svc,.cluster.local

    Include localhost and 127.0.0.1 in noProxy, because the NIM sends HTTP requests to itself, and add the cluster-internal domains and internal hosts that must not go through the proxy. When spec.proxy is set, the operator sets the proxy environment variables from these fields and overrides any proxy variables in spec.env.

  5. After the pod starts, confirm that the NIM trusts an endpoint that your CA signs:

    kubectl exec -n nim-service deploy/meta-llama3-8b-instruct -- \
    openssl s_client -connect <HOST>:443 -servername <HOST> -verify_return_error </dev/null

    The output includes Verify return code: 0 (ok) when the certificate chain is trusted. openssl s_client does not read the proxy environment variables. If the NIM reaches <HOST> through the HTTP proxy, add -proxy <PROXY_HOST>:<PROXY_PORT>, with the host and port from httpsProxy and no http:// prefix.

For each pod, the operator adds an init container that runs as root (UID 0), builds a trust store that includes your certificates, and mounts it at /etc/ssl in the NIM container. The NIM container uses that trust store as is, whatever spec.userID and spec.groupID it runs with.

If an admission webhook or another tool also mounts a CA certificate into the NIM container at /usr/local/share/ca-certificates/, a NIM container that runs as root (spec.userID: 0) adds that certificate to the trust store and keeps everything already in it, including your certificates. A non-root NIM container cannot change the trust store and logs the warning described in Startup Warning About Skipping the CA Certificate Update instead.

On OpenShift, the operator runs these pods under the anyuid security context constraint (SCC). The NIMCache Job uses anyuid whenever spec.proxy is set, even without certConfigMap. If your security policy does not allow a root init container or the anyuid SCC, refer to Use a Derived Image Instead of spec.proxy.

For more information, refer to Proxy Support in the NVIDIA NIM Operator documentation.

Use a Derived Image Instead of spec.proxy

If your security policy does not allow the root init container or the anyuid SCC, add the certificates to the image instead:

  1. Build an image from the NIM image that copies your certificates into /usr/local/share/ca-certificates/ and runs update-ca-certificates as root. Use this image as both the NIMCache modelPuller image and the NIMService image.

  2. Do not set spec.proxy on either resource. Set the following in spec.env of both the NIMCache and the NIMService instead:

    spec:
    env:
    - name: SSL_CERT_FILE
    value: /etc/ssl/certs/ca-certificates.crt
    - name: REQUESTS_CA_BUNDLE
    value: /etc/ssl/certs/ca-certificates.crt
    - name: NIM_SDK_USE_NATIVE_TLS
    value: "1"

    NIM_SDK_USE_NATIVE_TLS=1 makes model downloads use the system trust store; the operator sets it for you only when spec.proxy is set. If you use an HTTP proxy, also set HTTP_PROXY, HTTPS_PROXY, and NO_PROXY, and their lowercase forms, in the same env lists.

Monitor and Autoscale the Deployment

NIM LLM and VLM exposes the backend’s native Prometheus metrics at /v1/metrics. Use these metrics for autoscaling, alerting, and capacity planning in operator deployments.

Metric names are backend-native and differ between vLLM and SGLang. Query the deployment’s /v1/metrics endpoint to confirm the exact metric names exposed by your container image.

To collect metrics and scale operator-managed deployments, complete the following steps:

  1. Review available metrics, scrape configuration, and dashboard setup in Logging and Observability. For backend metric definitions, refer to the vLLM production metrics documentation or the SGLang production metrics documentation.

  2. Optional: Create a Prometheus ServiceMonitor for automatic metric scraping. The operator hardcodes the metrics endpoint path to /v1/metrics:

    spec:
    metrics:
    enabled: true
    serviceMonitor:
    additionalLabels: {}
  3. Optional: Enable horizontal pod autoscaling (HPA) based on custom Prometheus metrics. Standard CPU and memory metrics are not useful for scaling NIM. Use inference-specific metrics instead. The following example shows HPA configuration in a NIMService spec:

    spec:
    scale:
    enabled: true
    hpa:
    minReplicas: 1
    maxReplicas: 4
    metrics:
    - type: Pods
    pods:
    metric:
    name: vllm:num_requests_waiting
    target:
    type: AverageValue
    averageValue: "10"

    The vllm:num_requests_waiting metric name is backend-native and applies to the vLLM backend. On an SGLang image, the waiting-queue metric name differs. Query the deployment’s /v1/metrics endpoint to find the correct metric name for your backend before configuring the HPA.

    This requires the Prometheus Adapter to be installed and configured to expose the backend’s metrics as Kubernetes custom metrics.

Troubleshooting

Use the following troubleshooting sections to diagnose common deployment issues on NVIDIA NIM Operator.

The examples below use the resource names from this guide (for example, meta-llama3-8b-instruct). Replace them with the names of your own NIMCache and NIMService resources.

NIMCache Stuck in Pending or NotReady State

If NIMCache remains in Pending or NotReady, complete the following steps to isolate the issue:

  1. Verify the storage class is available and can provision volumes:

    kubectl get storageclass
  2. Check the PVC status:

    kubectl get pvc -n nim-service
  3. Check the job that downloads model artifacts. The NIMCache controller creates a Kubernetes Job named <nimcache-name>-job. Inspect the job status and its pod logs:

    kubectl get jobs -n nim-service
    kubectl logs -n nim-service -l job-name=meta-llama3-8b-instruct-job

    If the job fails, it retries up to five times, which is the default backoffLimit. Check for authentication errors, network issues, or insufficient disk space in the job pod logs.

  4. Confirm the NGC API key secret is correct and the image pull secret has access to the NIM container image.

  5. Check the NIMCache status conditions for details:

    kubectl describe nimcache -n nim-service meta-llama3-8b-instruct

NIMService Pod Fails to Start

If the NIMService pod fails to start, complete the following steps to isolate the issue:

  1. Check pod events:

    kubectl describe pod -n nim-service -l app=meta-llama3-8b-instruct
  2. Check pod logs:

    kubectl logs -n nim-service -l app=meta-llama3-8b-instruct
  3. Verify GPU resources are available:

    kubectl get nodes -o json | jq '.items[].status.allocatable["nvidia.com/gpu"]'
  4. Confirm the NIMCache is in Ready state before deploying the NIMService. The NIM pod mounts the cache PVC at /model-store and fails if the model artifacts are not present.

  5. If you use a specific model profile through spec.storage.nimCache.profile, verify that the profile name matches one available in the cached model manifest.

Startup Warning About Skipping the CA Certificate Update

The NIM container logs the following warning at startup when a certificate in /usr/local/share/ca-certificates/ is not in its trust store and the container cannot write to /etc/ssl/certs:

WARNING: custom CA certs are mounted but /etc/ssl/certs is read-only; skipping update-ca-certificates. Mount a writable /etc/ssl/certs (or pre-bake the CA into the image) if the custom roots must be trusted. Not in the trust bundle: /usr/local/share/ca-certificates/<CA_FILE>.crt

The NIM does not trust the files listed after Not in the trust bundle. The certificates that ship in the image, and the ones that you supply through spec.proxy.certConfigMap, are already in the trust store and do not cause this warning. Instead of mounting CA certificates into the NIM container, supply them through spec.proxy.certConfigMap, as described in Trust Custom CA Certificates, or add them to a derived image, as described in Use a Derived Image Instead of spec.proxy.

Health Probes Fail

The nginx proxy in the NIM container serves the health endpoints. /v1/health/live responds immediately, even during model loading, while /v1/health/ready only returns 200 after the model is fully loaded. By default, both endpoints use the NIM service port (NIM_SERVER_PORT, which defaults to 8000). If NIM_HEALTH_PORT is set, the health endpoints move to that dedicated port instead.

The operator configures a startup probe on /v1/health/ready with a default failureThreshold of 120 and a periodSeconds of 10, giving the model up to 20 minutes to load before the pod is killed. If readiness or startup probes are failing, complete the following steps:

  1. For large models that take longer to load, increase the startup probe failure threshold in the NIMService spec:

    spec:
    startupProbe:
    enabled: true
    probe:
    httpGet:
    path: /v1/health/ready
    port: 8000
    initialDelaySeconds: 30
    periodSeconds: 10
    failureThreshold: 240
  2. Check that spec.expose.service.port matches the port used by the NIM container (default 8000). The operator sets NIM_SERVER_PORT automatically from this value.

NIM Operator Pod Not Running

If the NIMService or NIMCache resources are not being reconciled, verify the operator itself is healthy:

kubectl get pods -n nim-operator
kubectl logs -n nim-operator -l app.kubernetes.io/name=k8s-nim-operator

Next Steps

Refer to the following resources for more information: