Skip to content

Commit 4f193fe

Browse files
authored
Merge pull request #30710 from sftim/20211201_improve_probe_documentation
Improve documentation for container probes
2 parents 3baac6d + 8a0f330 commit 4f193fe

File tree

2 files changed

+99
-65
lines changed

2 files changed

+99
-65
lines changed

content/en/docs/concepts/workloads/pods/pod-lifecycle.md

Lines changed: 71 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -233,57 +233,87 @@ When a Pod's containers are Ready but at least one custom condition is missing o
233233

234234
## Container probes
235235

236-
A [Probe](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#probe-v1-core) is a diagnostic
236+
A _probe_ is a diagnostic
237237
performed periodically by the
238238
[kubelet](/docs/reference/command-line-tools-reference/kubelet/)
239-
on a Container. To perform a diagnostic,
240-
the kubelet calls a
241-
[Handler](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#handler-v1-core) implemented by
242-
the container. There are three types of handlers:
239+
on a container. To perform a diagnostic,
240+
the kubelet either executes code within the container, or makes
241+
a network request.
243242

244-
* [ExecAction](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#execaction-v1-core):
245-
Executes a specified command inside the container. The diagnostic
246-
is considered successful if the command exits with a status code of 0.
243+
### Check mechanisms {#probe-check-methods}
244+
245+
There are four different ways to check a container using a probe.
246+
Each probe must define exactly one of these four mechanisms:
247247

248-
* [TCPSocketAction](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#tcpsocketaction-v1-core):
249-
Performs a TCP check against the Pod's IP address on
250-
a specified port. The diagnostic is considered successful if the port is open.
248+
`exec`
249+
: Executes a specified command inside the container. The diagnostic
250+
is considered successful if the command exits with a status code of 0.
251251

252-
* [HTTPGetAction](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#httpgetaction-v1-core):
253-
Performs an HTTP `GET` request against the Pod's IP
254-
address on a specified port and path. The diagnostic is considered successful
255-
if the response has a status code greater than or equal to 200 and less than 400.
252+
`grpc`
253+
: Performs a remote procedure call using [gRPC](https://grpc.io/).
254+
The target should implement
255+
[gRPC health checks](https://grpc.io/grpc/core/md_doc_health-checking.html).
256+
The diagnostic is considered successful if the `status`
257+
of the response is `SERVING`.
258+
gRPC probes are an alpha feature and are only available if you
259+
enable the `GRPCContainerProbe`
260+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/).
261+
262+
`httpGet`
263+
: Performs an HTTP `GET` request against the Pod's IP
264+
address on a specified port and path. The diagnostic is
265+
considered successful if the response has a status code
266+
greater than or equal to 200 and less than 400.
267+
268+
`tcpSocket`
269+
: Performs a TCP check against the Pod's IP address on
270+
a specified port. The diagnostic is considered successful if
271+
the port is open. If the remote system (the container) closes
272+
the connection immediately after it opens, this counts as healthy.
273+
274+
### Probe outcome
256275

257276
Each probe has one of three results:
258277

259-
* `Success`: The container passed the diagnostic.
260-
* `Failure`: The container failed the diagnostic.
261-
* `Unknown`: The diagnostic failed, so no action should be taken.
278+
`Success`
279+
: The container passed the diagnostic.
262280

263-
The kubelet can optionally perform and react to three kinds of probes on running
264-
containers:
281+
`Failure`
282+
: The container failed the diagnostic.
283+
284+
`Unknown`
285+
: The diagnostic failed (no action should be taken, and the kubelet
286+
will make further checks).
265287

266-
* `livenessProbe`: Indicates whether the container is running. If
267-
the liveness probe fails, the kubelet kills the container, and the container
268-
is subjected to its [restart policy](#restart-policy). If a Container does not
269-
provide a liveness probe, the default state is `Success`.
288+
### Types of probe
270289

271-
* `readinessProbe`: Indicates whether the container is ready to respond to requests.
272-
If the readiness probe fails, the endpoints controller removes the Pod's IP
273-
address from the endpoints of all Services that match the Pod. The default
274-
state of readiness before the initial delay is `Failure`. If a Container does
275-
not provide a readiness probe, the default state is `Success`.
290+
The kubelet can optionally perform and react to three kinds of probes on running
291+
containers:
276292

277-
* `startupProbe`: Indicates whether the application within the container is started.
278-
All other probes are disabled if a startup probe is provided, until it succeeds.
279-
If the startup probe fails, the kubelet kills the container, and the container
280-
is subjected to its [restart policy](#restart-policy). If a Container does not
281-
provide a startup probe, the default state is `Success`.
293+
`livenessProbe`
294+
: Indicates whether the container is running. If
295+
the liveness probe fails, the kubelet kills the container, and the container
296+
is subjected to its [restart policy](#restart-policy). If a container does not
297+
provide a liveness probe, the default state is `Success`.
298+
299+
`readinessProbe`
300+
: Indicates whether the container is ready to respond to requests.
301+
If the readiness probe fails, the endpoints controller removes the Pod's IP
302+
address from the endpoints of all Services that match the Pod. The default
303+
state of readiness before the initial delay is `Failure`. If a container does
304+
not provide a readiness probe, the default state is `Success`.
305+
306+
`startupProbe`
307+
: Indicates whether the application within the container is started.
308+
All other probes are disabled if a startup probe is provided, until it succeeds.
309+
If the startup probe fails, the kubelet kills the container, and the container
310+
is subjected to its [restart policy](#restart-policy). If a container does not
311+
provide a startup probe, the default state is `Success`.
282312

283313
For more information about how to set up a liveness, readiness, or startup probe,
284314
see [Configure Liveness, Readiness and Startup Probes](/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/).
285315

286-
### When should you use a liveness probe?
316+
#### When should you use a liveness probe?
287317

288318
{{< feature-state for_k8s_version="v1.0" state="stable" >}}
289319

@@ -295,7 +325,7 @@ with the Pod's `restartPolicy`.
295325
If you'd like your container to be killed and restarted if a probe fails, then
296326
specify a liveness probe, and specify a `restartPolicy` of Always or OnFailure.
297327

298-
### When should you use a readiness probe?
328+
#### When should you use a readiness probe?
299329

300330
{{< feature-state for_k8s_version="v1.0" state="stable" >}}
301331

@@ -329,7 +359,7 @@ The Pod remains in the unready state while it waits for the containers in the Po
329359
to stop.
330360
{{< /note >}}
331361

332-
### When should you use a startup probe?
362+
#### When should you use a startup probe?
333363

334364
{{< feature-state for_k8s_version="v1.20" state="stable" >}}
335365

@@ -451,13 +481,13 @@ This avoids a resource leak as Pods are created and terminated over time.
451481
## {{% heading "whatsnext" %}}
452482

453483
* Get hands-on experience
454-
[attaching handlers to Container lifecycle events](/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/).
484+
[attaching handlers to container lifecycle events](/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/).
455485

456486
* Get hands-on experience
457487
[configuring Liveness, Readiness and Startup Probes](/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/).
458488

459489
* Learn more about [container lifecycle hooks](/docs/concepts/containers/container-lifecycle-hooks/).
460490

461-
* For detailed information about Pod / Container status in the API, see [PodStatus](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podstatus-v1-core)
462-
and
463-
[ContainerStatus](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#containerstatus-v1-core).
491+
* For detailed information about Pod and container status in the API, see
492+
the API reference documentation covering
493+
[`.status`](/docs/reference/kubernetes-api/workload-resources/pod-v1/#PodStatus) for Pod.

content/en/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes.md

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -226,51 +226,56 @@ kubectl describe pod goproxy
226226

227227
If your application implements [gRPC Health Checking Protocol](https://github.com/grpc/grpc/blob/master/doc/health-checking.md),
228228
kubelet can be configured to use it for application liveness checks.
229+
You must enable the `GRPCContainerProbe`
230+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
231+
in order to configure checks that rely on gRPC.
232+
233+
Here is an example manifest:
229234

230235
{{< codenew file="pods/probe/grpc-liveness.yaml">}}
231236

232237
To use a gRPC probe, `port` must be configured. If the health endpoint is configured
233-
on a non-default service, `service` must be configured.
238+
on a non-default service, you must also specify the `service`.
234239

235240
{{< note >}}
236241
Unlike HTTP and TCP probes, named ports cannot be used and custom host cannot be configured.
237242
{{< /note >}}
238243

239-
Configuration problems (e.g. incorrect port and service, unimplemented health checking protocol)
244+
Configuration problems (for example: incorrect port and service, unimplemented health checking protocol)
240245
are considered a probe failure, similar to HTTP and TCP probes.
241246

242-
Before Kubernetes 1.23, gRPC health probes were often implemented using [grpc-health-probe](https://github.com/grpc-ecosystem/grpc-health-probe/),
243-
as described in the blog post [Health checking gRPC servers on Kubernetes](/blog/2018/10/01/health-checking-grpc-servers-on-kubernetes/).
244-
The built-in gRPC probes behavior is similar to one implemented by grpc-health-probe.
245-
When migrating from grpc-health-probe to built-in probes, remember the following differences:
246-
247-
- Built-in probes will run against pod IP, unlike grpc-health-probe that often runs against `127.0.0.1`.
248-
Be sure to configure your gRPC endpoint to listen for pod IP address.
249-
- Built-in probes do not currently support any authentication parameters (like `-tls`).
250-
- There are no error codes in built-in probes. All errors are considered as probe failures.
251-
- If `ExecProbeTimeout` feature gate is set to `false`, grpc-health-probe will NOT
252-
respect `timeoutSeconds` setting (which defaults to 1s),
253-
while built-in probe will fail on timeout.
254-
255247
To try the gRPC liveness check, create a Pod using the command below.
256-
In the example below, etcd pod is configured to use gRPC liveness probe.
257-
248+
In the example below, the etcd pod is configured to use gRPC liveness probe.
258249

259250
```shell
260251
kubectl apply -f https://k8s.io/examples/pods/probe/content/en/examples/pods/probe/grpc-liveness.yaml
261252
```
262253

263-
After 15 seconds, view Pod events to verify that the liveness probes has not failed:
254+
After 15 seconds, view Pod events to verify that the liveness check has not failed:
264255

265256
```shell
266257
kubectl describe pod etcd-with-grpc
267258
```
268259

260+
Before Kubernetes 1.23, gRPC health probes were often implemented using [grpc-health-probe](https://github.com/grpc-ecosystem/grpc-health-probe/),
261+
as described in the blog post [Health checking gRPC servers on Kubernetes](/blog/2018/10/01/health-checking-grpc-servers-on-kubernetes/).
262+
The built-in gRPC probes behavior is similar to one implemented by grpc-health-probe.
263+
When migrating from grpc-health-probe to built-in probes, remember the following differences:
264+
265+
- Built-in probes run against the pod IP address, unlike grpc-health-probe that often runs against `127.0.0.1`.
266+
Be sure to configure your gRPC endpoint to listen on the Pod's IP address.
267+
- Built-in probes do not support any authentication parameters (like `-tls`).
268+
- There are no error codes for built-in probes. All errors are considered as probe failures.
269+
- If `ExecProbeTimeout` feature gate is set to `false`, grpc-health-probe does **not** respect the `timeoutSeconds` setting (which defaults to 1s),
270+
while built-in probe would fail on timeout.
271+
269272
## Use a named port
270273

271274
You can use a named
272-
[ContainerPort](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#containerport-v1-core)
273-
for HTTP and TCP probes. Note, gRPC probe does not support named port.
275+
[`port`](/docs/reference/kubernetes-api/workload-resources/pod-v1/#ports)
276+
for HTTP and TCP probes. (gRPC probes do not support named ports).
277+
278+
For example:
274279

275280
```yaml
276281
ports:
@@ -533,12 +538,11 @@ It will be rejected by the API server.
533538

534539
## {{% heading "whatsnext" %}}
535540

536-
537541
* Learn more about
538542
[Container Probes](/docs/concepts/workloads/pods/pod-lifecycle/#container-probes).
539543

540544
You can also read the API references for:
541545

542-
* [Pod](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#pod-v1-core)
543-
* [Container](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#container-v1-core)
544-
* [Probe](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#probe-v1-core)
546+
* [Pod](/docs/reference/kubernetes-api/workload-resources/pod-v1/), and specifically:
547+
* [container(s)](/docs/reference/kubernetes-api/workload-resources/pod-v1/#Container)
548+
* [probe(s)](/docs/reference/kubernetes-api/workload-resources/pod-v1/#Probe)

0 commit comments

Comments
 (0)