Skip to content

Commit d3c91e6

Browse files
authored
Merge pull request #27081 from mburke5678/BZ-1883052
[Readiness/Liveness] the initialDelaySeconds behavior does not match the documentation
2 parents 1ef4420 + 30a139e commit d3c91e6

File tree

4 files changed

+268
-218
lines changed

4 files changed

+268
-218
lines changed

applications/application-health.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:context: application-health
22
[id="application-health"]
3-
= Monitoring application health
3+
= Monitoring application health by using health checks
44
include::modules/common-attributes.adoc[]
55

66
toc::[]

modules/application-health-about.adoc

Lines changed: 187 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -5,125 +5,214 @@
55
[id="application-health-about_{context}"]
66
= Understanding health checks
77

8-
A probe is a Kubernetes action that periodically performs diagnostics on a
9-
running container. Currently, two types of probes exist, each serving a
10-
different purpose.
11-
12-
Readiness Probe::
13-
A Readiness check determines if the container in which it is scheduled is ready to service requests. If
14-
the readiness probe fails a container, the endpoints controller ensures the
15-
container has its IP address removed from the endpoints of all services. A
16-
readiness probe can be used to signal to the endpoints controller that even
17-
though a container is running, it should not receive any traffic from a proxy.
18-
19-
For example, a Readiness check can control which pods are used. When a pod is not ready,
20-
it is removed.
21-
22-
Liveness Probe::
23-
A Liveness checks determines if the container in which it is scheduled is still
24-
running. If the liveness probe fails due to a condition such as a deadlock, the kubelet kills the container The container then
8+
A health check periodically performs diagnostics on a
9+
running container using any combination of the readiness, liveness, and startup health checks.
10+
11+
You can include one or more probes in the specification for the pod that contains the container which you want to perform the health checks.
12+
13+
[NOTE]
14+
====
15+
If you want to add or edit health checks in an existing pod, you must edit the pod deployment configuration or use the *Developer* perspective in the web console. You cannot use the CLI to add or edit health checks for an existing pod.
16+
====
17+
18+
Readiness probe::
19+
A _readiness probe_ determines if a container is ready to accept service requests. If
20+
the readiness probe fails for a container, the kubelet removes the pod from the list of available service endpoints.
21+
+
22+
After a failure, the probe continues to examine the pod. If the pod becomes available, the kubelet adds the pod to the list of available service endpoints.
23+
24+
Liveness health check::
25+
A _liveness probe_ determines if a container is still
26+
running. If the liveness probe fails due to a condition such as a deadlock, the kubelet kills the container. The pod then
2527
responds based on its restart policy.
28+
+
29+
For example, a liveness probe on a pod with a `restartPolicy` of `Always` or `OnFailure`
30+
kills and restarts the container.
31+
32+
Startup probe::
33+
A _startup probe_ indicates whether the application within a container is started. All other probes are disabled until the startup succeeds. If the startup probe does not succeed within a specified time period, the kubelet kills the container, and the container is subject to the pod `restartPolicy`.
34+
+
35+
Some applications can require additional start-up time on their first initialization. You can use a startup probe with a liveness or readiness probe to delay that probe long enough to handle lengthy start-up time using the `failureThreshold` and `periodSeconds` parameters.
36+
+
37+
For example, you can add a startup probe, with a `failureThreshold` of 30 seconds and a `periodSeconds` of 10 seconds (30 * 10 = 300s) for a maximum of 5 minutes, to a liveness probe. After the startup probe succeeds the first time, the liveness probe takes over.
38+
39+
You can configure liveness, readiness, and startup probes with any of the following types of tests:
40+
41+
* HTTP `GET`: When using an HTTP `GET` test, the test determines the healthiness of the container by using a web hook. The test is successful if the HTTP response code is between `200` and `399`.
42+
+
43+
You can use an HTTP `GET` test with applications that return HTTP status codes when completely initialized.
44+
45+
* Container Command: When using a container command test, the probe executes a command inside the container. The probe is successful if the test exits with a `0` status.
46+
47+
* TCP socket: When using a TCP socket test, the probe attempts to open a socket to the container. The container is only
48+
considered healthy if the probe can establish a connection. You can use a TCP socket test with applications that do not start listening until
49+
initialization is complete.
50+
51+
You can configure several fields to control the behavior of a probe:
52+
53+
* `initialDelaySeconds`: The time, in seconds, after the container starts before the probe can be scheduled. The defaults is `0`.
54+
* `periodSeconds`: The delay, in seconds, between performing probes. The default is `10`.
55+
* `timeoutSeconds`: The number of seconds of inactivity after which the probe times out and the container is assumed to have failed. The defaults is `1`.
56+
* `successThreshold`: The number of times that the probe must report success after a failure in order to reset the container status to successful. The value must be `1` for a liveness probe. The default is `1`.
57+
* `failureThreshold`: The number of times that the probe is allowed to fail. The default is 3. After the specified attempts:
58+
** for a liveness probe, the container is restarted
59+
** for a readiness probe, the pod is marked `Unready`
60+
** for a startup probe, the container is killed and is subject to the pod's `restartPolicy`
61+
+
62+
[NOTE]
63+
====
64+
The `timeoutSeconds` parameter has no effect on the readiness and liveness
65+
probes for container command probes, as {product-title} cannot time out on an exec call into
66+
the container. One way to implement a timeout in a container command probe is by using the `exec-timeout` command to run your
67+
liveness or readiness probes, as shown in the examples.
68+
====
69+
70+
[discrete]
71+
[id="application-health-examples"]
72+
== Example probes
73+
74+
The following are samples of different probes as they would appear in an object specification.
75+
76+
.Sample readiness probe with a container command readiness probe in a pod spec
77+
[source,yaml]
78+
----
79+
apiVersion: v1
80+
kind: Pod
81+
metadata:
82+
labels:
83+
test: health-check
84+
name: my-application
85+
...
86+
spec:
87+
containers:
88+
- name: goproxy-app <1>
89+
args:
90+
image: k8s.gcr.io/goproxy:0.1 <2>
91+
readinessProbe: <3>
92+
exec: <4>
93+
command: <5>
94+
- cat
95+
- /tmp/healthy
96+
...
97+
----
2698

