Skip to content

[DOCS] KubeRay APIServer V2 document #3594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions apiserversdk/Installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# KubeRay APIServer Installation

## Step 1: Create a Kubernetes cluster

This step creates a local Kubernetes cluster using [Kind](https://kind.sigs.k8s.io/). If you already have a Kubernetes
cluster, you can skip this step.

```sh
kind create cluster --image=kindest/node:v1.26.0
```

## Step 2: Deploy a KubeRay operator

Follow [this
document](https://docs.ray.io/en/latest/cluster/kubernetes/getting-started/kuberay-operator-installation.html#kuberay-operator-deploy)
to install the latest stable KubeRay operator from the Helm repository.

## Step 3: Install APIServer with Helm

```sh
helm repo add kuberay https://ray-project.github.io/kuberay-helm/
helm repo update
# Install KubeRay APIServer
helm install kuberay-apiserver kuberay/kuberay-apiserver --version 1.4.0
```

## Step 4: Validate installation

Check that the KubeRay APIServer is running in the "default" namespaces.

```sh
kubectl get pods
# NAME READY STATUS RESTARTS AGE
# kuberay-apiserver-xxxxxx 1/1 Running 0 17s
```
76 changes: 76 additions & 0 deletions apiserversdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# KubeRay APIServer

The KubeRay APIServer provides an HTTP proxy to the Kubernetes APIServer with the same
interface. Users can directly use the Kubernetes OpenAPI Spec and KubeRay CRD to create, query,
update, and delete Ray resources. It contains the following highlighted features:

1. Compatibility with existing Kubernetes clients and API interfaces, allowing users to use
existing Kubernetes clients to interact with the proxy provided by the APIServer.
2. Provides the APIServer as a Go library for users to build their proxies with custom HTTP middleware functions.

## When to use APIServer

Consider using the APIServer if:

- You want to manage Ray clusters in Kubernetes via HTTP/REST (e.g., from a UI, SDK, or CLI).
- You want to create templates or default values to simplify configuration setup.

## Installation

Please follow the [Installation](./Installation.md) guide to install the APIServer.

## Quick Start

- [RayCluster Quickstart](./docs/raycluster-quickstart.md)
- [RayJob Quickstart](./docs/rayjob-quickstart.md)
- [RayService Quickstart](./docs/rayservice-quickstart.md)

## Usage

The KubeRay APIServer exposes a RESTful API that mirrors the Kubernetes APIServer. You
can interact with it using Kubernetes-style endpoints and request patterns to create,
retrieve, update, and delete custom resources such as `RayCluster` and `RayJob`.

### API Structure

The KubeRay API follows standard Kubernetes conventions. The structure of the endpoint
path depends on whether you are interacting with custom resources (e.g., `RayCluster`) or
core Kubernetes resources.

#### Custom Resources

For custom resources defined by CRDs (e.g., `RayCluster`, `RayJob`, etc.), the endpoint format is:

```sh
<baseURL>/apis/ray.io/v1/namespaces/<namespace>/<resourceType>/<resourceName>
```

- `namespace`: Your target Kubernetes namespace (e.g., `default`)
- `resourceType`: Custom resource type (e.g., `rayclusters`, `rayjobs`, `rayservices`)
- `resourceName`: Name of the resource.

### Label and Field Selectors

When listing resources (using `GET` on a collection endpoint), you can filter results using selectors:

- Label selector: filters resources by their labels.

```sh
# Get all RayClusters with the label key=value
GET /apis/ray.io/v1/namespaces/default/rayclusters?labelSelector=key%3Dvalue
```

- Field selector: Filters resources based on the value of their resource
fields (e.g., `metadata.name`, `status.phase`).

```sh
# Retrieve the RayCluster where the name is raycluster-prod
GET /apis/ray.io/v1/namespaces/default/rayclusters?fieldSelector=metadata.name%3Draycluster-prod
```

- Combined selectors: You can combine label and field selectors using `&`

```sh
# Get the RayCluster named raycluster-prod that also has the label env=prod.
GET /apis/ray.io/v1/namespaces/default/rayclusters?labelSelector=env%3Dprod&fieldSelector=metadata.name%3Draycluster-prod
```
92 changes: 92 additions & 0 deletions apiserversdk/docs/raycluster-quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# RayCluster QuickStart

This document focuses on explaining how to manage and interact with RayCluster using the
KubeRay APIServer. For a detailed introduction and more advanced usage with Kubernetes,
please refer to [this
guide](https://docs.ray.io/en/latest/cluster/kubernetes/getting-started/raycluster-quick-start.html).

## Preparation

- Install [Helm](https://helm.sh/docs/intro/install/) (>= v3.4),
[Kind](https://kind.sigs.k8s.io/docs/user/quick-start/#installation), and
[Docker](https://docs.docker.com/engine/install/).
- KubeRay v1.4.0 or higher and Ray 2.41.0.
- Make sure your Kubernetes cluster has at least 4 CPU and 4 GB RAM.

## Step 1: Create a Kubernetes cluster

This step creates a local Kubernetes cluster using [Kind](https://kind.sigs.k8s.io/). If you already have a Kubernetes
cluster, you can skip this step.

```sh
kind create cluster --image=kindest/node:v1.26.0
```

## Step 2: Install KubeRay operator and APIServer

Follow [Installation Guide](../Installation.md) to install the latest stable KubeRay operator and APIServer
from the Helm repository.

## Step 3: Deploy a RayCluster custom resource

Once the KubeRay operator is running, you are ready to deploy a RayCluster. While we are using APIServer, we can do this
with curl. The following command will create a RayCluster CR named `raycluster-kuberay` in your current cluster:

```sh
curl -s https://raw.githubusercontent.com/ray-project/kuberay/master/ray-operator/config/samples/ray-cluster.sample.yaml | \
curl -X POST http://localhost:31888/apis/ray.io/v1/namespaces/default/rayclusters \
-H "Content-Type: application/yaml" \
--data-binary @-
```

Once the RayCluster CR has been created, you can view its details by executing the following command:

```sh
curl http://localhost:31888/apis/ray.io/v1/namespaces/default/rayclusters/raycluster-kuberay
```

## Step 4: Modify Created RayCluster

To modify the created RayCluster, we can use the `PATCH` method of the KubeRay APIServer.
The following command adds an `annotation` to the raycluster-kuberay resource:

```sh
curl -X PATCH 'http://localhost:31888/apis/ray.io/v1/namespaces/default/rayclusters/raycluster-kuberay' \
-H 'Content-Type: application/merge-patch+json' \
--data '{
"metadata": {
"annotations": {
"example.com/purpose": "model-training"
}
}
}'
```

You can verify if the `annotation` is added with the following command. You should see the
annotations you added in the output:

```sh
curl -s http://localhost:31888/apis/ray.io/v1/namespaces/default/rayclusters/raycluster-kuberay \
| jq '.metadata.annotations'
```

## Step 5: Delete the RayCluster

To delete the RayCluster with KubeRay APIServer, execute the following command. The `raycluster-kuberay` is the name of
the RayCluster that we created earlier:

```sh
curl -X DELETE 'localhost:31888/apis/ray.io/v1/namespaces/default/rayclusters/raycluster-kuberay'
```

You can then verify if the RayCluster is removed. The following command should return 404:

```sh
curl -s http://localhost:31888/apis/ray.io/v1/namespaces/default/rayclusters/raycluster-kuberay
```

## Clean up

```sh
kind delete cluster
```
69 changes: 69 additions & 0 deletions apiserversdk/docs/rayjob-quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# RayJob QuickStart

RayJob automatically creates the RayCluster, submits the job when ready, and can
optionally delete the RayCluster after the job finishes. This document focus on explaining
how to manage and interact with RayJob using the KubeRay APIServer. For detailed
introduction and more advanced usage with Kubernetes, please refer to [this
guide](https://docs.ray.io/en/latest/cluster/kubernetes/getting-started/rayjob-quick-start.html).

## Preparation

- Install [Helm](https://helm.sh/docs/intro/install/) (>= v3.4),
[Kind](https://kind.sigs.k8s.io/docs/user/quick-start/#installation), and
[Docker](https://docs.docker.com/engine/install/).
- KubeRay v1.4.0 or higher and Ray 2.41.0.

## Step 1: Create a Kubernetes cluster

This step creates a local Kubernetes cluster using [Kind](https://kind.sigs.k8s.io/). If you already have a Kubernetes
cluster, you can skip this step.

```sh
kind create cluster --image=kindest/node:v1.26.0
```

## Step 2: Install KubeRay operator and APIServer

Follow [Installation Guide](../Installation.md) to install the latest stable KubeRay operator and APIServer
from the Helm repository.

## Step 3: Install a RayJob

Once the KubeRay operator is running, we can install a RayJob through APIServer with
following command. This will create a RayJob named `rayjob-interactive-mode`:

```sh
curl -s https://raw.githubusercontent.com/ray-project/kuberay/master/ray-operator/config/samples/ray-job.interactive-mode.yaml \
| curl -X POST http://localhost:31888/apis/ray.io/v1/namespaces/default/rayjobs \
-H "Content-Type: application/yaml" \
--data-binary @-
```

## Step 4: Check RayJob Status

You can check the detail of the submitted RayJob by executing following command:

```sh
curl -s http://localhost:31888/apis/ray.io/v1/namespaces/default/rayjobs/rayjob-interactive-mode
```

## Step 5: Delete the RayJob

To delete the RayJob with KubeRay APIServer, execute the following command. The `rayjob-interactive-mode` is the name of
the RayJob we created.

```sh
curl -X DELETE 'localhost:31888/apis/ray.io/v1/namespaces/default/rayjobs/rayjob-interactive-mode'
```

You can then verify if the RayJob is removed. The following command should return 404:

```sh
curl -s http://localhost:31888/apis/ray.io/v1/namespaces/default/rayjobs/rayjob-interactive-mode
```

## Clean up

```sh
kind delete cluster
```
Loading
Loading