Skip to content

[doc][KubeRay] Add NetworkPolicy user guide + kuberay namespace note - #65074

Merged
andrewsykim merged 15 commits into
ray-project:masterfrom
chipspeak:add-kuberay-networkpolicy-docs
Aug 12, 2026
Merged

andrewsykim merged 15 commits into
ray-project:masterfrom
chipspeak:add-kuberay-networkpolicy-docs

Conversation

@chipspeak

@chipspeak chipspeak commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adding documentation around the new NetworkPolicy feature in KubeRay.

Related issues

kuberay-project/kuberay#5030

Additional information

N/A

@chipspeak
chipspeak force-pushed the add-kuberay-networkpolicy-docs branch from b65acbc to 38dbe13 Compare July 28, 2026 16:19
@machichima machichima self-assigned this Jul 29, 2026
@chipspeak
chipspeak marked this pull request as ready for review July 29, 2026 08:58
@chipspeak
chipspeak requested review from a team and andrewsykim as code owners July 29, 2026 08:58

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@chipspeak
chipspeak force-pushed the add-kuberay-networkpolicy-docs branch from 38dbe13 to 826d9a4 Compare July 29, 2026 09:41
@ray-gardener ray-gardener Bot added docs An issue or change related to documentation core Issues that should be addressed in Ray Core community-contribution Contributed by the community labels Jul 29, 2026

@machichima machichima left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this section, I think it's enough to just have something similar to:

Install the KubeRay operator, following [these instructions](https://docs.ray.io/en/latest/cluster/kubernetes/getting-started/kuberay-operator-installation.html). The minimum version for this guide is v1.6.0. To use this feature, the `RayCronJob` feature gate must be enabled. To enable the feature gate when installing the kuberay operator, run the following command:
```sh
helm repo add kuberay https://ray-project.github.io/kuberay-helm/
helm repo update
# Install KubeRay operator v1.6.0 with the RayCronJob feature gate enabled
helm install kuberay-operator kuberay/kuberay-operator \
--version 1.6.0 \
--set "featureGates[0].name=RayCronJob" \
--set "featureGates[0].enabled=true"

Comment on lines +77 to +81
- **`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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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`.
:::

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have a "Prerequisites" section here similar to:

## Prerequisites
* **Kubernetes 1.35 or later.** In-Place Pod Resize graduated to GA in Kubernetes 1.35 ([blog post](https://kubernetes.io/blog/2025/12/19/kubernetes-v1-35-in-place-pod-resize-ga/)).
* **KubeRay v1.5.0 or later.**
* **Ray Autoscaler V2** enabled on the RayCluster. See {ref}`kuberay-autoscaler-v2`.

Showing the min version requirements for user to use this feature

Comment on lines +83 to +87
## 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 machichima left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment on lines +184 to +188
| 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 |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| 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`:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@chipspeak chipspeak Aug 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@chipspeak chipspeak Aug 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

@Nolbag

Nolbag commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Hi @machichima thanks for the feedback. I've updated the PR to address your comments.

@machichima machichima left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Left a few more comments
cc @chipspeak @Nolbag

Comment on lines +77 to +81
- **`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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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]>
@Nolbag
Nolbag force-pushed the add-kuberay-networkpolicy-docs branch from b7c0acc to 74a5a8f Compare August 10, 2026 14:13
@machichima

Copy link
Copy Markdown
Contributor

Please ping me when all comments are resolved. Thank you!

@Nolbag

Nolbag commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Hi @machichima all comments should be resolved now. Thanks

ports:
- port: 8080
protocol: TCP

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing ``` here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @machichima. Added the missing backticks

@machichima machichima left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just a nit left. cc @rueian or @andrewsykim for final pass and merge

@andrewsykim andrewsykim added the go add ONLY when ready to merge, run all tests label Aug 12, 2026
@andrewsykim
andrewsykim enabled auto-merge (squash) August 12, 2026 01:11

### 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

long overdue to recommend a dedicated namespace for KubeRay :)

FYI @machichima @win5923 @Future-Outlier @rueian

@andrewsykim
andrewsykim merged commit 82ea275 into ray-project:master Aug 12, 2026
8 checks passed
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…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]>
dstrodtman added a commit that referenced this pull request Aug 28, 2026
## 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]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community core Issues that should be addressed in Ray Core docs An issue or change related to documentation go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants