You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
224
267
## What you can't do with network policies (at least, not yet)
225
268
226
269
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
232
275
- Creation or management of "Policy requests" that are fulfilled by a third party.
233
276
- Default policies which are applied to all namespaces or pods (there are some third party Kubernetes distributions and projects which can do this).
234
277
- Advanced policy querying and reachability tooling.
235
-
- The ability to target ranges of Ports in a single policy declaration.
236
278
- The ability to log network security events (for example connections that are blocked or accepted).
237
279
- The ability to explicitly deny policies (currently the model for NetworkPolicies are deny by default, with only the ability to add allow rules).
238
280
- 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).
0 commit comments