运行 RayCluster

在 Kueue 上运行 RayCluster。

此页面展示了在运行 RayCluster 时如何利用 Kueue 的调度和资源管理功能。

本指南适用于对 Kueue 有基本了解的 批处理用户。有关更多信息,请参阅 Kueue 概述

开始之前

  1. 确保你使用 Kueue v0.6.0 或更新版本和 KubeRay 1.1.0 或更新版本。

  2. 查看 管理集群配额 了解 Kueue 初始设置的详细信息。

  3. 请参阅 KubeRay 安装 了解 KubeRay 的安装和配置详细信息。

RayCluster 定义

在 Kueue 上运行 RayCluster 时,请考虑以下方面

a. 队列选择

目标 本地队列 应在 RayCluster 配置的 metadata.labels 部分中指定。

metadata:
  name: raycluster-sample
  namespace: default
  labels:
    kueue.x-k8s.io/queue-name: local-queue

b. 配置资源需求

工作负载的资源需求可以在 spec 中配置。

    headGroupSpec:
       spec:
        affinity: {}
        containers:
        - env: []
          image: rayproject/ray:2.7.0
          imagePullPolicy: IfNotPresent
          name: ray-head
          resources:
            limits:
              cpu: "1"
              memory: 2G
            requests:
              cpu: "1"
              memory: 2G
          securityContext: {}
          volumeMounts:
          - mountPath: /tmp/ray
            name: log-volume
    workerGroupSpecs:
      template:
        spec:
          affinity: {}
          containers:
          - env: []
          image: rayproject/ray:2.7.0
          imagePullPolicy: IfNotPresent
          name: ray-worker
          resources:
            limits:
            cpu: "1"
            memory: 1G
            requests:
            cpu: "1"
            memory: 1G

请注意,RayCluster 在存在期间会保留资源配额。为了优化资源管理,你应该删除不再使用的 RayCluster。

c. 限制

  • 受限工作组:由于 Kueue 工作负载最多可包含 8 个 PodSet,因此 spec.workerGroupSpecs 的最大数量为 7
  • 禁用树内自动缩放:Kueue 管理 RayCluster 的资源分配;因此,需要禁用集群的内部自动缩放机制

示例 RayCluster

RayCluster 如下所示

apiVersion: ray.io/v1
kind: RayCluster
metadata:
  name: raycluster-sample
  namespace: default
  labels:
    kueue.x-k8s.io/queue-name: local-queue
spec:
  headGroupSpec:
    rayStartParams:
      dashboard-host: 0.0.0.0
    serviceType: ClusterIP
    template:
      metadata:
        annotations: {}
      spec:
        affinity: {}
        containers:
        - env: []
          image: rayproject/ray:2.7.0
          imagePullPolicy: IfNotPresent
          name: ray-head
          resources:
            limits:
              cpu: "1"
              memory: 2G
            requests:
              cpu: "1"
              memory: 2G
          securityContext: {}
          volumeMounts:
          - mountPath: /tmp/ray
            name: log-volume
        imagePullSecrets: []
        nodeSelector: {}
        tolerations: []
        volumes:
        - emptyDir: {}
          name: log-volume
  workerGroupSpecs:
  - groupName: workergroup
    maxReplicas: 10
    minReplicas: 1
    rayStartParams: {}
    replicas: 4
    template:
      metadata:
        annotations: {}
      spec:
        affinity: {}
        containers:
        - env: []
          image: rayproject/ray:2.7.0
          imagePullPolicy: IfNotPresent
          name: ray-worker
          resources:
            limits:
              cpu: "1"
              memory: 1G
            requests:
              cpu: "1"
              memory: 1G
          securityContext: {}
          volumeMounts:
          - mountPath: /tmp/ray
            name: log-volume
        imagePullSecrets: []
        nodeSelector: {}
        tolerations: []
        volumes:
        - emptyDir: {}
          name: log-volume

你可以使用 CLI 提交 Ray 作业,或登录 Ray Head 并按照此 示例 使用 kind 集群执行作业。