-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ray start block in Pod's entrypoint (#77)
* use ray start block Signed-off-by: chenk008 <[email protected]> * add block into rayStartParams * fix ut * add block in sample config * add sample without block Co-authored-by: wuhua.ck <[email protected]>
- Loading branch information
Showing
7 changed files
with
149 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
ray-operator/config/samples/ray-cluster.without-block.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
apiVersion: ray.io/v1alpha1 | ||
kind: RayCluster | ||
metadata: | ||
labels: | ||
controller-tools.k8s.io: "1.0" | ||
# An unique identifier for the head node and workers of this cluster. | ||
name: raycluster-non-block | ||
spec: | ||
rayVersion: '1.8.0' # should match the Ray version in the image of the containers | ||
######################headGroupSpecs################################# | ||
# head group template and specs, (perhaps 'group' is not needed in the name) | ||
headGroupSpec: | ||
# Kubernetes Service Type, valid values are 'ClusterIP', 'NodePort' and 'LoadBalancer' | ||
serviceType: ClusterIP | ||
# the pod replicas in this group typed head (assuming there could be more than 1 in the future) | ||
replicas: 1 | ||
# logical group name, for this called head-group, also can be functional | ||
# pod type head or worker | ||
# rayNodeType: head # Not needed since it is under the headgroup | ||
# the following params are used to complete the ray start: ray start --head --block --redis-port=6379 ... | ||
rayStartParams: | ||
port: '6379' # should match headService targetPort | ||
object-manager-port: '12345' | ||
node-manager-port: '12346' | ||
object-store-memory: '100000000' | ||
redis-password: 'LetMeInRay' | ||
dashboard-host: '0.0.0.0' | ||
num-cpus: '1' # can be auto-completed from the limits | ||
node-ip-address: $MY_POD_IP # auto-completed as the head pod IP | ||
#pod template | ||
template: | ||
metadata: | ||
labels: | ||
# custom labels. NOTE: do not define custom labels start with `raycluster.`, they may be used in controller. | ||
# Refer to https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ | ||
rayCluster: raycluster-sample # will be injected if missing | ||
rayNodeType: head # will be injected if missing, must be head or wroker | ||
groupName: headgroup # will be injected if missing | ||
# annotations for pod | ||
annotations: | ||
key: value | ||
spec: | ||
containers: | ||
- name: ray-head | ||
image: rayproject/ray:1.8.0 | ||
# Without the `--block` flag, you can have any command and args here to run your code. | ||
# the below command/args will be appended after the Ray start command and it args, and executed after Ray start. | ||
command: [ "python" ] | ||
args: | ||
- '/opt/sample_code.py' | ||
env: | ||
- name: MY_POD_IP | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: status.podIP | ||
ports: | ||
- containerPort: 6379 | ||
volumeMounts: | ||
- mountPath: /opt | ||
name: config | ||
volumes: | ||
# You set volumes at the Pod level, then mount them into containers inside that Pod | ||
- name: config | ||
configMap: | ||
# Provide the name of the ConfigMap you want to mount. | ||
name: ray-code-single | ||
# An array of keys from the ConfigMap to create as files | ||
items: | ||
- key: sample_code.py | ||
path: sample_code.py | ||
######################Ray code sample################################# | ||
# this is only an example code that is mounted into the container and executed to show the Ray cluster at work | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: ray-code-single | ||
data: | ||
sample_code.py: | | ||
import ray | ||
from os import environ | ||
redis_pass = environ.get("REDIS_PASSWORD") | ||
print("trying to connect to Ray!") | ||
ray.init(address="auto", _redis_password=redis_pass) | ||
print("now executing some code with Ray!") | ||
import time | ||
start = time.time() | ||
@ray.remote | ||
def f(): | ||
time.sleep(0.01) | ||
return ray._private.services.get_node_ip_address() | ||
values=set(ray.get([f.remote() for _ in range(1000)])) | ||
print("Ray Nodes: ",str(values)) | ||
file = open("/tmp/ray_nodes.txt","a") | ||
file.write("available nodes: %s\n" % str(values)) | ||
file.close() | ||
end = time.time() | ||
print("Execution time = ",end - start) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters