From 8f6bd6cece11d799ecdd185d82ec48bb9ad21302 Mon Sep 17 00:00:00 2001 From: Rong Ou Date: Wed, 30 Jan 2019 17:50:37 -0800 Subject: [PATCH] change kubernetes examples to use `Deployment` (#3909) --- doc/source/deploy-on-kubernetes.rst | 48 ++++++++++++++++------------- kubernetes/example.py | 4 ++- kubernetes/head.yaml | 12 ++++---- kubernetes/submit.yaml | 23 +++++++------- kubernetes/worker.yaml | 11 ++++--- 5 files changed, 54 insertions(+), 44 deletions(-) diff --git a/doc/source/deploy-on-kubernetes.rst b/doc/source/deploy-on-kubernetes.rst index baaee56f3..117b0be77 100644 --- a/doc/source/deploy-on-kubernetes.rst +++ b/doc/source/deploy-on-kubernetes.rst @@ -35,17 +35,17 @@ minutes for the pods to enter the "Running" state). .. code-block:: shell $ kubectl get pods - NAME READY STATUS RESTARTS AGE - ray-head-controller-2kkfq 1/1 Running 0 47s - ray-worker-controller-d6jml 1/1 Running 0 45s - ray-worker-controller-m7jxs 1/1 Running 0 45s - ray-worker-controller-rg2sl 1/1 Running 0 45s + NAME READY STATUS RESTARTS AGE + ray-head-5455bb66c9-6bxvz 1/1 Running 0 10s + ray-worker-5c49b7cc57-c6xs8 1/1 Running 0 5s + ray-worker-5c49b7cc57-d9m86 1/1 Running 0 5s + ray-worker-5c49b7cc57-kzk4s 1/1 Running 0 5s To run tasks interactively on the cluster, connect to one of the pods, e.g., .. code-block:: shell - kubectl exec -it ray-head-controller-2kkfq -- bash + kubectl exec -it ray-head-5455bb66c9-6bxvz -- bash Start an IPython interpreter, e.g., ``ipython`` @@ -56,7 +56,9 @@ Start an IPython interpreter, e.g., ``ipython`` import time import ray - ray.init(redis_address="{}:6379".format(socket.gethostbyname("ray-head"))) + # Note that if you run this script on a non-head node, then you must replace + # "localhost" with socket.gethostbyname("ray-head"). + ray.init(redis_address="localhost:6379") @ray.remote def f(x): @@ -86,24 +88,28 @@ running ``kubectl get all``. You'll see output like the following. .. code-block:: shell $ kubectl get all - NAME READY STATUS RESTARTS AGE - pod/ray-head-controller-q6lck 1/1 Running 0 1m - pod/ray-worker-controller-kchfh 1/1 Running 0 1m - pod/ray-worker-controller-nmq5c 1/1 Running 0 1m - pod/ray-worker-controller-tfl2q 1/1 Running 0 1m + NAME READY STATUS RESTARTS AGE + pod/ray-head-5486648dc9-c6hz2 1/1 Running 0 11s + pod/ray-worker-5c49b7cc57-2jz4l 1/1 Running 0 11s + pod/ray-worker-5c49b7cc57-8nwjk 1/1 Running 0 11s + pod/ray-worker-5c49b7cc57-xlksn 1/1 Running 0 11s - NAME DESIRED CURRENT READY AGE - replicationcontroller/ray-head-controller 1 1 1 1m - replicationcontroller/ray-worker-controller 3 3 3 1m + NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE + service/ray-head ClusterIP 10.110.54.241 6379/TCP,6380/TCP,6381/TCP,12345/TCP,12346/TCP 11s - NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE - service/ray-head ClusterIP 10.64.5.153 6379/TCP,6380/TCP,6381/TCP,12345/TCP,12346/TCP 1m + NAME READY UP-TO-DATE AVAILABLE AGE + deployment.apps/ray-head 1/1 1 1 11s + deployment.apps/ray-worker 3/3 3 3 11s -Find the name of the ``ray-head-controller`` pod and run the equivalent of + NAME DESIRED CURRENT READY AGE + replicaset.apps/ray-head-5486648dc9 1 1 1 11s + replicaset.apps/ray-worker-5c49b7cc57 3 3 3 11s + +Find the name of the ``ray-head`` pod and run the equivalent of .. code-block:: shell - kubectl logs ray-head-controller-q6lck + kubectl logs ray-head-5486648dc9-c6hz2 Cleaning Up ----------- @@ -113,8 +119,8 @@ To remove the services you have created, run the following. .. code-block:: shell kubectl delete service/ray-head \ - replicationcontroller/ray-head-controller \ - replicationcontroller/ray-worker-controller + deployment.apps/ray-head \ + deployment.apps/ray-worker Customization diff --git a/kubernetes/example.py b/kubernetes/example.py index b18ee6451..b5097ddd9 100644 --- a/kubernetes/example.py +++ b/kubernetes/example.py @@ -9,7 +9,9 @@ import time import ray if __name__ == "__main__": - ray.init(redis_address="{}:6379".format(socket.gethostbyname("ray-head"))) + # Note that if you run this script on a non-head node, then you must + # replace "localhost" with socket.gethostbyname("ray-head"). + ray.init(redis_address="localhost:6379") # Wait for all 4 nodes to join the cluster. while True: diff --git a/kubernetes/head.yaml b/kubernetes/head.yaml index c30f43c75..7274f01b7 100644 --- a/kubernetes/head.yaml +++ b/kubernetes/head.yaml @@ -3,7 +3,6 @@ kind: Service metadata: name: ray-head spec: - ports: ports: - name: redis-primary port: 6379 @@ -23,14 +22,15 @@ spec: selector: component: ray-head --- -apiVersion: v1 -kind: ReplicationController +apiVersion: apps/v1 +kind: Deployment metadata: - name: ray-head-controller + name: ray-head spec: replicas: 1 selector: - component: ray-head + matchLabels: + component: ray-head template: metadata: labels: @@ -54,4 +54,4 @@ spec: fieldPath: status.podIP resources: requests: - cpu: 10 + cpu: 2 diff --git a/kubernetes/submit.yaml b/kubernetes/submit.yaml index 52e8c1b1c..76e5718c3 100644 --- a/kubernetes/submit.yaml +++ b/kubernetes/submit.yaml @@ -3,7 +3,6 @@ kind: Service metadata: name: ray-head spec: - ports: ports: - name: redis-primary port: 6379 @@ -23,14 +22,15 @@ spec: selector: component: ray-head --- -apiVersion: v1 -kind: ReplicationController +apiVersion: apps/v1 +kind: Deployment metadata: - name: ray-head-controller + name: ray-head spec: replicas: 1 selector: - component: ray-head + matchLabels: + component: ray-head template: metadata: labels: @@ -57,16 +57,17 @@ spec: fieldPath: status.podIP resources: requests: - cpu: 10 + cpu: 2 --- -apiVersion: v1 -kind: ReplicationController +apiVersion: apps/v1 +kind: Deployment metadata: - name: ray-worker-controller + name: ray-worker spec: replicas: 3 selector: - component: ray-worker + matchLabels: + component: ray-worker template: metadata: labels: @@ -87,4 +88,4 @@ spec: fieldPath: status.podIP resources: requests: - cpu: 10 + cpu: 2 diff --git a/kubernetes/worker.yaml b/kubernetes/worker.yaml index c4d9204eb..cebf6d9b9 100644 --- a/kubernetes/worker.yaml +++ b/kubernetes/worker.yaml @@ -1,11 +1,12 @@ -apiVersion: v1 -kind: ReplicationController +apiVersion: apps/v1 +kind: Deployment metadata: - name: ray-worker-controller + name: ray-worker spec: replicas: 3 selector: - component: ray-worker + matchLabels: + component: ray-worker template: metadata: labels: @@ -26,4 +27,4 @@ spec: fieldPath: status.podIP resources: requests: - cpu: 10 + cpu: 2