Running Ray on Kubernetes with KubeRay

KubeRay manages Ray clusters, batch jobs and inference services as Kubernetes resources. This page covers the design choices, GPU autoscaling, version management and upgrades for self-managed clusters.

On this page

When teams need Ray on Kubernetes with KubeRay

KubeRay is the Kubernetes operator that runs Ray clusters for you, so teams can start distributed training or batch inference jobs on GPU nodes without hand-building head and worker pods for each run. It is the right starting point when a training or inference workload has outgrown one machine, when several teams need to share the same GPU nodes, and when the work has to live inside the cluster governance you already operate. The operator turns Ray's own concepts into Kubernetes custom resources, and the choice of resource depends on how the work starts and stops.

A RayCluster is a long-lived Ray cluster with a head pod and worker groups, suited to interactive development and shared capacity that several users or jobs attach to. A RayJob wraps a submitted entrypoint in a cluster that the operator creates, runs to completion and can tear down afterward, which fits scheduled training runs and batch inference passes. A RayService manages a Ray Serve deployment with rolling upgrades of the application, which fits online inference endpoints that must stay up while code changes. Map each workload to one of these before you design anything else, because they differ in lifecycle, in how failures are handled and in how GPU capacity is held.

Before you commit, confirm in your own environment which KubeRay and Ray versions your platform team can support, whether your GPU nodes and device plugin expose the resources Ray workers will request, and whether your scheduling tools, such as Kueue or a gang scheduler, will admit Ray pods together. Check these against the KubeRay documentation for the release you plan to run, since autoscaling, job submission and upgrade behavior are defined there rather than by this page.

RayCluster, RayJob and RayService: choosing the right resource

KubeRay gives you three custom resources, and each one owns a different lifecycle. Picking the right one before you write manifests decides who restarts what, how jobs finish and how serving stays up during changes. The cards below separate the four decisions most teams face.

Long-lived interactive clusters

A RayCluster keeps a Ray head and worker pods running until someone deletes it, which suits notebooks, exploratory work and shared development environments. Nothing in the resource says a workload has finished, so the platform team must decide who owns idle clusters and when they are removed. Check how the cluster is reached from users' tools, how its logs are kept, and who is allowed to create clusters in each namespace.

Finite training and batch jobs

A RayJob submits a Ray application to a cluster it creates for that run, and it is meant to finish. The job owns the submission, the status and the cluster lifecycle, so teams can tie resources to one training run or one batch inference pass. Confirm how the operator handles a failed submission, whether the cluster is kept after completion for debugging, and where checkpoints are written so a restart does not lose work.

Online serving with RayService

A RayService runs a Ray Serve application behind a stable Kubernetes service and changes it with zero-downtime upgrades of new application versions. It is the resource for model endpoints that must answer requests continuously. Plan the health checks, the rollout behavior during a version change and the GPU capacity needed to run old and new replicas side by side, and confirm these settings against the KubeRay documentation for your release.

Autoscaling and GPU capacity settings

Autoscaling in KubeRay operates on Ray's own demand signals and on Kubernetes pods, so GPU nodes must be able to appear when Ray asks for them. The decisions are the minimum and maximum worker counts per group, whether scale-to-zero is acceptable for each group, and how node provisioning on your cluster responds to pending GPU pods. Ask your team to test scale-up and scale-down with real GPU quota before production traffic depends on it.

Mixing Ray versions and upgrade paths

Each RayCluster or RayService pins its own Ray image, so one Kubernetes cluster can run several Ray versions at once. This helps teams move training jobs forward while serving stays on a tested release. The cost is more images to build, scan and patch, and more compatibility checks between Ray, Python and CUDA libraries. Decide which versions are supported at the same time and who signs off on each upgrade.

Configuration options and when each fits

This table compares the main KubeRay and Ray cluster choices: operator scope, head and worker layout, GPU versus CPU groups, autoscaling, and how several Ray versions share a platform. Read each row for the fit, the main trade-off, and what to confirm in the KubeRay and Ray documentation before you commit. The takeaway is that most choices are cheap to make early and expensive to change once jobs depend on them.

