Repository navigation
[doc][KubeRay] Add NetworkPolicy user guide + kuberay namespace note - #65074
Conversation
b65acbc to
38dbe13
Compare
There was a problem hiding this comment.
Code Review
This pull request updates the KubeRay operator installation guide to use a dedicated ray-system namespace by default and introduces a comprehensive user guide for configuring RayCluster with NetworkPolicies. The review feedback identifies a critical issue in the Kustomize configuration example where a strategic merge patch would overwrite the operator's default arguments and break its functionality, recommending a JSON 6902 patch instead. Additionally, it suggests simplifying the validation instructions since the ray-system namespace is now the default for all installation methods.
| ## Step 3: Validate Installation | ||
|
|
||
| Confirm that the operator is running in the namespace `default`. | ||
| Confirm that the operator is running. If you installed into `ray-system`, pass `-n ray-system`: |
There was a problem hiding this comment.
Since both Method 1 (Helm) and Method 2 (Kustomize) in the updated guide now install the operator into the ray-system namespace by default, the conditional phrasing "If you installed into ray-system" is no longer necessary.
We can simplify this to:
Confirm that the operator is running in the `ray-system` namespace:There was a problem hiding this comment.
@machichima I'm happy to still have this in just to double down on the ray-system namespace advice but I can change it to the above too depending on what you think.
There was a problem hiding this comment.
Could we just create a note block :::{note} on step 2 showing that it's recommended to install on ray-system namespace to reduce the security surface. And do not update the default commands directly as it would affect all other docs
There was a problem hiding this comment.
Yeah for sure I'll do that now!
Signed-off-by: Pat O'Connor <[email protected]> Co-authored-by: David Adamache <[email protected]> Co-authored-by: Paul Nolan <[email protected]>
38dbe13 to
826d9a4
Compare
machichima
left a comment
There was a problem hiding this comment.
Went through half of the docs, will finish rest of it tomorrow
| NetworkPolicy support is alpha and disabled by default. Enable the `RayClusterNetworkPolicy` feature gate before using `spec.networkPolicy`. | ||
| ::: | ||
|
|
||
| ## Enable the feature gate |
There was a problem hiding this comment.
For this section, I think it's enough to just have something similar to:
| - **`DenyAll`**: deny all ingress and egress except intra-cluster pod traffic. | ||
| - **`DenyAllIngress`**: deny inbound traffic only; outbound is unrestricted. | ||
| - **`DenyAllEgress`**: deny outbound traffic only; inbound is unrestricted. | ||
|
|
||
| In all modes, the operator always permits pod-to-pod traffic within the same `RayCluster` on all ports. For `DenyAll` and `DenyAllIngress`, the head pod policy also allows the submitter pod to reach the dashboard port when a `RayJob` running in `K8sJobMode` owns the cluster. |
There was a problem hiding this comment.
Could we show what are the default ingress / egress rules we will have? e.g. show the generated NetworkPolicy from kubectl get networkpolicy <name> -o yaml after deploying, or just paste the default settings in YAML
There was a problem hiding this comment.
Sorry, after second thought, I think having bullet point is enough. Adding kubectl describe result here is less readable for users.
|
|
||
| ## Enable NetworkPolicy | ||
|
|
||
| Add a `networkPolicy` field to `spec` and choose a mode: |
There was a problem hiding this comment.
| Add a `networkPolicy` field to `spec` and choose a mode: | |
| Add a `networkPolicy` field to the `RayCluster` `spec` and choose a mode: |
| :::{warning} | ||
| NetworkPolicy support is alpha and disabled by default. Enable the `RayClusterNetworkPolicy` feature gate before using `spec.networkPolicy`. | ||
| ::: | ||
|
|
There was a problem hiding this comment.
Could we have a "Prerequisites" section here similar to:
ray/doc/source/cluster/kubernetes/user-guides/configuring-ippr.md
Lines 40 to 44 in e8bd0a2
Showing the min version requirements for user to use this feature
| ## Apply a namespace default-deny policy first | ||
|
|
||
| Ray cluster pods and their `NetworkPolicy` resources are created by different controllers asynchronously. A pod can start before its policy is applied, leaving a brief window where all traffic is permitted. | ||
|
|
||
| To address this, pre-apply a namespace-level policy scoped to the directions your chosen mode manages. This closes the race window without interfering with the directions your mode leaves unrestricted. |
There was a problem hiding this comment.
This will apply to all pods in the namespace, including ones that are not managed by KubeRay. Maybe we can add a note saying that if user want to limit to KubeRay pods, use this label:
podSelector:
matchLabels:
ray.io/is-ray-node: "yes"Also if user set DenyAll or DenyAllEgress, it's recommended to add this label to exclude submitter pod, otherwise the RayJob will fail if they do not set extra rules to enable submitter pod egress.
machichima
left a comment
There was a problem hiding this comment.
Go through the whole document. Feel free to ping me after you resolved all the comments and I'll do a second pass. Thank you!
|
|
||
| ### DNS egress | ||
|
|
||
| Workers reach the head node through its service FQDN. Without a DNS egress rule, workers can't resolve the head address and the cluster won't start. Add this rule to both `head.egressRules` and `worker.egressRules`: |
There was a problem hiding this comment.
| Workers reach the head node through its service FQDN. Without a DNS egress rule, workers can't resolve the head address and the cluster won't start. Add this rule to both `head.egressRules` and `worker.egressRules`: | |
| Workers reach the head node through its service FQDN. Without a DNS egress rule, workers can't resolve the head address and the cluster won't start. The operator doesn't add this rule by default because DNS deployments vary across clusters. Adjust the selector to match your cluster's DNS provider before applying. Add the rule to both `head.egressRules` and `worker.egressRules`: |
Let's tell users that they may need to update the rule for their DNS provider
| | CNI | Required form | | ||
| |---|---| | ||
| | kindnet, Calico, Antrea | `ipBlock` with the endpoint IP (post-DNAT) | | ||
| | Cilium | `CiliumNetworkPolicy` with `toEntities: [kube-apiserver]`; standard `ipBlock` doesn't work | | ||
| | EKS (Amazon VPC CNI) | `ipBlock` with the `kubernetes` Service ClusterIP | |
There was a problem hiding this comment.
| | CNI | Required form | | |
| |---|---| | |
| | kindnet, Calico, Antrea | `ipBlock` with the endpoint IP (post-DNAT) | | |
| | Cilium | `CiliumNetworkPolicy` with `toEntities: [kube-apiserver]`; standard `ipBlock` doesn't work | | |
| | EKS (Amazon VPC CNI) | `ipBlock` with the `kubernetes` Service ClusterIP | | |
| | CNI | Required form | | |
| |---|---| | |
| | kindnet | No rule needed — kindnet allows egress to the API server by default | | |
| | Calico, Cilium (with `kube-proxy-replacement`) | `ipBlock` with the endpoint IP (post-DNAT); a ClusterIP rule blocks autoscaling | | |
| | EKS (Amazon VPC CNI) | `ipBlock` with the `kubernetes` Service ClusterIP; an endpoint IP rule blocks autoscaling | | |
| These results come from testing in [kuberay#4638](https://github.com/ray-project/kuberay/pull/4638#issuecomment-4660571594); other CNIs or configurations may behave differently. | |
| Calico and Cilium also require `policyCIDRMatchMode: Node` set on the CNI (see [this issue](https://github.com/hcloud-k8s/terraform-hcloud-kubernetes/issues/285)) for the endpoint-IP `ipBlock` rule below to match. Without it, the rule may not take effect. |
Let update to this, following our experiment results
| kubectl get endpointslices -n default -l kubernetes.io/service-name=kubernetes | ||
| ``` | ||
|
|
||
| For kindnet, Calico, and Antrea, add this rule to `head.egressRules`: |
There was a problem hiding this comment.
| For kindnet, Calico, and Antrea, add this rule to `head.egressRules`: | |
| For Calico and Cilium, add this rule to `head.egressRules`: |
| protocol: TCP | ||
| ``` | ||
|
|
||
| For EKS, replace `<endpoint-ip>` with the ClusterIP from `kubectl get svc kubernetes`. For Cilium, create a `CiliumNetworkPolicy` instead. |
There was a problem hiding this comment.
| For EKS, replace `<endpoint-ip>` with the ClusterIP from `kubectl get svc kubernetes`. For Cilium, create a `CiliumNetworkPolicy` instead. | |
| For EKS, replace `<endpoint-ip>` with the ClusterIP from `kubectl get svc kubernetes`. As a [suggested alternative for Cilium in kuberay#4638](https://github.com/ray-project/kuberay/pull/4638#discussion_r3336164401), you can instead use a `CiliumNetworkPolicy` with `toEntities: [kube-apiserver]` to target the API server by identity instead of IP. See Cilium's [Layer 3 policy docs](https://docs.cilium.io/en/stable/security/policy/layer3/) for details. |
|
|
||
| For `HTTPMode` and `SidecarMode`, there is no standalone submitter pod, so no additional ingress rule is required. | ||
|
|
||
| ### Standalone clusters with clusterSelector |
There was a problem hiding this comment.
Please correct me if I'm wrong, I might missed some discussions. Based on comment: kuberay-project/kuberay#4638 (comment), I think option 2 shared opt-in access label is more recommended?
There was a problem hiding this comment.
Hey yes thanks for catching that. We can drop the ray.io/originated-from-cr-name: <rayjob-name> and clarify the use-cases in the initial text. cc @Nolbag
There was a problem hiding this comment.
That is, if we want to clarify that a user can use the broader rule to achieve the same result or else create their own opt-in label. Does that make sense and which is your preference? I went with this approach in the controller because it still provides a user with the ability to use a broader rule while preserving the ability to fall back on a templated system that doesn't need them to label their own submitter pod.
There was a problem hiding this comment.
I think option 2 (self-defined opt-in label) is better. It lets many RayJobs share one cluster without editing the RayCluster per job, while still limiting which RayJobs can access it.
Only dropping ray.io/originated-from-cr-name: <rayjob-name> would grant head access to every RayJob in the namespace, which goes against the purpose of restricting traffic.
|
|
||
| ## Custom rules | ||
|
|
||
| Add per-role rules under `head` and `worker`. The operator appends them to the base policy for that role and doesn't apply head rules to workers or vice versa. |
There was a problem hiding this comment.
| Add per-role rules under `head` and `worker`. The operator appends them to the base policy for that role and doesn't apply head rules to workers or vice versa. | |
| Add rules under `head` or `worker` to target that role's policy. The operator appends `head` rules only to the head pod's policy, and `worker` rules only to worker pods' policy. |
Signed-off-by: Paul Nolan <[email protected]>
Signed-off-by: Paul Nolan <[email protected]>
Signed-off-by: Paul Nolan <[email protected]>
Signed-off-by: Paul Nolan <[email protected]>
… provider Signed-off-by: Paul Nolan <[email protected]>
Signed-off-by: Paul Nolan <[email protected]>
…licies Signed-off-by: Paul Nolan <[email protected]>
…vale errors Signed-off-by: Paul Nolan <[email protected]>
…bmitter Signed-off-by: Paul Nolan <[email protected]>
|
Hi @machichima thanks for the feedback. I've updated the PR to address your comments. |
machichima
left a comment
There was a problem hiding this comment.
Thank you! Left a few more comments
cc @chipspeak @Nolbag
| - **`DenyAll`**: deny all ingress and egress except intra-cluster pod traffic. | ||
| - **`DenyAllIngress`**: deny inbound traffic only; outbound is unrestricted. | ||
| - **`DenyAllEgress`**: deny outbound traffic only; inbound is unrestricted. | ||
|
|
||
| In all modes, the operator always permits pod-to-pod traffic within the same `RayCluster` on all ports. For `DenyAll` and `DenyAllIngress`, the head pod policy also allows the submitter pod to reach the dashboard port when a `RayJob` running in `K8sJobMode` owns the cluster. |
There was a problem hiding this comment.
Sorry, after second thought, I think having bullet point is enough. Adding kubectl describe result here is less readable for users.
|
|
||
| For `HTTPMode` and `SidecarMode`, there is no standalone submitter pod, so no additional ingress rule is required. | ||
|
|
||
| ### Standalone clusters with clusterSelector |
There was a problem hiding this comment.
I think option 2 (self-defined opt-in label) is better. It lets many RayJobs share one cluster without editing the RayCluster per job, while still limiting which RayJobs can access it.
Only dropping ray.io/originated-from-cr-name: <rayjob-name> would grant head access to every RayJob in the namespace, which goes against the purpose of restricting traffic.
|
|
||
| ## Custom rules | ||
|
|
||
| Add rules under `head` or `worker` to target that role's policy. The operator appends `head` rules only to the head pod's policy, and `worker` rules only to worker pods' policy. |
There was a problem hiding this comment.
User could also set rules for each worker group through workerGroups (added in kuberay-project/kuberay#5028). Could you also mention it here and add an example below for configuring per worker group?
Also, please mention that for each worker group, it'll defaults to the rules set in worker, and will be "replace" by the workerGroups entry if set
|
|
||
| ## Enable NetworkPolicy | ||
|
|
||
| Add a `networkPolicy` field to the `RayCluster` `spec` and choose a mode: |
There was a problem hiding this comment.
| Add a `networkPolicy` field to the `RayCluster` `spec` and choose a mode: | |
| Add a `networkPolicy` field to the `RayCluster` spec and choose a mode: |
… each mode" This reverts commit 7a09fc5. Signed-off-by: Paul Nolan <[email protected]>
b7c0acc to
74a5a8f
Compare
|
Please ping me when all comments are resolved. Thank you! |
… access Signed-off-by: Paul Nolan <[email protected]>
Signed-off-by: Paul Nolan <[email protected]>
…erGroups Signed-off-by: Paul Nolan <[email protected]>
|
Hi @machichima all comments should be resolved now. Thanks |
| ports: | ||
| - port: 8080 | ||
| protocol: TCP | ||
|
|
There was a problem hiding this comment.
Thanks @machichima. Added the missing backticks
machichima
left a comment
There was a problem hiding this comment.
LGTM! Just a nit left. cc @rueian or @andrewsykim for final pass and merge
Signed-off-by: Paul Nolan <[email protected]>
|
|
||
| ### Method 1: Helm (Recommended) | ||
|
|
||
| Install the operator into a dedicated `ray-system` namespace rather than `default` to isolate the operator's service account from workload pods. |
There was a problem hiding this comment.
long overdue to recommend a dedicated namespace for KubeRay :)
…ay-project#65074) ## Description Adding documentation around the new NetworkPolicy feature in KubeRay. ## Related issues kuberay-project/kuberay#5030 ## Additional information N/A --------- Signed-off-by: Paul Nolan <[email protected]> Co-authored-by: David Adamache <[email protected]> Co-authored-by: Paul Nolan <[email protected]> Signed-off-by: 400Ping <[email protected]>
## Why The [KubeRay v1.7 blog](https://www.anyscale.com/blog/kuberay-v1-7) highlights several features whose docs currently live only on `master`. The corresponding pages are missing (404) or incomplete on the `latest` (2.58.0) docs build, and several blog links point at `/master` as a result. This backports the doc pages so the 2.58.0 `latest` docs cover the released KubeRay v1.7 surface. ## What (cherry-picks onto `releases/2.58.0`) | Commit | Blog feature | Gap on `latest` | |---|---|---| | #64303 | RayJob `SidecarMode` retry | new page was missing | | #65249 | RayService incremental upgrade rollback (beta) | `#rollback` section missing | | #65074 | NetworkPolicy support (alpha) | new page was missing | | #65429 | Embedded RocksDB GCS backend | example version pin missing | | #65513 | Fix docs for KubeRay v1.7 | wrong NetworkPolicy field names + incorrect `kubernetes` pip guidance | | #65483 | Customizable Ingress options | `ingressOptions` undocumented | Each commit is applied with `cherry-pick -x` (provenance preserved) and DCO sign-off. ## Not duplicating - No open PR cherry-picks these into `releases/2.58.0` (checked by PR number and by `--base releases/2.58.0`). - The two History Server refinements (#65441, #65505) are intentionally **excluded** — they already landed on `releases/2.58.0` (`c6061c10b97`, `d8277b53b0d`) and that page is already identical to `master`. - Broad, non-feature changes touching these files on `master` (llms.txt page descriptions #65115, the "Ray Pod" terminology rename #65423, the vendored CRD API reference #65428) are deliberately left out to keep this a tight, low-risk release-branch backport. ## Testing - Verified every new/changed page's `{ref}`/`{doc}` cross-reference target resolves on this branch (`fail_on_warning: true` build safety). - Verified both new toctree entries (`network-policy`, `rayjob-sidecar-submitter-restart`) point at files that exist on the branch. - Confirmed each touched file matches `master` except for the intentionally-excluded frontmatter/rename hunks above. - A full local Sphinx docs build is recommended before marking ready for review. AI assistance (Claude Code) was used to prepare this backport. --------- Signed-off-by: justinyeh1995 <[email protected]> Signed-off-by: Justin Yeh <[email protected]> Signed-off-by: JustinYeh <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]> Signed-off-by: win5923 <[email protected]> Signed-off-by: Paul Nolan <[email protected]> Signed-off-by: machichima <[email protected]> Signed-off-by: wuallen57730 <[email protected]> Co-authored-by: JustinYeh <[email protected]> Co-authored-by: Jun-Hao Wan <[email protected]> Co-authored-by: Pat O'Connor <[email protected]> Co-authored-by: David Adamache <[email protected]> Co-authored-by: Paul Nolan <[email protected]> Co-authored-by: Nary Yeh <[email protected]> Co-authored-by: Lima <[email protected]>
…ay-project#65074) ## Description Adding documentation around the new NetworkPolicy feature in KubeRay. ## Related issues kuberay-project/kuberay#5030 ## Additional information N/A --------- Signed-off-by: Paul Nolan <[email protected]> Co-authored-by: David Adamache <[email protected]> Co-authored-by: Paul Nolan <[email protected]>
Description
Adding documentation around the new NetworkPolicy feature in KubeRay.
Related issues
kuberay-project/kuberay#5030
Additional information
N/A