Skip to content

Commit ae26b7e

Browse files
committed
Add "Pod lifecycle" section to the network policy docs.
Signed-off-by: Nadia Pinaeva <[email protected]>
1 parent ef76483 commit ae26b7e

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,48 @@ The value of the label is the namespace name.
312312
While NetworkPolicy cannot target a namespace by its name with some object field, you can use the
313313
standardized label to target a specific namespace.
314314

315+
## Pod lifecycle
316+
317+
{{< note >}}
318+
The following applies to clusters with a conformant networking plugin and a conformant implementation of
319+
NetworkPolicy.
320+
{{< /note >}}
321+
322+
When a new NetworkPolicy object is created, it may take some time for a network plugin
323+
to handle the new object. If a pod that is affected by a NetworkPolicy
324+
is created before the network plugin has completed NetworkPolicy handling,
325+
that pod may be started unprotected, and isolation rules will be applied when
326+
the NetworkPolicy handling is completed.
327+
328+
Once the NetworkPolicy is handled by a network plugin,
329+
330+
1. All newly created pods affected by a given NetworkPolicy will be isolated before
331+
they are started.
332+
Implementations of NetworkPolicy must ensure that filtering is effective throughout
333+
the Pod lifecycle, even from the very first instant that any container in that Pod is started.
334+
Because they are applied at Pod level, NetworkPolicies apply equally to init containers,
335+
sidecar containers, and regular containers.
336+
337+
2. Allow rules will be applied eventually after the isolation rules (or may be applied at the same time).
338+
In the worst case, a newly created pod may have no network connectivity at all when it is first started, if
339+
isolation rules were already applied, but no allow rules were applied yet.
340+
341+
Every created NetworkPolicy will be handled by a network plugin eventually, but there is no
342+
way to tell from the Kubernetes API when exactly that happens.
343+
344+
Therefore, pods must be resilient against being started up with different network
345+
connectivity than expected. If you need to make sure the pod can reach certain destinations
346+
before being started, you can use an [init container](/docs/concepts/workloads/pods/init-containers/)
347+
to wait for those destinations to be reachable before kubelet starts the app containers.
348+
349+
Every NetworkPolicy will be applied to all selected pods eventually.
350+
Because the network plugin may implement NetworkPolicy in a distributed manner,
351+
it is possible that pods may see a slightly inconsistent view of network policies
352+
when the pod is first created, or when pods or policies change.
353+
For example, a newly-created pod that is supposed to be able to reach both Pod A
354+
on Node 1 and Pod B on Node 2 may find that it can reach Pod A immediately,
355+
but cannot reach Pod B until a few seconds later.
356+
315357
## What you can't do with network policies (at least, not yet)
316358

317359
As of Kubernetes {{< skew currentVersion >}}, the following functionality does not exist in the

0 commit comments

Comments
 (0)