OptionGood fitMain trade-offConfirm before committing
Operator scope: cluster-wideOne platform team runs Ray for several teams and wants a single operator upgrade pathBroader RBAC and a shared blast radius if the operator or its CRDs failWhich namespaces the operator watches and the CRD versions your release installs
Operator scope: namespacedEach team owns its namespace and you want tighter isolation of Ray control objectsMore operator installs to upgrade and monitor across namespacesWhether your KubeRay release supports namespaced watching and the exact Helm values that enable it
Head and worker group layoutSeparate head pod from worker groups so the head stays lightweight and workers scale independentlyHead pods still need resources and recovery planning, and a head failure affects the whole clusterHead resource requests, GCS fault tolerance settings and how your Ray version handles head restarts
GPU worker groupsTraining and GPU inference that need CUDA, a GPU device plugin and placement on accelerator nodesHigher node cost, GPU scheduling fragmentation, and longer scale-up timesGPU resource names, node selectors and tolerations, and the matching CUDA and driver versions for your Ray image
CPU worker groupsData preprocessing, batch steps, and control tasks that do not need acceleratorsSome workloads will still need a GPU group, so mixed pipelines require two group types and clear placementRay resource tags for CPU and GPU so tasks land on the intended group
Autoscaler onWorkloads with variable demand where idle workers should be released and new ones addedScale decisions take time, and GPU nodes can sit idle while the autoscaler reactsAutoscaler version compatibility, idle timeout settings and how it interacts with your cluster autoscaler
Autoscaler offFixed-size training runs or inference services with predictable capacityIdle GPUs cost money and capacity must be sized up frontReplica counts and whether your RayCluster spec disables autoscaling as you expect
Separate clusters per Ray versionTeams need different Ray releases and upgrades must not affect other teams' jobsMore clusters to size, monitor and pay for, including idle head podsImage tags, the supported Ray and KubeRay version pairing and any shared storage constraints
Shared image with several Ray versionsA small number of teams that accept one image and a coordinated upgrade windowDependency conflicts and a larger rebuild and test surface for each image changePython, CUDA and library pins for each Ray version and whether your build pipeline can produce them

How GPU autoscaling interacts with Kubernetes node scaling

Ray's autoscaler and the Kubernetes node scaler make decisions separately, so a GPU Ray cluster only works when both layers agree on what a worker needs. KubeRay's autoscaler reads the resource demand of pending Ray tasks and actors, then asks the Kubernetes API for more worker Pods by changing the replica settings in the RayCluster spec. It does not add machines itself. The cluster autoscaler or your node provisioner then sees Pods stuck in Pending and adds GPU nodes. Each Ray worker group must therefore declare the same GPU resource name, the same nvidia.com/gpu request and limit, and the same nodeSelector, tolerations and node affinity that your GPU nodes carry. If a worker group asks for a GPU shape that no node pool offers, the Pods never schedule and Ray keeps waiting. Confirm this mapping for each worker group before you enable autoscaling.

Idle timeout is the main cost control and the main source of cold-start delay. A short idle timeout releases expensive GPU nodes quickly, but a Ray job that starts after a short lull waits for a new node to boot, pull the image, install drivers through the GPU stack and join the cluster. A long timeout keeps nodes warm for bursts of inference or hyperparameter sweeps, at the cost of paying for idle accelerators. Set the Ray-side idle timeout and the node-side scale-down delay together, because a node that Ray has released but the node scaler still holds, or the reverse, produces either waste or stalls. Measure your actual node start time in your own environment before choosing values, since that time depends on your images, drivers and cloud or data center provisioning.

