Skip to main content
This document is for deploying a RoCE network-based SGLang two-node inference service on a Kubernetes (K8S) cluster. LeaderWorkerSet (LWS) is a Kubernetes API that aims to address common deployment patterns of AI/ML inference workloads. A major use case is for multi-host/multi-node distributed inference. SGLang can also be deployed with LWS on Kubernetes for distributed model serving. Please see this guide for more details on deploying SGLang on Kubernetes using LWS. Here we take the deployment of DeepSeek-R1 as an example.

Prerequisites

  1. At least two Kubernetes nodes, each with two H20 systems and eight GPUs, are required.
  2. Make sure your K8S cluster has LWS correctly installed. If it hasn’t been set up yet, please follow the installation instructions. Note: For LWS versions ≤0.5.x, you must use the Downward API to obtain LWS_WORKER_INDEX, as native support for this feature was introduced in v0.6.0.

Basic example

For the basic example documentation, refer to Deploy Distributed Inference Service with SGLang and LWS on GPUs. However, that document only covers the basic NCCL socket mode. In this section, we’ll make some simple modifications to adapt the setup to the RDMA scenario.

RDMA RoCE case

  • Check your env:
Command
  • Prepare the lws.yaml file for deploying on k8s.
Config
  • Then use kubectl apply -f lws.yaml you will get this output.
Output
Wait for the sglang leader (sglang-0) status to change to 1/1, which indicates it is Ready. You can use the command kubectl logs -f sglang-0 to view the logs of the leader node. Once successful, you should see output like this:
Output
If it doesn’t start up successfully, please follow these steps to check for any remaining issues. Thanks!

Debug

  • Set NCCL_DEBUG=TRACE to check if it is a NCCL communication problem.
This should resolve most NCCL-related issues. Notice: If you find that NCCL_DEBUG=TRACE is not effective in the container environment, but the process is stuck or you encounter hard-to-diagnose issues, try switching to a different container image. Some images may not handle standard error output properly.

RoCE scenario

  • Please make sure that RDMA devices are available in the cluster environment.
  • Please make sure that the nodes in the cluster have Mellanox NICs with RoCE. In this example, we use Mellanox ConnectX 5 model NICs, and the proper OFED driver has been installed. If not, please refer to the document Install OFED Driver to install the driver.
  • Check your env:
    Command
  • Check the OFED driver:
    Command
  • Show RDMA link status and check IB devices:
    Command
  • Test RoCE network speed on the host:
    Command
  • Check RDMA accessible in your container:
    Command

Keys to success

  • In the YAML configuration above, pay attention to the NCCL environment variable. For older versions of NCCL, you should check the NCCL_IB_GID_INDEX environment setting.
  • NCCL_SOCKET_IFNAME is also crucial, but in a containerized environment, this typically isn’t an issue.
  • In some cases, it’s necessary to configure GLOO_SOCKET_IFNAME correctly.
  • NCCL_DEBUG is essential for troubleshooting, but I’ve found that sometimes it doesn’t show error logs within containers. This could be related to the Docker image you’re using. You may want to try switching images if needed.
  • Avoid using Docker images based on Ubuntu 18.04, as they tend to have compatibility issues.

Remaining issues

  • In Kubernetes, Docker, or Containerd environments, we use hostNetwork to prevent performance degradation.
  • We utilize privileged mode, which isn’t secure. Additionally, in containerized environments, full GPU isolation cannot be achieved.

TODO