4
0

More than 1 year has passed since last update.

ローカルのKubernetesでRayクラスター作成

Last updated at Posted at 2022-01-04

概要

ローカルのKubernetes上、すなわちMinikubeで作成したKubernetesクラスター上にRay clusterをデプロイして、Ray cluster上でJupyter notebookが利用できる環境を構築する。

参考

前提

  • Windows 10 Home
  • WSLのUbuntuディストリビューション(Ubuntu20.04)がインストール済み
    • Ubuntu18.04だと最新のRayがインストールできないので20.04を利用する
  • AWSのIAMユーザアカウント作成済み(アクセスキーとシークレットキーが手元にある)
  • Docker-desktopをインストール済み

手順

1. Rayインストール

$ sudo apt-get update
$ sudo apt-get install python3
$ sudo apt install python3-pip
$ pip3 install -U "ray[default]" boto3

ここでWSLを再起動する。

2. helmインストール

$ curl -O https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
$ bash ./get-helm-3
$ helm version

'helm version'でバージョンが確認できれば正常にインストールされている。

3. Ray Helm Chartをダウンロード

$ git clone https://github.com/ray-project/ray.git

4. minikubeインストール & 起動

$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
$ chmod +x minikube
$ sudo install minikube /usr/local/bin/
$ minikube start --driver=docker

5. Rayクラスターの起動

$ cd ray/deploy/charts
$ helm -n ray install example-cluster --create-namespace ./ray

インストールしたリソースを見ていく。

# カスタムリソースrayClusterのステータスを確認
$ kubectl -n ray get rayCluster
NAME              STATUS    RESTARTS   AGE
example-cluster   Running   0          53s

# PodとしてRay Head nodeとRay Worker nodeがデプロイされていることを確認
# Head nodeが1つ、Worker nodeが2つ
# Pod個数を変更するには、~/ray/deploy/charts/ray/values.yamlのminWorkersとmaxWorkersの設定値を変更する
$ kubectl -n ray get pods
NAME                                    READY   STATUS    RESTARTS   AGE
example-cluster-ray-head-type-5926k     1/1     Running   0          57s
example-cluster-ray-worker-type-8gbwx   1/1     Running   0          40s
example-cluster-ray-worker-type-l6cvx   1/1     Running   0          40s

# Head nodeを公開するためのService (ClusterIP)
$ kubectl -n ray get service
NAME                       TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                       AGE
example-cluster-ray-head   ClusterIP   10.8.11.17   <none>        10001/TCP,8265/TCP,8000/TCP   115s

# The operator deployment.
# By default, the deployment is launched in namespace "default".
$ kubectl get deployment ray-operator
NAME           READY   UP-TO-DATE   AVAILABLE   AGE
ray-operator   1/1     1            1           3m1s

# The single pod of the operator deployment.
$ kubectl get pod -l cluster.ray.io/component=operator
NAME                            READY   STATUS    RESTARTS   AGE
ray-operator-84f5d57b7f-xkvtm   1/1     Running   0          3m35

# The Custom Resource Definition defining a RayCluster.
$ kubectl get crd rayclusters.cluster.ray.io
NAME                         CREATED AT
rayclusters.cluster.ray.io   2021-05-14T18:44:02

6. Jupyter notebookの起動

$ kubectl -n ray exec -it service/example-cluster-ray-head -- bash
$ pip3 install notebook
$ jupyter notebook --ip=* --no-browser --port 8000

別のUbuntuを開く。

$ kubectl -n ray port-forward service/example-cluster-ray-head 8000:8000

7.ブラウザでJupyter notebookにアクセス

ブラウザで以下にアクセスする。Jupyter notebook起動時に表示されたtokenを入力してJupyter notebookにログインする。

http://localhost:8000/

あとはJupyter notebookを使ってRayを試すことができます。

8. 削除

使い終わったら削除を忘れずに。

# まずカスタムリソースrayClusterの「example-cluster」を削除
$ kubectl -n ray delete raycluster example-cluster

# 次に「example-cluster」をアンインストール
$ helm -n ray uninstall example-cluster
release "example-cluster" uninstalled

# 最後にネームスペースrayを削除
$ kubectl delete namespace ray
namespace "ray" deleted
4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0