Skip to content

Commit 60935ce

Browse files
authored
Merge pull request #26714 from rikatz/endport-netpol
Add netpol endport documentation
2 parents e1acd19 + 77f868e commit 60935ce

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

content/en/docs/concepts/services-networking/network-policies.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,49 @@ When the feature gate is enabled, you can set the `protocol` field of a NetworkP
221221
You must be using a {{< glossary_tooltip text="CNI" term_id="cni" >}} plugin that supports SCTP protocol NetworkPolicies.
222222
{{< /note >}}
223223

224+
## Targeting a range of Ports
225+
226+
{{< feature-state for_k8s_version="v1.21" state="alpha" >}}
227+
228+
When writing a NetworkPolicy, you can target a range of ports instead of a single port.
229+
230+
This is achiveable with the usage of the `endPort` field, as the following example:
231+
232+
```yaml
233+
apiVersion: networking.k8s.io/v1
234+
kind: NetworkPolicy
235+
metadata:
236+
name: multi-port-egress
237+
namespace: default
238+
spec:
239+
podSelector:
240+
matchLabels:
241+
role: db
242+
policyTypes:
243+
- Egress
244+
egress:
245+
- to:
246+
- ipBlock:
247+
cidr: 10.0.0.0/24
248+
ports:
249+
- protocol: TCP
250+
port: 32000
251+
endPort: 32768
252+
```
253+
254+
The above rule will allow a Pod with label `db` on the namespace `default` to communicate with any IP within the range `10.0.0.0/24` if the target port is between the range 32000 and 32768.
255+
256+
The following restrictions apply when using this field:
257+
* As an alpha feature, this is disabled by default. To enable endPort field at a cluster level, you (or your cluster administrator) will need to enable the `NetworkPolicyEndPort` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/) for the API server with `--feature-gates=NetworkPolicyEndPort=true,…`.
258+
* The `endPort` field must be equal than or greater to `port` field.
259+
* `endPort` can only be defined if `port` is also defined.
260+
* Both ports must be numeric.
261+
262+
{{< note >}}
263+
Your cluster must be using a {{< glossary_tooltip text="CNI" term_id="cni" >}} plugin that
264+
supports the `endPort` field in NetworkPolicy specifications.
265+
{{< /note >}}
266+
224267
## What you can't do with network policies (at least, not yet)
225268

226269
As of Kubernetes 1.20, the following functionality does not exist in the NetworkPolicy API, but you might be able to implement workarounds using Operating System components (such as SELinux, OpenVSwitch, IPTables, and so on) or Layer 7 technologies (Ingress controllers, Service Mesh implementations) or admission controllers. In case you are new to network security in Kubernetes, its worth noting that the following User Stories cannot (yet) be implemented using the NetworkPolicy API. Some (but not all) of these user stories are actively being discussed for future releases of the NetworkPolicy API.
@@ -232,7 +275,6 @@ As of Kubernetes 1.20, the following functionality does not exist in the Network
232275
- Creation or management of "Policy requests" that are fulfilled by a third party.
233276
- Default policies which are applied to all namespaces or pods (there are some third party Kubernetes distributions and projects which can do this).
234277
- Advanced policy querying and reachability tooling.
235-
- The ability to target ranges of Ports in a single policy declaration.
236278
- The ability to log network security events (for example connections that are blocked or accepted).
237279
- The ability to explicitly deny policies (currently the model for NetworkPolicies are deny by default, with only the ability to add allow rules).
238280
- The ability to prevent loopback or incoming host traffic (Pods cannot currently block localhost access, nor do they have the ability to block access from their resident node).

content/en/docs/reference/command-line-tools-reference/feature-gates.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ different Kubernetes components.
133133
| `LocalStorageCapacityIsolation` | `true` | Beta | 1.10 | |
134134
| `LocalStorageCapacityIsolationFSQuotaMonitoring` | `false` | Alpha | 1.15 | |
135135
| `MixedProtocolLBService` | `false` | Alpha | 1.20 | |
136+
| `NetworkPolicyEndPort` | `false` | Alpha | 1.21 | |
136137
| `NodeDisruptionExclusion` | `false` | Alpha | 1.16 | 1.18 |
137138
| `NodeDisruptionExclusion` | `true` | Beta | 1.19 | |
138139
| `NonPreemptingPriority` | `false` | Alpha | 1.15 | 1.18 |
@@ -659,6 +660,7 @@ Each feature gate is designed for enabling/disabling a specific feature:
659660
the volume mounter.
660661
- `MountPropagation`: Enable sharing volume mounted by one container to other containers or pods.
661662
For more details, please see [mount propagation](/docs/concepts/storage/volumes/#mount-propagation).
663+
- `NetworkPolicyEndPort`: Enable use of the field `endPort` in NetworkPolicy objects, allowing the selection of a port range instead of a single port.
662664
- `NodeDisruptionExclusion`: Enable use of the Node label `node.kubernetes.io/exclude-disruption`
663665
which prevents nodes from being evacuated during zone failures.
664666
- `NodeLease`: Enable the new Lease API to report node heartbeats, which could be used as a node health signal.

0 commit comments

Comments
 (0)