GPU scheduling gaps stall jobs in ways CPU workloads rarely do. A distributed training job that needs eight GPUs across several workers can hold a few Pods while the rest wait for capacity, leaving the placed GPUs idle. On a shared pool, a batch job may consume capacity that a higher-priority RayService needs for inference. Plan for this before you run mixed workloads: decide which Ray groups may trigger node scale-up, set priority classes, and check whether all-or-nothing admission is needed. For shared pools, queueing with Kueue or gang scheduling may be required, covered in the sibling topics GPU quota and job queueing with Kueue and Kubernetes gang scheduling for distributed training. Test a deliberately oversubscribed queue in a non-production cluster and record how long a stalled job waits before you accept the design.

How the KubeRay components connect

The flow starts when a team submits a RayCluster, RayJob or RayService custom resource to the Kubernetes API. The KubeRay operator watches those objects and creates the head and GPU worker Pods. The Ray autoscaler then asks for more worker Pods when work queues up, and the node autoscaler adds GPU nodes only when Pods cannot be scheduled. Check where the trust boundary falls, because the Kubernetes API and the object store or model storage hold credentials and data that the Ray Pods read.

Custom resources flow through the operator, then autoscalers add Pods and nodes.

Setting up KubeRay on a GPU-enabled cluster

This sequence takes a GPU-enabled Kubernetes cluster to a working KubeRay installation, with a test Ray cluster, a batch RayJob and a promoted RayService. Each step ends with a check that confirms the layer below it works before the next one starts.

  1. Confirm GPU nodes and the device plugin

    Before installing anything Ray-specific, confirm that the GPU nodes are prepared and advertise GPUs to the scheduler. The platform or GPU team does this work, usually through the NVIDIA GPU Operator, which is covered in the sibling topic on deploying the NVIDIA GPU Operator on Kubernetes. Check that each GPU node reports allocatable GPU resources and that a short test Pod requesting one GPU reaches Running and sees the device. If this check fails, stop here, because every later step depends on Kubernetes scheduling GPUs correctly.

  2. Install the KubeRay operator and CRDs

    Install the KubeRay operator into its own namespace, using the chart or manifests your team has chosen and pinned to a specific version. The installation adds the custom resource definitions for RayCluster, RayJob and RayService, along with the controller that reconciles them. Confirm that the operator Pod is Running, that the three custom resource definitions are registered, and that the operator logs show no reconciliation errors. Record the operator version, because the Ray versions you can run depend on it and upgrades start from this record.

  3. Create a namespace with GPU-suited Pod Security

    Create a dedicated namespace for Ray workloads and set its Pod Security Admission label. Kubernetes defines three Pod Security Standards (Privileged, Baseline and Restricted), enforced per namespace. Ray and GPU containers often need settings that the Restricted level rejects, so most teams choose Baseline with warn and audit labels at the stricter level, then document any exceptions. Confirm the labels with a dry-run apply of a test Pod. Also confirm that a ServiceAccount and the RBAC rules for the Ray workloads are in place in this namespace.

  4. Deploy a test RayCluster

    Apply a small RayCluster manifest with one head group and one GPU worker group, using a Ray image that matches the version you plan to standardize on. Keep the GPU request to one device per worker so that failures are easy to read. Confirm that the head Pod and worker Pods reach Running, that the KubeRay status shows the cluster as ready, and that the Ray dashboard is reachable through a port-forward or Service. From inside the head Pod, run a short Ray check that lists the cluster resources and confirms that GPUs are visible to Ray. A count of zero usually points to a missing GPU request, a missing resource label or a mismatched image.

  5. Submit a test RayJob

    Submit a RayJob that runs a short script against the test cluster, using the same Ray image and a GPU request on the worker group. A RayJob creates its own cluster, runs the entrypoint and then reports a terminal status, so this step tests the batch path that most training and batch inference work will use. Confirm that the job status moves to Succeeded, that the driver logs show the expected GPU count, and that the cluster is cleaned up or retained according to the shutdown setting you chose. Note the job's logs location, since your monitoring and retention plans will rely on it.

  6. Promote a RayService for serving

    Deploy a RayService that runs a small Serve application on GPU workers, with a rolling update strategy. A RayService is the path for long-running inference endpoints, and it adds a Serve layer and a zero-downtime update model on top of the cluster. Confirm that the Serve application reports healthy, that the endpoint answers a test request, and that the GPU worker is allocated to the deployment. Then change a harmless setting, such as a replica count, and confirm that the update completes without the endpoint going unavailable. This check tells you whether your upgrade process will be safe later.

  7. Record versions and pin the baseline

    Write down the Kubernetes version, GPU Operator and driver versions, KubeRay operator version, and the Ray image tags used in each test. Store these in version control next to the manifests. Ask your platform team to confirm which Kubernetes minor versions your cluster supports and which KubeRay releases are compatible with them, using the vendor and project release notes rather than assumptions. This record becomes the baseline for the upgrade plan, and it lets you reproduce the working setup if a node pool or cluster has to be rebuilt.

