Skip to content

Commit 1b12bcc

Browse files
authored
Merge pull request #30958 from MikeSpreitzer/fix-105494b
Update NetworkPolicy concept doc for egress
2 parents 4832d30 + c25398b commit 1b12bcc

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ weight: 50
1010

1111
<!-- overview -->
1212

13-
If you want to control traffic flow at the IP address or port level (OSI layer 3 or 4), then you might consider using Kubernetes NetworkPolicies for particular applications in your cluster. NetworkPolicies are an application-centric construct which allow you to specify how a {{< glossary_tooltip text="pod" term_id="pod">}} is allowed to communicate with various network "entities" (we use the word "entity" here to avoid overloading the more common terms such as "endpoints" and "services", which have specific Kubernetes connotations) over the network.
13+
If you want to control traffic flow at the IP address or port level (OSI layer 3 or 4), then you might consider using Kubernetes NetworkPolicies for particular applications in your cluster. NetworkPolicies are an application-centric construct which allow you to specify how a {{< glossary_tooltip text="pod" term_id="pod">}} is allowed to communicate with various network "entities" (we use the word "entity" here to avoid overloading the more common terms such as "endpoints" and "services", which have specific Kubernetes connotations) over the network. NetworkPolicies apply to a connection with a pod on one or both ends, and are not relevant to other connections.
1414

1515
The entities that a Pod can communicate with are identified through a combination of the following 3 identifiers:
1616

@@ -27,15 +27,17 @@ Meanwhile, when IP based NetworkPolicies are created, we define policies based o
2727

2828
Network policies are implemented by the [network plugin](/docs/concepts/extend-kubernetes/compute-storage-net/network-plugins/). To use network policies, you must be using a networking solution which supports NetworkPolicy. Creating a NetworkPolicy resource without a controller that implements it will have no effect.
2929

30-
## Isolated and Non-isolated Pods
30+
## The Two Sorts of Pod Isolation
3131

32-
By default, pods are non-isolated; they accept traffic from any source.
32+
There are two sorts of isolation for a pod: isolation for egress, and isolation for ingress. They concern what connections may be established. "Isolation" here is not absolute, rather it means "some restrictions apply". The alternative, "non-isolated for $direction", means that no restrictions apply in the stated direction. The two sorts of isolation (or not) are declared independently, and are both relevant for a connection from one pod to another.
3333

34-
Pods become isolated by having a NetworkPolicy that selects them. Once there is any NetworkPolicy in a namespace selecting a particular pod, that pod will reject any connections that are not allowed by any NetworkPolicy. (Other pods in the namespace that are not selected by any NetworkPolicy will continue to accept all traffic.)
34+
By default, a pod is non-isolated for egress; all outbound connections are allowed. A pod is isolated for egress if there is any NetworkPolicy that both selects the pod and has "Egress" in its `policyTypes`; we say that such a policy applies to the pod for egress. When a pod is isolated for egress, the only allowed connections from the pod are those allowed by the `egress` list of some NetworkPolicy that applies to the pod for egress. The effects of those `egress` lists combine additively.
3535

36-
Network policies do not conflict; they are additive. If any policy or policies select a pod, the pod is restricted to what is allowed by the union of those policies' ingress/egress rules. Thus, order of evaluation does not affect the policy result.
36+
By default, a pod is non-isolated for ingress; all inbound connections are allowed. A pod is isolated for ingress if there is any NetworkPolicy that both selects the pod and has "Ingress" in its `policyTypes`; we say that such a policy applies to the pod for ingress. When a pod is isolated for ingress, the only allowed connections into the pod are those from the pod's node and those allowed by the `ingress` list of some NetworkPolicy that applies to the pod for ingress. The effects of those `ingress` lists combine additively.
3737

38-
For a network flow between two pods to be allowed, both the egress policy on the source pod and the ingress policy on the destination pod need to allow the traffic. If either the egress policy on the source, or the ingress policy on the destination denies the traffic, the traffic will be denied.
38+
Network policies do not conflict; they are additive. If any policy or policies apply to a given pod for a given direction, the connections allowed in that direction from that pod is the union of what the applicable policies allow. Thus, order of evaluation does not affect the policy result.
39+
40+
For a connection from a source pod to a destination pod to be allowed, both the egress policy on the source pod and the ingress policy on the destination pod need to allow the connection. If either side does not allow the connection, it will not happen.
3941

4042
## The NetworkPolicy resource {#networkpolicy-resource}
4143

@@ -176,33 +178,37 @@ in that namespace.
176178

177179
### Default deny all ingress traffic
178180

179-
You can create a "default" isolation policy for a namespace by creating a NetworkPolicy that selects all pods but does not allow any ingress traffic to those pods.
181+
You can create a "default" ingress isolation policy for a namespace by creating a NetworkPolicy that selects all pods but does not allow any ingress traffic to those pods.
180182

181183
{{< codenew file="service/networking/network-policy-default-deny-ingress.yaml" >}}
182184

183-
This ensures that even pods that aren't selected by any other NetworkPolicy will still be isolated. This policy does not change the default egress isolation behavior.
185+
This ensures that even pods that aren't selected by any other NetworkPolicy will still be isolated for ingress. This policy does not affect isolation for egress from any pod.
184186

185-
### Default allow all ingress traffic
187+
### Allow all ingress traffic
186188

187-
If you want to allow all traffic to all pods in a namespace (even if policies are added that cause some pods to be treated as "isolated"), you can create a policy that explicitly allows all traffic in that namespace.
189+
If you want to allow all incoming connections to all pods in a namespace, you can create a policy that explicitly allows that.
188190

189191
{{< codenew file="service/networking/network-policy-allow-all-ingress.yaml" >}}
190192

193+
With this policy in place, no additional policy or policies can cause any incoming connection to those pods to be denied. This policy has no effect on isolation for egress from any pod.
194+
191195
### Default deny all egress traffic
192196

193197
You can create a "default" egress isolation policy for a namespace by creating a NetworkPolicy that selects all pods but does not allow any egress traffic from those pods.
194198

195199
{{< codenew file="service/networking/network-policy-default-deny-egress.yaml" >}}
196200

197201
This ensures that even pods that aren't selected by any other NetworkPolicy will not be allowed egress traffic. This policy does not
198-
change the default ingress isolation behavior.
202+
change the ingress isolation behavior of any pod.
199203

200-
### Default allow all egress traffic
204+
### Allow all egress traffic
201205

202-
If you want to allow all traffic from all pods in a namespace (even if policies are added that cause some pods to be treated as "isolated"), you can create a policy that explicitly allows all egress traffic in that namespace.
206+
If you want to allow all connections from all pods in a namespace, you can create a policy that explicitly allows all outgoing connections from pods in that namespace.
203207

204208
{{< codenew file="service/networking/network-policy-allow-all-egress.yaml" >}}
205209

210+
With this policy in place, no additional policy or policies can cause any outgoing connection from those pods to be denied. This policy has no effect on isolation for ingress to any pod.
211+
206212
### Default deny all ingress and all egress traffic
207213

208214
You can create a "default" policy for a namespace which prevents all ingress AND egress traffic by creating the following NetworkPolicy in that namespace.

0 commit comments

Comments
 (0)