Clarify ports
behavior in NetworkPolicy to
and from
blocks
#49556
Labels
kind/feature
Categorizes issue or PR as related to a new feature.
needs-triage
Indicates an issue or PR lacks a `triage/foo` label and requires one.
What is the problem?
The current Kubernetes documentation does not explicitly mention that the
ports
field in theto
andfrom
blocks of a NetworkPolicyPeer is optional. This omission leads to confusion for users who may assume that omittingports
blocks traffic by default. Instead, the actual behavior is that omittingports
allows traffic to all ports for the specified destination(s).Proposed Solution
Update the Kubernetes documentation to explicitly state:
ports
is optional in theto
andfrom
blocks of a NetworkPolicyPeer.ports
is omitted, all ports are allowed for the specified destinations (ipBlock
,namespaceSelector
, orpodSelector
).ports
(allowing all ports).ports
(restricting to specific ports).Examples for Documentation:
Without
ports
:app=database
.With
ports
:app=database
.Where to Update
The following sections of the Kubernetes documentation should be updated:
[Network Policies Documentation](https://kubernetes.io/docs/concepts/services-networking/network-policies/):
ports
being optional and its default behavior.ports
is omitted or specified.[NetworkPolicyPeer API Reference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#networkpolicypeer-v1-networking-k8s-io):
to
andfrom
blocks to include the optionalports
field.ports
is omitted.Why This Is Important
ports
will:ports
may not be specified.Additional Context
This clarification aligns with Kubernetes behavior verified through testing. Below is an additional example demonstrating traffic allowed to specific namespaces and pods when
ports
is omitted:app=redis
in namespaces labeledteam=backend
.The text was updated successfully, but these errors were encountered: