GitHub

@@ -0,0 +1,198 @@

1+

---

2+

content_type: "reference"

3+

title: What Happens After A Node Restart

4+

weight: 90

5+

---

6+7+

System components on a node sometimes restart, either because of an upgrade, a

8+

crash, or an explicit operator action. This page describes what happens to Pods

9+

and to the node when the {{< glossary_tooltip term_id="kubelet" text="kubelet" >}},

10+

the {{< glossary_tooltip term_id="container-runtime" text="container runtime" >}},

11+

or the node as a whole restarts.

12+13+

In a healthy cluster these restarts are usually safe and do not break running

14+

workloads. The sections below describe the effects to be aware of, which become

15+

more pronounced on large or heavily loaded nodes. The most disruptive case is a

16+

[node reboot](#impact-of-a-node-reboot), which encompasses both a container

17+

runtime restart and a kubelet restart, but with more consequences because every

18+

container on the node stops first.

19+20+

## Impact of a kubelet restart

21+22+

If only the kubelet restarts, the containers that are already running **continue to

23+

run**. The kubelet re-establishes its view of the Node, and reconciles the running

24+

containers against the desired state. During this period of time, the following happens:

25+26+

* The kubelet re-initializes and re-synchronizes its caches, which produces a

27+

burst of requests to the {{< glossary_tooltip term_id="kube-apiserver" text="API server" >}}.

28+

On large nodes with many Pods this burst can be significant.

29+30+

* The node is temporarily reported as `NotReady` until the kubelet finishes

31+

initializing. While the node is `NotReady`, the

32+

{{< glossary_tooltip term_id="kube-scheduler" text="scheduler" >}} does not

33+

place new Pods on it.

34+35+

* [Node heartbeats](/docs/concepts/architecture/nodes/#node-heartbeats) pause

36+

while the kubelet is down and resume once it has restarted and finished

37+

initializing, when the kubelet renews its `Lease` object and posts node status

38+

again.

39+40+

* The kubelet preserves the readiness of running containers across a restart.

41+

Each Pod's readiness drives

42+

{{< glossary_tooltip term_id="endpoint-slice" text="EndpointSlices" >}},

43+

Endpoints, and

44+

downstream configuration (such as Gateways or Ingresses); this means that resetting

45+

container readiness on every restart would place a large

46+

load on the API server and on components that watch endpoint state, and could

47+

briefly remove healthy Pods from Service load balancing. This behavior is

48+

described in

49+

[KEP-4781: Fix inconsistent container ready state after kubelet restart](https://www.kubernetes.dev/resources/keps/4781/).

50+

Resetting container readiness to `false` on every restart was the default

51+

behavior for a long time. The `ChangeContainerStatusOnKubeletRestart`

52+

[feature gate](/docs/reference/command-line-tools-reference/feature-gates/)

53+

lets you revert to that behavior, but it is a deprecated legacy escape hatch

54+

that is slated for removal, so you should not rely on it. For more detail, see

55+

[Pod behavior during kubelet restarts](/docs/concepts/workloads/pods/pod-lifecycle/#kubelet-restarts).

56+57+

* During the initial kubelet startup,

58+

{{< glossary_tooltip term_id="garbage-collection" text="Garbage collection" >}}

59+

of unused images and containers, and Pod

60+

[evictions](/docs/concepts/scheduling-eviction/node-pressure-eviction/) driven

61+

by node-pressure, are paused. This pause continues for a short

62+

grace period after the kubelet has completed its main startup routines.

63+

This delay can slow the node's reaction to memory or disk pressure.

64+65+

* Ongoing image pulls are cancelled. Depending on the container runtime, a

66+

cancelled pull may have to start over from the beginning when it is retried.

67+68+

* Pod admission runs again for the Pods on the node as the kubelet replays them

69+

through its admission checks. If the node's

70+

{{< glossary_tooltip term_id="label" text="labels" >}} or

71+

{{< glossary_tooltip term_id="taint" text="taints" >}} have changed while

72+

the kubelet was down, a Pod can fail admission and be rejected even though it

73+

was already running. This is an existing behavior, and whether it should be

74+

considered a bug is still debated; see

75+

[kubernetes/kubernetes#123859](https://github.com/kubernetes/kubernetes/issues/123859)

76+

for the discussion and details.

77+78+

Overall, in a healthy cluster a kubelet restart does not break running

79+

workloads. On large clusters with overcommitted nodes, however, the

80+

re-initialization load and the paused garbage collection and eviction can

81+

contribute to system instability.

82+83+

Kubernetes does not define the behavior of your

84+

container runtime if you restart it. Depending on the container runtime

85+

you use, a restart may trigger a stop or restart for

86+

all local containers.

87+

However, most container runtimes used with Kubernetes

88+

use a configuration that allows you to restart the

89+

runtime and leave containers executing.

90+91+

## Impact of a container runtime restart

92+93+

When the container runtime (such as

94+

{{< glossary_tooltip term_id="containerd" text="containerd" >}} or CRI-O)

95+

restarts, the kubelet loses its connection to the runtime until it comes back.

96+

During this window:

97+98+

* `exec` [probes](/docs/concepts/workloads/pods/pod-lifecycle/#container-probes)

99+

fail for the duration of the restart, because the kubelet cannot run commands

100+

inside containers. With a short timeout and failure threshold, a failing

101+

liveness probe can cause a container to be restarted, and a failing readiness

102+

probe can cause the Pod to flap out of the `Ready` state.

103+104+

* The node is reported as `NotReady` by the kubelet, which blocks scheduling of

105+

new Pods onto the node.

106+107+

* Container operations such as restarts, initialization, and status updates are

108+

delayed until the runtime is available again.

109+110+

* If an

111+

{{< glossary_tooltip term_id="init-container" text="init container" >}} was executing

112+

when the runtime restarted, its execution state can be lost, in which case the

113+

init container runs again.

114+115+

* In rare cases, interrupting an operation at a precise moment can leave state

116+

inconsistent:

117+118+

* An interrupted image pull may leave inconsistent image layers, which can

119+

render the image unusable until it is pulled again.

120+121+

* An interrupted sandbox creation, if it is terminated in the middle of a CNI

122+

or NRI call, may leave the sandbox in an inconsistent state, with CNI only

123+

partially initialized and the possibility of a resource leak.

124+125+

Interrupting an operation at a precise moment is a low-probability situation, so

126+

restarting a container runtime is generally a safe operation. On a heavily loaded

127+

node, where every operation is slower, the window for interrupting a critical

128+

operation is larger and the probability of hitting one of these edge cases

129+

increases.

130+131+

## Impact of a node reboot

132+133+

A node reboot is the most disruptive of these events, because every container on

134+

the node stops. A reboot encompasses both a container runtime restart and a

135+

kubelet restart, but with more consequences: where a standalone kubelet or

136+

runtime restart leaves the already-running containers in place, a reboot stops

137+

every container first. After the node boots, the kubelet and container runtime

138+

start again with no containers actually running.

139+140+

Before a planned reboot you can reduce the impact by cordoning the node, so the

141+

scheduler stops placing new Pods on it, and then

142+

{{< glossary_tooltip term_id="drain" text="draining" >}} it to evict the existing

143+

Pods gracefully. When

144+

[graceful node shutdown](/docs/concepts/cluster-administration/node-shutdown/#graceful-node-shutdown)

145+

is enabled, the kubelet also attempts to stop running Pods cleanly when it

146+

detects that the node is shutting down.

147+148+

When the node comes back:

149+150+

* The reboot stops all containers, and the kubelet recreates them when the node

151+

comes back. If the node stays down longer than the configured

152+

toleration period described below, only Pods managed by a controller

153+

(such as a

154+

{{< glossary_tooltip term_id="deployment" text="Deployment" >}},

155+

{{< glossary_tooltip term_id="statefulset" text="StatefulSet" >}}, or

156+

{{< glossary_tooltip term_id="daemonset" text="DaemonSet" >}})

157+

get a replacement Pod. The replacement Pod might schedule onto a different

158+

node. Standalone Pods (without another object or controller managing them) are

159+

**not** recreated after deletion.

160+161+

* The node renews the lease and reconcile it's status. It is reported as `NotReady` until the kubelet,

162+

container runtime, and network are ready.

163+

While the node is `NotReady`, the node may be

164+

[tainted](/docs/concepts/scheduling-eviction/taint-and-toleration/)

165+

with `node.kubernetes.io/not-ready`, and after the configured toleration

166+

period the control plane can evict Pods that do not tolerate it.

167+168+

* The kubelet re-runs admission for the Pods assigned to the node, so the label

169+

and taint considerations described under

170+

[kubelet restart](#impact-of-a-kubelet-restart) apply here as well.

171+172+

* For Pods that request devices, the kubelet calls the relevant

173+

[device plugin](/docs/concepts/extend-kubernetes/compute-storage-net/device-plugins/)

174+

again to confirm the device allocations for the Pods that are being restored on

175+

the node. The device plugin must re-register with the kubelet after the reboot

176+

so that these allocations can be reconciled.

177+178+

* Local storage tied to the lifetime of a container or Pod can be lost. A

179+

container's writable layer is discarded when the container is recreated, so

180+

data written there does not survive the reboot. An

181+

[`emptyDir`](/docs/concepts/storage/volumes/#emptydir) volume lasts as long as

182+

the Pod stays on the node: a memory-backed `emptyDir` (`medium: Memory`) is

183+

always lost on reboot because it is held in RAM, while a disk-backed `emptyDir`

184+

survives a reboot as long as the Pod is not evicted or deleted, and is removed

185+

only when the Pod leaves the node.

186+187+

For workloads that must tolerate node reboots, run Pods through a controller, use

188+

[persistent volumes](/docs/concepts/storage/persistent-volumes/) for data that

189+

must survive, and configure

190+

[disruption budgets](/docs/concepts/workloads/pods/disruptions/) and probes so

191+

that traffic is only sent to Pods once they are ready.

192+193+

## {{% heading "whatsnext" %}}

194+195+

* Learn about the kubelet's [sync loop](/docs/reference/node/kubelet-sync-loop/).

196+

* Read about [Pod lifecycle](/docs/concepts/workloads/pods/pod-lifecycle/).

197+

* Read about [node-pressure eviction](/docs/concepts/scheduling-eviction/node-pressure-eviction/).

198+

* Learn how to [safely drain a node](/docs/tasks/administer-cluster/safely-drain-node/).

Read the original on github.com ↗