|
| 1 | +--- |
| 2 | +layout: blog |
| 3 | +title: 'Kubernetes 1.25: PodHasNetwork condition for pods' |
| 4 | +date: 2022-09-14 |
| 5 | +slug: pod-has-network-condition |
| 6 | +--- |
| 7 | + |
| 8 | +**Author:** |
| 9 | +Deep Debroy (Apple) |
| 10 | + |
| 11 | +Kubernetes 1.25 introduces Alpha support for a new kubelet-managed pod condition |
| 12 | +in the status field of a pod: `PodHasNetwork`. The kubelet, for a worker node, |
| 13 | +will use the `PodHasNetwork` condition to accurately surface the initialization |
| 14 | +state of a pod from the perspective of pod sandbox creation and network |
| 15 | +configuration by a container runtime (typically in coordination with CNI |
| 16 | +plugins). The kubelet starts to pull container images and start individual |
| 17 | +containers (including init containers) after the status of the `PodHasNetwork` |
| 18 | +condition is set to `True`. Metrics collection services that report latency of |
| 19 | +pod initialization from a cluster infrastructural perspective (i.e. agnostic of |
| 20 | +per container characteristics like image size or payload) can utilize the |
| 21 | +`PodHasNetwork` condition to accurately generate Service Level Indicators |
| 22 | +(SLIs). Certain operators or controllers that manage underlying pods may utilize |
| 23 | +the `PodHasNetwork` condition to optimize the set of actions performed when pods |
| 24 | +repeatedly fail to come up. |
| 25 | + |
| 26 | +### How is this different from the existing Initialized condition reported for pods? |
| 27 | + |
| 28 | +The kubelet sets the status of the existing `Initialized` condition reported in |
| 29 | +the status field of a pod depending on the presence of init containers in a pod. |
| 30 | + |
| 31 | +If a pod specifies init containers, the status of the `Initialized` condition in |
| 32 | +the pod status will not be set to `True` until all init containers for the pod |
| 33 | +have succeeded. However, init containers, configured by users, may have errors |
| 34 | +(payload crashing, invalid image, etc) and the number of init containers |
| 35 | +configured in a pod may vary across different workloads. Therefore, |
| 36 | +cluster-wide, infrastructural SLIs around pod initialization cannot depend on |
| 37 | +the `Initialized` condition of pods. |
| 38 | + |
| 39 | +If a pod does not specify init containers, the status of the `Initialized` |
| 40 | +condition in the pod status is set to `True` very early in the lifecycle of the |
| 41 | +pod. This occurs before the kubelet initiates any pod runtime sandbox creation |
| 42 | +and network configuration steps. As a result, a pod without init containers will |
| 43 | +report the status of the `Initialized` condition as `True` even if the container |
| 44 | +runtime is not able to successfully initialize the pod sandbox environment. |
| 45 | + |
| 46 | +Relative to either situation above, the `PodHasNetwork` condition surfaces more |
| 47 | +accurate data around when the pod runtime sandbox was initialized with |
| 48 | +networking configured so that the kubelet can proceed to launch user-configured |
| 49 | +containers (including init containers) in the pod. |
| 50 | + |
| 51 | +Note that a node agent may dynamically re-configure network interface(s) for a |
| 52 | +pod by watching changes in pod annotations that specify additional networking |
| 53 | +configuration (e.g. `k8s.v1.cni.cncf.io/networks`). Dynamic updates of pod |
| 54 | +networking configuration after the pod sandbox is initialized by Kubelet (in |
| 55 | +coordination with a container runtime) are not reflected by the `PodHasNetwork` |
| 56 | +condition. |
| 57 | + |
| 58 | +### Try out the PodHasNetwork condition for pods |
| 59 | + |
| 60 | +In order to have the kubelet report the `PodHasNetwork` condition in the status |
| 61 | +field of a pod, please enable the `PodHasNetworkCondition` feature gate on the |
| 62 | +kubelet. |
| 63 | + |
| 64 | +For a pod whose runtime sandbox has been successfully created and has networking |
| 65 | +configured, the kubelet will report the `PodHasNetwork` condition with status set to `True`: |
| 66 | + |
| 67 | +``` |
| 68 | +$ kubectl describe pod nginx1 |
| 69 | +Name: nginx1 |
| 70 | +Namespace: default |
| 71 | +... |
| 72 | +Conditions: |
| 73 | + Type Status |
| 74 | + PodHasNetwork True |
| 75 | + Initialized True |
| 76 | + Ready True |
| 77 | + ContainersReady True |
| 78 | + PodScheduled True |
| 79 | +``` |
| 80 | + |
| 81 | +For a pod whose runtime sandbox has not been created yet (and networking not |
| 82 | +configured either), the kubelet will report the `PodHasNetwork` condition with |
| 83 | +status set to `False`: |
| 84 | + |
| 85 | +``` |
| 86 | +$ kubectl describe pod nginx2 |
| 87 | +Name: nginx2 |
| 88 | +Namespace: default |
| 89 | +... |
| 90 | +Conditions: |
| 91 | + Type Status |
| 92 | + PodHasNetwork False |
| 93 | + Initialized True |
| 94 | + Ready False |
| 95 | + ContainersReady False |
| 96 | + PodScheduled True |
| 97 | +``` |
| 98 | + |
| 99 | +### What’s next? |
| 100 | + |
| 101 | +Depending on feedback and adoption, the Kubernetes team plans to push the |
| 102 | +reporting of the `PodHasNetwork` condition to Beta in 1.26 or 1.27. |
| 103 | + |
| 104 | +### How can I learn more? |
| 105 | + |
| 106 | +Please check out the |
| 107 | +[documentation](/docs/concepts/workloads/pods/pod-lifecycle/) for the |
| 108 | +`PodHasNetwork` condition to learn more about it and how it fits in relation to |
| 109 | +other pod conditions. |
| 110 | + |
| 111 | +### How to get involved? |
| 112 | + |
| 113 | +This feature is driven by the SIG Node community. Please join us to connect with |
| 114 | +the community and share your ideas and feedback around the above feature and |
| 115 | +beyond. We look forward to hearing from you! |
| 116 | + |
| 117 | +### Acknowledgements |
| 118 | + |
| 119 | +We want to thank the following people for their insightful and helpful reviews |
| 120 | +of the KEP and PRs around this feature: Derek Carr (@derekwaynecarr), Mrunal |
| 121 | +Patel (@mrunalp), Dawn Chen (@dchen1107), Qiutong Song (@qiutongs), Ruiwen Zhao |
| 122 | +(@ruiwen-zhao), Tim Bannister (@sftim), Danielle Lancashire (@endocrimes) and |
| 123 | +Agam Dua (@agamdua). |
0 commit comments