To configure readiness, liveness, and startup probes, add one or more probes to the specification for the pod that contains the container which you want to perform the health checks
|
Note
|
If you want to add or edit health checks in an existing pod, you must edit the pod |
To add probes for a container:
-
Create a
Podobject to add one or more probes:apiVersion: v1 kind: Pod metadata: labels: test: health-check name: my-application spec: containers: - name: my-container (1) args: image: k8s.gcr.io/goproxy:0.1 (2) livenessProbe: (3) tcpSocket: (4) port: 8080 (5) initialDelaySeconds: 15 (6) periodSeconds: 20 (7) timeoutSeconds: 10 (8) readinessProbe: (9) httpGet: (10) host: my-host (11) scheme: HTTPS (12) path: /healthz port: 8080 (13) startupProbe: (14) exec: (15) command: (16) - cat - /tmp/healthy failureThreshold: 30 (17) periodSeconds: 20 (18) timeoutSeconds: 10 (19)
-
Specify the container name.
-
Specify the container image to deploy.
-
Optional: Create a Liveness probe.
-
Specify a test to perform, here a TCP Socket test.
-
Specify the port on which the container is listening.
-
Specify the time, in seconds, after the container starts before the probe can be scheduled.
-
Specify the number of seconds to perform the probe. The default is
10. This value must be greater thantimeoutSeconds. -
Specify the number of seconds of inactivity after which the probe is assumed to have failed. The default is
1. This value must be lower thanperiodSeconds. -
Optional: Create a Readiness probe.
-
Specify the type of test to perform, here an HTTP test.
-
Specify a host IP address. When
hostis not defined, thePodIPis used. -
Specify
HTTPorHTTPS. Whenschemeis not defined, theHTTPscheme is used. -
Specify the port on which the container is listening.
-
Optional: Create a Startup probe.
-
Specify the type of test to perform, here an Container Execution probe.
-
Specify the commands to execute on the container.
-
Specify the number of times to try the probe after a failure.
-
Specify the number of seconds to perform the probe. The default is
10. This value must be greater thantimeoutSeconds. -
Specify the number of seconds of inactivity after which the probe is assumed to have failed. The default is
1. This value must be lower thanperiodSeconds.NoteIf the
initialDelaySecondsvalue is lower than theperiodSecondsvalue, the first Readiness probe occurs at some point between the two periods due to an issue with timers.The
timeoutSecondsvalue must be lower than theperiodSecondsvalue.
-
-
Create the
Podobject:$ oc create -f <file-name>.yaml -
Verify the state of the health check pod:
$ oc describe pod health-checkExample outputEvents: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 9s default-scheduler Successfully assigned openshift-logging/liveness-exec to ip-10-0-143-40.ec2.internal Normal Pulling 2s kubelet, ip-10-0-143-40.ec2.internal pulling image "k8s.gcr.io/liveness" Normal Pulled 1s kubelet, ip-10-0-143-40.ec2.internal Successfully pulled image "k8s.gcr.io/liveness" Normal Created 1s kubelet, ip-10-0-143-40.ec2.internal Created container Normal Started 1s kubelet, ip-10-0-143-40.ec2.internal Started containerThe following is the output of a failed probe that restarted a container:
Sample Liveness check output with unhealthy container$ oc describe pod pod1Example output.... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled <unknown> Successfully assigned aaa/liveness-http to ci-ln-37hz77b-f76d1-wdpjv-worker-b-snzrj Normal AddedInterface 47s multus Add eth0 [10.129.2.11/23] Normal Pulled 46s kubelet, ci-ln-37hz77b-f76d1-wdpjv-worker-b-snzrj Successfully pulled image "k8s.gcr.io/liveness" in 773.406244ms Normal Pulled 28s kubelet, ci-ln-37hz77b-f76d1-wdpjv-worker-b-snzrj Successfully pulled image "k8s.gcr.io/liveness" in 233.328564ms Normal Created 10s (x3 over 46s) kubelet, ci-ln-37hz77b-f76d1-wdpjv-worker-b-snzrj Created container liveness Normal Started 10s (x3 over 46s) kubelet, ci-ln-37hz77b-f76d1-wdpjv-worker-b-snzrj Started container liveness Warning Unhealthy 10s (x6 over 34s) kubelet, ci-ln-37hz77b-f76d1-wdpjv-worker-b-snzrj Liveness probe failed: HTTP probe failed with statuscode: 500 Normal Killing 10s (x2 over 28s) kubelet, ci-ln-37hz77b-f76d1-wdpjv-worker-b-snzrj Container liveness failed liveness probe, will be restarted Normal Pulling 10s (x3 over 47s) kubelet, ci-ln-37hz77b-f76d1-wdpjv-worker-b-snzrj Pulling image "k8s.gcr.io/liveness" Normal Pulled 10s kubelet, ci-ln-37hz77b-f76d1-wdpjv-worker-b-snzrj Successfully pulled image "k8s.gcr.io/liveness" in 244.116568ms