Running multiple Ray versions in one cluster

Running one RayCluster per Ray version inside a single namespace is the lightest option. Each RayCluster carries its own head and worker pods, and each pins its own Ray image, so a team can run an older version while another moves forward. Everything still shares one namespace's quotas, service accounts, network policies and GPU pool, which makes this suitable when the teams trust each other and the cluster is small.

  • Image pinning: Set the Ray image explicitly in each RayCluster spec, and avoid floating tags such as latest so a node restart cannot change the version underneath a running job.
  • Resource contention: Both clusters draw from the same ResourceQuota and GPU nodes, so an autoscaling spike in one can starve the other. Set per-cluster limits on worker groups.
  • Upgrade blast radius: An upgrade to one RayCluster touches only its own pods, but a shared operator upgrade or a shared namespace policy change affects all of them.
  • Client and head mismatch: Confirm that the client Ray version used to submit work matches the head within the range the Ray project supports for your target versions.
  • Naming and labels: Use names that carry the Ray version so dashboards and cost reports separate the clusters.

Before relying on this model, check that your monitoring and quota reports can tell the two RayClusters apart.

Security and operational considerations

A KubeRay deployment puts a privileged operator, a dashboard that can submit code and GPU nodes that run it inside one cluster. The cards below cover the access paths, supply chain, permissions, secrets, network boundaries and audit trail that need an explicit owner and a verification step before any team runs production jobs on the cluster.

Dashboard and job submission access

The Ray dashboard and the job submission endpoint can start arbitrary code on your GPU workers, so reaching them is equivalent to running workloads on the cluster. Decide which services are exposed through ingress and which stay cluster-internal, then confirm that authentication sits in front of every route. Test whether an unauthenticated user or a user from another team can list jobs, read logs or submit work.

Image provenance for Ray and CUDA

Ray images bundle Python packages, CUDA libraries and driver-facing components, so one unvetted base image can affect every job. Pin images by digest rather than by floating tag, record which Ray and CUDA versions each image contains, and mirror approved images into a private registry. Ask who signs and scans images and how a rebuild is triggered when a CUDA or Python dependency has a published fix.

Least-privilege RBAC for the operator

The KubeRay operator creates pods, services and other objects across namespaces it manages, so its ClusterRole is often broader than teams expect. Scope it to the namespaces where Ray clusters run where your model allows, and review which verbs it holds on secrets and pods. Check who can create or edit RayCluster and RayJob objects, because those objects control images, service accounts and mounted volumes.

Secrets for data stores and registries

Training jobs usually need credentials for object storage, feature stores, model registries and experiment trackers. Kubernetes Secrets are stored unencrypted in etcd by default, so confirm that encryption at rest is enabled and restrict which service accounts can read Secrets in the Ray namespaces. Prefer short-lived credentials or an external store mounted through the Secrets Store CSI Driver, and avoid placing tokens in the Ray job entrypoint or runtime environment, where they appear in logs and job metadata.

Secrets good practices

Network policies between head and workers

