Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Inject cluster name as an environment variable into head and worker pods #928

Closed
1 of 2 tasks
JoshKarpel opened this issue Feb 24, 2023 · 8 comments · Fixed by #934
Closed
1 of 2 tasks
Assignees
Labels
enhancement New feature or request P1 Issue that should be fixed within a few weeks

Comments

@JoshKarpel
Copy link
Contributor

Search before asking

  • I had searched in the issues and found no similar feature requirement.

Description

The cluster name should be easily available from inside Kubernetes pods inside the cluster. An env var would be more convenient than e.g. a Ray API call, so that this would be available both from inside Python and from e.g. bash scripts.

Use case

I'd like to use the cluster name for namespacing extra information I'll be storing in an external Redis.

Related issues

No response

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!
@JoshKarpel JoshKarpel added the enhancement New feature or request label Feb 24, 2023
@kevin85421 kevin85421 added the P1 Issue that should be fixed within a few weeks label Feb 24, 2023
@kevin85421
Copy link
Member

@Yicheng-Lu-llll are you interested in this issue?

@Yicheng-Lu-llll
Copy link
Contributor

Sure

@Jeffwan Jeffwan added this to the v0.5.0 release milestone Feb 25, 2023
@Yicheng-Lu-llll
Copy link
Contributor

Yicheng-Lu-llll commented Feb 28, 2023

Hi @JoshKarpel, I would like to double-check if this is what you want.

image

@JoshKarpel
Copy link
Contributor Author

Oh, I think maybe that isn't what I meant, though that looks useful too. What I was thinking of was the same name that ends up getting used in keys for GCS Fault Tolerance with Redis, which is presumably uniquely generated across different instances of the cluster during e.g. a rolling deploy.

@Yicheng-Lu-llll
Copy link
Contributor

Yicheng-Lu-llll commented Mar 1, 2023

Oh, I think maybe that isn't what I meant, though that looks useful too. What I was thinking of was the same name that ends up getting used in keys for GCS Fault Tolerance with Redis, which is presumably uniquely generated across different instances of the cluster during e.g. a rolling deploy.

So, It is not the ray cluster name defined in ray cluster CR but the Redis's key? I am not sure if kuberay is able to get the Redis's key and make it as env var.

I wonder if you could give me an example so that I can better understand what env var you want.

@JoshKarpel
Copy link
Contributor Author

Oh, I think maybe that isn't what I meant, though that looks useful too. What I was thinking of was the same name that ends up getting used in keys for GCS Fault Tolerance with Redis, which is presumably uniquely generated across different instances of the cluster during e.g. a rolling deploy.

So, It is not the ray cluster name defined in ray cluster CR but the Redis's key? I am not sure if kuberay is able to get the Redis's key and make it as env var.

I wonder if you could give me an example so that I can better understand what env var you want.

What I'm looking for is a unique, cluster-global, cluster-instance-unique string that I can use to store information that should be namespaced to a particular instance of my Ray cluster. My assumption was that this was generated by KubeRay and was used as part of the prefix of the pod names, e.g. in https://ray-project.github.io/kuberay/guidance/rayservice/#run-an-example-cluster

$ kubectl get pods
NAME                                                      READY   STATUS    RESTARTS   AGE
rayservice-sample-raycluster-qd2vl-worker-small-group-bxpp6   1/1     Running   0          24m
rayservice-sample-raycluster-qd2vl-head-45hj4             1/1     Running   0          24m

the cluster name is rayservice-sample (https://github.com/ray-project/kuberay/blob/master/ray-operator/config/samples/ray_v1alpha1_rayservice.yaml#L8), but the qd2vl fragment in the middle is what uniquely identifies the pods belonging to this cluster (for example, during a rolling deploy, the new instance would have a different random fragment there). I was hoping to get that fragment qd2vl, or whatever is readily available that contains it (maybe the entire rayservice-sample-raycluster-qd2vl prefix? or just raycluster-qd2vl?) as an environment variable so that I can piggy-back on that unique identifier.

I was also assuming in my previous message that this string was used as part of the namespace key for GCS Fault Tolerance to prevent state from leaking between clusters, but I don't actually know that - sorry if that was misleading.

@Yicheng-Lu-llll
Copy link
Contributor

Yicheng-Lu-llll commented Mar 1, 2023

Hi @JoshKarpel, I get your idea, thank you for explaining! #934 actually meet your need.

In your case, rayservice name is rayservice-sample and raycluster name is rayservice-sample-raycluster-qd2vl.

In my previous example, I use raycluster directly while in your case, you use rayservice.

So, in my PR, After running kubectl apply -f config/samples/ray_v1alpha1_rayservice.yaml (your case):
1677638568884

You can get a unique, cluster-global, cluster-instance-unique string from env var CLUSTER_NAME

@JoshKarpel
Copy link
Contributor Author

D'oh! I get it! That is indeed exactly what I need. Thanks for bearing with me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P1 Issue that should be fixed within a few weeks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants