Kubernetes Container Probes

From NovaOrdis Knowledge Base
Revision as of 23:39, 2 October 2019 by Ovidiu (talk | contribs) (→‎Overview)
Jump to navigation Jump to search

External

Internal

Overview

A probe is a diagnostic performed periodically by the kubelet on a container. The diagnostic is sometimes referred to as a probe. To perform the diagnostic, the kubelet calls a handler, that must be declared and implemented by the container. Each probe has one of these results:

  • Success - the container passed the diagnostic
  • Failure - the container failed the diagnostic
  • Unknown - the diagnostic itself filed so no action should be taken.

There are three kinds of probes: startup, liveness and readiness.

Handlers

A handler is a piece of logic declared and implemented by the container, which is used by Kubernetes control mechanism to draw conclusions about the state the container is in There are three types of handlers, described below. Any of these handlers can be used to perform startup, liveness and readiness checks.

ExecAction

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#execaction-v1-core

The exec action (declared as "exec:") executes a specified command inside the container. The diagnostic is considered successful if the command exits with a status code of 0.

TCPSocketAction

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#tcpsocketaction-v1-core

Performs a TCP check against the container’s IP address on a specified port. The diagnostic is considered successful if the port is open.

HTTPGetAction

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#httpgetaction-v1-core

Performs an HTTP GET request against the container’s IP address on a specified port and path. The diagnostic is considered successful if the response has a status code greater than or equal to 200 and less than 400

Container Startup Check

The startup check is performed by a startup probe.

Container Liveness Check

The result of the container liveness check is used by Kubernetes to know when to restart the container (Not the pod? How about atomicity?)

Container Readiness Check

The result of the container readiness check is used by Kubernetes to know when the container is ready to accept traffic. The pod is considered ready wen all of its containers are ready. The readiness check is used by services to decide whether to send traffic into the pod or not. Container will be removed from service endpoints if the probe fails.

Probe Template

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#probe-v1-core
kind: Pod
spec:
  containers:
  - name: ...
    readinessProbe|livenessProbe:
      exec:

Example:

readinessProbe:
  exec:
    command:
    - /bin/sh
    - -c
    - nodetool status | grep -E "^UN\s+${POD_IP}"
  failureThreshold: 3
  initialDelaySeconds: 90
  periodSeconds: 30
  successThreshold: 1
  timeoutSeconds: 5

Elements

initialDelaySeconds

Specifies the number of seconds after the container has started before liveness probes are initiated.

failureThreshold

periodSeconds

successThreshold

timeoutSeconds