Ray nodes communicate over many ports for the GCS, object transfer and worker coordination, and the head node is a high-value target. Write network policies that allow traffic between the head and its own workers, plus only the specific client and dashboard paths you approved. Verify the policies with a test pod from another namespace, since a CNI that does not enforce NetworkPolicy will silently allow everything.

Audit logging of job submissions

Job submissions are the record of who ran what code, on which hardware and with which data, so they belong in your audit trail. Enable Kubernetes API audit logging for changes to RayJob, RayCluster and RayService objects, and capture submissions made through the Ray job API, which may not appear in the Kubernetes audit log. Confirm where logs are retained, who can read them and how long they are kept under your own policy.

Upgrading Ray and KubeRay without interrupting jobs

The safe order is fixed: upgrade the Kubernetes cluster first, then the KubeRay operator, then the Ray images. Start with the control plane, because the Kubernetes version skew policy requires kube-apiserver to move one minor version at a time and before kube-controller-manager, kube-scheduler and kubelets. Confirm the current minor version and the supported target in the Kubernetes version skew policy before you schedule anything. Once the cluster is on a supported version, upgrade the KubeRay operator, which manages the RayCluster, RayJob and RayService custom resources. Check the KubeRay release notes for the Kubernetes versions it supports and for any CRD changes that must be applied first. Ray image changes come last, because they touch running workloads.

Ray image changes should never replace a running head or worker pod in place. For a RayService, change the Ray image in the spec and let the operator roll it out, but confirm the serve configuration is compatible with the new Ray version and that health checks pass on the new cluster before traffic shifts. For batch and training work, a RayJob will not survive a cluster replacement without help. Drain running RayJobs by letting active jobs finish or by scheduling the change in a quiet window, and make sure training code writes checkpoints to shared storage at a planned interval. Test restore from a checkpoint under the new Ray version in staging before relying on it in production.

Keep the previous Ray image in your registry and keep the prior RayCluster manifest in Git, so rollback means applying the old definition rather than rebuilding anything. Keep the old image pullable for as long as any job, checkpoint or serialized model still depends on it. Ask your platform team to confirm how long old images stay in the registry and who approves a rollback. For GPU node changes that happen in the same window, sequence them with the Kubernetes upgrades work and the GPU Operator driver upgrade so that no change lands on a node that is still running a job.

Questions teams ask before running Ray on Kubernetes

What drives the cost and effort of a KubeRay platform?

Cost follows the number of clusters, the GPU capacity they reserve, and the engineering time needed to run them. Costs fall into two groups. One-time costs include design, cluster and GPU node preparation, identity and storage integration, and the first set of Ray images and job templates. Recurring costs include GPU capacity, storage for checkpoints and datasets, monitoring, and the staff time spent on Ray and KubeRay version upgrades. The biggest factors are how many Ray versions must run side by side, whether autoscaling with GPUs is required, how many teams share the GPU pool, and whether inference (RayService) runs alongside training (RayJob). When requesting a quote, ask for the work split by RayCluster, RayJob and RayService, the upgrade effort assumed for each Ray version, and which items are one-time versus recurring. Confirm GPU and cloud costs separately, since they come from your own accounts and are not part of the services fee.

How long does a first KubeRay deployment usually take?

The duration depends mainly on how ready the underlying cluster already is, not on KubeRay itself. The main time drivers are GPU node readiness, including the driver and device plugin setup, the identity and secrets integration, the storage design for model weights and checkpoints, and how many workload types must be proven. A first deployment that targets one training workload on a cluster with working GPU support is far shorter than a platform that supports training, batch inference and online serving with several Ray versions. Approvals and security reviews often take longer than the technical build, so ask for a timeline that lists these dependencies separately. A written scope should name the milestones, the environments included (for example, staging and production) and the acceptance tests each milestone must pass before work continues.

What does the work need from our own team?