27-
For example, a liveness probe on a node with a `restartPolicy` of `Always` or `OnFailure`
28-
kills and restarts the Container on the node.
99+
<1> The container name.
100+
<2> The container image to deploy.
101+
<3> A readiness probe.
102+
<4> A container command test.
103+
<5> The commands to execute on the container.
29104

30-
.Sample Liveness Check
105+
.Sample container command startup probe and liveness probe with container command tests in a pod spec
31106
[source,yaml]
32107
----
33108
apiVersion: v1
34109
kind: Pod
35110
metadata:
36111
labels:
37-
test: liveness
38-
name: liveness-http
112+
test: health-check
113+
name: my-application
114+
...
39115
spec:
40116
containers:
41-
- name: liveness-http
42-
image: k8s.gcr.io/liveness <1>
117+
- name: goproxy-app <1>
43118
args:
44-
- /server
45-
livenessProbe: <2>
46-
httpGet: <3>
47-
# host: my-host
48-
# scheme: HTTPS
119+
image: k8s.gcr.io/goproxy:0.1 <2>
120+
livenessProbe: <3>
121+
httpGet: <4>
122+
scheme: HTTPS <5>
49123
path: /healthz
50-
port: 8080
124+
port: 8080 <6>
51125
httpHeaders:
52126
- name: X-Custom-Header
53127
value: Awesome
54-
initialDelaySeconds: 15 <4>
55-
timeoutSeconds: 1 <5>
56-
name: liveness <6>
57-
----
58-
<1> Specifies the image to use for the liveness probe.
59-
<2> Specifies the type of heath check.
60-
<3> Specifies the type of Liveness check:
61-
* HTTP Checks. Specify `httpGet`.
62-
* Container Execution Checks. Specify `exec`.
63-
* TCP Socket Check. Specify `tcpSocket`.
64-
<4> Specifies the number of seconds before performing the first probe after the container starts.
65-
<5> Specifies the number of seconds between probes.
66-
67-
68-
.Sample Liveness check output wth unhealthy container
69-
[source,terminal]
70-
----
71-
$ oc describe pod pod1
128+
startupProbe: <7>
129+
httpGet: <8>
130+
path: /healthz
131+
port: 8080 <9>
132+
failureThreshold: 30 <10>
133+
periodSeconds: 10 <11>
134+
...
72135
----
73136

