赞
踩
使用Kuberay Operator是官方推荐的方式,operator 提供了一种k8s原生方式的管理ray集群的方法
在这个部分,我们可以学习到:
1)安装以及部署
注意事项:我之前部署Ray 的时候有可能用的就是较早版本的 Kuberay operator
1)前置工作:在本地机器上安装对应版本的 Ray release,安装kubectl,并能访问到k8s集群
2)首先部署 kuberay operator:一个用来创建以及管理ray集群的特殊pod
a)根据配置文件部署 kuberay operator 请查看下面的通过 Helm方式 的部署
# 注意 create 不能用 apply 代替,issue问题已提出
# 也可以通过下载 kuberay git 仓库,找到 kuberay operator 的配置文件来部署
# default 文件夹下的 Namespace.yaml 与 kustomization 文件可以自定义 K8s 中 命名空间的名称,默认为 ray-system
! kubectl create -k "github.com/ray-project/kuberay/ray-operator/config/default?ref=v0.4.0&timeout=90s"
# 检查 kuberay-operator 已经成功运行
! kubectl -n ray-system get pod --selector=app.kubernetes.io/component=kuberay-operator
a)使用 Helm 部署
version 1.0.0
版本的$ helm repo add kuberay https://ray-project.github.io/kuberay-helm/
$ helm repo update
# 记得先创建好自己所需要的命名空间:namespace
$ helm install kuberay-operator kuberay/kuberay-operator --version 1.0.0 --namespace ray-system
3)部署 Ray 集群
1)kuberay operator已成功执行,现在可以通过它来部署一个简单的 ray cluster
# Deploy a sample Ray Cluster CR from the KubeRay repo:
# 这个配置文件同样可以在 kuberay git 仓库中找到
$ kubectl -n ray-system apply -f https://raw.githubusercontent.com/ray-project/kuberay/master/ray-operator/config/samples/ray-cluster.autoscaler.yaml
# This Ray cluster is named `raycluster-autoscaler` because it has optional Ray Autoscaler support enabled.
2)自定义YAML配置文件部署ray集群
# 下载 kuberay 对应 git 仓库
$ git clone https://github.com/ray-project/kuberay.git
# checkout 到你想使用的 kuberay release 版本,或者不切换使用最新版本,这里我切换到 release1.0
$ cd ./kuberay
$ git checkout dcb5d3d
# 切换到官方给出的 sample YAML配置文件夹
$ cd ./ray-operator/config/samples/
# 通过kubectl apply 方式部署,可以自定义 YAML 配置文件的配置项
$ kubectl apply -f ray-cluster.autoscaler.yaml --namespace ray-system
# 等待一段时间,查看部署状态
$ kubectl get pods -o wide -n ray-system
$ kubectl get svc -o wide -n ray-system
4)在Ray集群上运行 Ray应用:
a)直接使用 kubect exec 命令在 pod 内执行
# Substitute your output from the last cell in place of "raycluster-autoscaler-head-xxxxx"
$ kubectl exec raycluster-autoscaler-head-xxxxx -it -c ray-head -n ray-system -- python -c "import ray; ray.init()"
# 2022-08-10 11:23:17,093 INFO worker.py:1312 -- Connecting to existing Ray cluster at address: <IP address>:6379...
# 2022-08-10 11:23:17,097 INFO worker.py:1490 -- Connected to Ray cluster.
ray.init()
初始化包含的环节以后详细分析b)通过 Ray Job Submission的方式
# 首先对主节点的端口进行转发,端口转发时记得不要退出
# Execute this in a separate shell.
$ kubectl port-forward service/raycluster-autoscaler-head-svc 8265:8265 -n ray-system
# 然后在本地拥有 ray release 的地方提交 ray 代码
# The following job's logs will show the Ray cluster's total resource capacity, including 3 CPUs.
$ ray job submit --address http://localhost:8265 -- python -c "import ray; ray.init(); print(ray.cluster_resources())"
# 或者提交你自己的本地 ray_example.py 脚本
$ ray job submit --address http://localhost:8265 --working-dir . -- python remote_function.py
c)连接到 ray head 或 worker 节点内部,查看节点内部情况
# 记得 xxxx 处改为你自己的 head pod实际名称对应
# worker pod一样,只是worker pod中只用一个container,因此不需要再指定container了,去掉 --container ray-head 即可
$ sudo kubectl exec -it raycluster-autoscaler-head-xxxxx --container ray-head -n ray-system -- /bin/bash
5)清理工作:卸载Ray集群、kubera operator以及相关资源
清理工作如下:
# 先清理 Ray 集群
# Delete by reference to the RayCluster custom resource
$ kubectl delete raycluster raycluster-autoscaler -n ray-system
# 或者使用 创建Ray集群时所使用的 YAML 文件清楚
$ kubectl delete -f samples/xxx.yaml -n ray-system
# 然后清理删除 kuberay operator
# 使用 helm uninstall 即可
$ helm uninstall [your-release-name]
pod 扩容过程:
replicas
field.replicas
specification.建议:
扩缩容速度:
autoscalerOptions
field来控制扩缩容的速度,它包含有两个子fields
upscalingMode
:
idleTimeoutSeconds
:default 60s,60s 没有任何 tasks、actors、objects任务就可以缩容Ray Autoscaler vs. Horizontal Pod Autoscaler
Ray Autoscaler 与 K8s Cluster Autoscaler的关系
与 Vertical Pod Autoscaler 的关系 VPA
可以在本地 通过 Ray job submit 的方式将本地的 scripts 项目提交至 Ray 集群中执行
$ ray job submit --address http://localhost:8265 --working-dir your_working_directory -- python script.py
hello world
in this case). Ray will also make the contents of the directory passed as --working-dir
available to the Ray job by downloading the directory to all nodes in your cluster.Warning:
ray job submit --runtime-env=...
or JobSubmissionClient.submit_job(runtime_env=...)
), not via ray.init(runtime_env=...)
in the driver script.Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。