The work needs named people from your team who can make decisions and provide access. Typically this includes a platform owner for the Kubernetes clusters, someone who manages GPU nodes and drivers, an identity owner for SSO and group mapping, a storage owner for object and shared volumes, and a data or ML lead who defines the training and serving workloads. Your team should provide cluster access in your environment, container registry and image pull rights, a place for Ray images and model artifacts, and a decision on who approves changes to production. Plan for these people to be available during design reviews and acceptance testing. Ask the provider to state in writing which of these roles it expects you to fill and how many hours of availability it assumes each week.

Can an internal team run KubeRay alone after launch?

An internal team can run KubeRay alone if it already operates Kubernetes with GPU nodes and has someone who understands Ray's job and serving model. The operating load is shaped by the number of Ray versions, the frequency of cluster upgrades, and the on-call expectations for RayService endpoints. Teams often underestimate the operations of autoscaling GPU node pools, handling preempted or failed workers, and diagnosing jobs that stall because of scheduling. Before deciding, check whether your team has the Kubernetes skills to maintain the operator, the monitoring to see Ray dashboards and GPU metrics, and the runbooks for restarting head nodes and recovering checkpoints. A fixed-scope handover with documented runbooks and a retainer for upgrades is one way to close that gap. DeployOpen plans, implements, documents and supports self-hosted platforms in your infrastructure, and support terms are agreed in writing.

How do upgrades affect running training jobs?

Upgrades can interrupt running training jobs, so the plan should decide which changes are applied to live workloads and which wait for a job boundary. Upgrading the KubeRay operator, the Ray version, the container image or the GPU driver each carries a different risk. Changing a Ray version normally means the RayJob must restart on new images, so jobs without checkpoints lose progress. Kubernetes itself follows a version skew policy that limits which component versions can run together, so cluster upgrades must be sequenced with the operator's supported versions. Good practice is to write checkpoints to durable storage at a set interval, to run each Ray version in its own RayCluster or namespace until jobs finish, and to upgrade inference (RayService) with rolling replacement. Ask the provider for an upgrade runbook that states how each component is tested and how a failed upgrade is rolled back.

When do we need Kueue or gang scheduling for Ray?

You need Kueue when several teams compete for a shared GPU pool and need fair queueing, quotas or preemption, and you need gang scheduling when a Ray cluster can deadlock if only some of its pods start. Ray workers depend on a head node and on each other, so a partially scheduled cluster can hold GPUs without making progress. Kueue admits whole workloads against queues and resource flavors, which helps when GPU demand exceeds supply. Gang scheduling makes sure all required pods start together. A single team running one RayJob at a time on a dedicated pool may need neither. Ask for a scheduling design that names the queues, quotas, priority classes and how preemption interacts with checkpointing, and confirm which integration with Kueue your chosen KubeRay version supports.

How DeployOpen scopes and delivers KubeRay platforms

DeployOpen plans, implements, hardens, documents and supports self-hosted open-source platforms inside your own infrastructure, including Ray clusters on Kubernetes managed with KubeRay. Each engagement starts from a written scope that sets out which Ray workloads run, where they run and who operates them afterward.

How we scope

  • Inventory the training and batch inference workloads that will run on RayCluster, RayJob and RayService resources
  • Confirm GPU node pools, accelerator types, and which Ray versions each team must run side by side
  • Agree in writing how autoscaling, identity integration, storage and etcd backups are covered before work starts

How we build

  • Install the KubeRay operator and Ray images from a registry you control, including air-gapped mirrors where required
  • Configure GPU scheduling, autoscaler limits and resource requests against the node pools you have agreed
  • Test job submission, failover and version upgrades in a staging cluster before anything reaches production

How we hand over

  • Deliver the architecture record, configuration as code, and runbooks for submitting jobs and rolling Ray versions
  • Walk your platform and data science teams through the operating model and the verification steps they will repeat
  • Document open items, known limits and the upgrade plan so your team can run the platform without DeployOpen

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers after handover
  • Retainers can cover KubeRay and Ray version upgrades, autoscaling changes and periodic restore tests
  • Confirm response expectations and included upgrade work in the retainer agreement, since these are set per engagement

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.