74-
.Example output
75-
[source,terminal]
137+
<1> The container name.
138+
<2> Specify the container image to deploy.
139+
<3> A liveness probe.
140+
<4> An HTTP `GET` test.
141+
<5> The internet scheme: `HTTP` or `HTTPS`. The default value is `HTTP`.
142+
<6> The port on which the container is listening.
143+
<7> A startup probe.
144+
<8> An HTTP `GET` test.
145+
<9> The port on which the container is listening.
146+
<10> The number of times to try the probe after a failure.
147+
<11> The number of seconds to perform the probe.
148+
149+
.Sample liveness probe with a container command test that uses a timeout in a pod spec
150+
[source,yaml]
76151
----
77-
....
78-
79-
FirstSeen LastSeen Count From SubobjectPath Type Reason Message
80-
--------- -------- ----- ---- ------------- -------- ------ -------
81-
37s 37s 1 {default-scheduler } Normal Scheduled Successfully assigned liveness-exec to worker0
82-
36s 36s 1 {kubelet worker0} spec.containers{liveness} Normal Pulling pulling image "k8s.gcr.io/busybox"
83-
36s 36s 1 {kubelet worker0} spec.containers{liveness} Normal Pulled Successfully pulled image "k8s.gcr.io/busybox"
84-
36s 36s 1 {kubelet worker0} spec.containers{liveness} Normal Created Created container with docker id 86849c15382e; Security:[seccomp=unconfined]
85-
36s 36s 1 {kubelet worker0} spec.containers{liveness} Normal Started Started container with docker id 86849c15382e
86-
2s 2s 1 {kubelet worker0} spec.containers{liveness} Warning Unhealthy Liveness probe failed: cat: can't open '/tmp/healthy': No such file or directory
152+
apiVersion: v1
153+
kind: Pod
154+
metadata:
155+
labels:
156+
test: health-check
157+
name: my-application
158+
...
159+
spec:
160+
containers:
161+
- name: goproxy-app <1>
162+
args:
163+
image: k8s.gcr.io/goproxy:0.1 <2>
164+
livenessProbe: <3>
165+
exec: <4>
166+
command: <5>
167+
- /bin/bash
168+
- '-c'
169+
- timeout 60 /opt/eap/bin/livenessProbe.sh
170+
periodSeconds: 10 <6>
171+
successThreshold: 1 <7>
172+
failureThreshold: 3 <8>
173+
...
87174
----
88175

89-
Startup Probe::
90-
Legacy applications can require additional startup time on their first initialization. This situation can make it difficult to set up liveness probe parameters without compromising the fast response to deadlocks that a liveness probe provides. To prevent containers from starting slowly, configure a startup probe using the same command, HTTP or TCP check, with a `failureThreshold * periodSeconds` value long enough to handle the worst case startup time.
91-
92-
For example, add the startup probe to the to the previous liveness check sample using a maximum of 5 minutes (30 * 10 = 300s). After the startup probe succeeds the first time, the liveness probe takes over to provide a fast response to container deadlocks. If the startup probe never succeeds within the specified time period, the container is killed and is subject to the pod's `restartPolicy`.
176+
<1> The container name.
177+
<2> Specify the container image to deploy.
178+
<3> The liveness probe.
179+
<4> The type of probe, here a container command probe.
180+
<5> The command line to execute inside the container.
181+
<6> How often in seconds to perform the probe.
182+
<7> The number of number of consecutive successes needed to show success after a failure.
183+
<8> The number of times to try the probe after a failure.
93184

94-
95-
.Sample Startup Check
96-
[source, yaml]
185+
.Sample readiness probe and liveness probe with a TCP socket test in a deployment
186+
[source,yaml]
97187
----
98-
startupProbe:
99-
httpGet:
100-
path: /healthz
101-
port: liveness-port <1>
102-
failureThreshold: 30 <2>
103-
periodSeconds: 10 <3>
188+
kind: Deployment
189+
apiVersion: apps/v1
190+
...
191+
spec:
192+
...
193+
template:
194+
spec:
195+
containers:
196+
- resources: {}
197+
readinessProbe: <1>
198+
tcpSocket:
199+
port: 8080
200+
timeoutSeconds: 1
201+
periodSeconds: 10
202+
successThreshold: 1
203+
failureThreshold: 3
204+
terminationMessagePath: /dev/termination-log
205+
name: ruby-ex
206+
livenessProbe: <2>
207+
tcpSocket:
208+
port: 8080
209+
initialDelaySeconds: 15
210+
timeoutSeconds: 1
211+
periodSeconds: 10
212+
successThreshold: 1
213+
failureThreshold: 3
214+
...
104215
----
105-
<1> Specifies the liveness port number.
106-
<2> Specifies the maximum number of startup attempts before the container is killed.
107-
<3> Specifies the number of seconds the application has to attempt starting.
108-
109-
110-
[id="application-health-about_types_{context}"]
111-
== Understanding the types of health checks
112-
113-
Liveness checks and Readiness checks can be configured in three ways:
114-
115-
HTTP Checks::
116-
The kubelet uses a web hook to determine the healthiness of the container. The
117-
check is deemed successful if the HTTP response code is between 200 and 399.
118-
119-
A HTTP check is ideal for applications that return HTTP status codes
120-
when completely initialized.
121-
122-
Container Execution Checks::
123-
The kubelet executes a command inside the container. Exiting the check with
124-
status 0 is considered a success.
125-
126-
TCP Socket Checks::
127-
The kubelet attempts to open a socket to the container. The container is only
128-
considered healthy if the check can establish a connection. A TCP socket check is ideal for applications that do not start listening until
129-
initialization is complete.
216+
<1> The readiness probe.
217+
<2> The liveness probe.
218+

0 commit comments

Comments
 (0)