Liveness, Readiness, and Startup Probes (2024)

Objectives

After completing this section, you should be able to review how Kubernetes evaluates application health status via probes and automatic application restart.

Kubernetes Readiness and Liveness Probes

Applications can become unreliable for a variety of reasons, for example:

  • Temporary connection loss

  • Configuration errors

  • Application errors

Developers can use probes to monitor their applications. Probes make developers aware of events such as application status, resource usage, and errors.

Monitoring of such events is useful for fixing problems, but can also help with resource planning and managing.

A probe is a periodic check that monitors the health of an application. Developers can configure probes by using either thekubectlcommand-line client or a YAML deployment template.

There are currently three types of probes in Kubernetes:

Startup Probe

A startup probe verifies whether the application within a container is started. Startup probes run before any other probe, and, unless it finishes successfully, disables other probes. If a container fails its startup probe, then the container is killed and follows the pod’srestartPolicy.

This type of probe is only executed at startup, unlike readiness probes, which are run periodically.

The startup probe is configured in the spec.containers.startupprobe attribute of the pod configuration.

Readiness Probe

Readiness probes determine whether or not a container is ready to serve requests. If the readiness probe returns a failed state, then Kubernetes removes the IP address for the container from the endpoints of all Services.

Developers use readiness probes to instruct Kubernetes that a running container should not receive any traffic. This is useful when waiting for an application to perform time-consuming initial tasks, such as establishing network connections, loading files, and warming caches.

The readiness probe is configured in thespec.containers.readinessprobeattribute of the pod configuration.

Liveness Probe

Liveness probes determine whether or not an application running in a container is in ahealthystate. If the liveness probe detects an unhealthy state, then Kubernetes kills the container and tries to redeploy it.

The liveness probe is configured in thespec.containers.livenessprobeattribute of the pod configuration.

Kubernetes provides five options that control these probes:

NameMandatoryDescriptionDefault Value

initialDelaySeconds

Yes

Determines how long to wait after the container starts before beginning the probe.

timeoutSeconds

Yes

Determines how long to wait for the probe to finish. If this time is exceeded, then Kubernetes assumes that the probe failed.

1

periodSeconds

No

Specifies the frequency of the checks.

10

successThreshold

No

Specifies the minimum consecutive successes for the probe to be considered successful after it has failed.

1

failureThreshold

No

Specifies the minimum consecutive failures for the probe to be considered failed after it has succeeded.

3

Methods of Checking Application Health

Startup, readiness, and liveness probes can check the health of applications in three ways: HTTP checks, container execution checks, and TCP socket checks.

HTTP Checks

An HTTP check is ideal for applications that return HTTP status codes, such as REST APIs.

HTTP probe uses GET requests to check the health of an application. The check is successful if the HTTP response code is in the range 200-399.

The following example demonstrates how to implement a readiness probe with the HTTP check method:

...contents omitted...readinessProbe: httpGet: path: /health (1) port: 8080 initialDelaySeconds: 15 (2) timeoutSeconds: 1 (3)...contents omitted...
  1. The readiness probe endpoint.

  2. How long to wait after the container starts before checking its health.

  3. How long to wait for the probe to finish.

Container Execution Checks

Container execution checks are ideal in scenarios where you must determine the status of the container based on the exit code of a process or shell script running in the container.

When using container execution checks Kubernetes executes a command inside the container. Exiting the check with a status of0is considered a success. All other status codes are considered a failure.

The following example demonstrates how to implement a container execution check:

...contents omitted...livenessProbe: exec: command:(1) - cat - /tmp/health initialDelaySeconds: 15 timeoutSeconds: 1...contents omitted...
  1. The command to run and its arguments, as a YAML array.

TCP Socket Checks

A TCP socket check is ideal for applications that run as daemons, and open TCP ports, such as database servers, file servers, web servers, and application servers.

When using TCP socket checks Kubernetes attempts to open a socket to the container. The container is considered healthy if the check can establish a successful connection.

The following example demonstrates how to implement a liveness probe by using the TCP socket check method:

...contents omitted...livenessProbe: tcpSocket: port: 8080 (1) initialDelaySeconds: 15 timeoutSeconds: 1...contents omitted...
  1. The TCP port to check.

Creating Probes

To configure probes on a deployment, edit the deployment’s resource definition. To do this, you can use thekubectl editorkubectl patchcommands. Alternatively, if you already have a deployment YAML definition, you can modify it to include the probes and then apply it withkubectl apply.

The following example demonstrates using thekubectl editcommand to add a readiness probe to a deployment:

Note

This will open your system’s default editor with the deployment definition. Once you make the necessary changes, save and quit the editor to apply them.

[user@host ~]$ kubectl set probe deployment myapp --readiness \--get-url=http://:8080/healthz --period=20[user@host ~]$ kubectl patch deployment myapp \-p '{"spec":{"containers"[0]: {"readinessProbe": {}}}}'

The following examples demonstrate using thekubectl set probecommand with a variety of options:

[user@host ~]$ kubectl set probe deployment myapp --readiness \--get-url=http://:8080/healthz --period=20
[user@host ~]$ kubectl set probe deployment myapp --liveness \--open-tcp=3306 --period=20 \--timeout-seconds=1
[user@host ~]$ kubectl set probe deployment myapp --liveness \--get-url=http://:8080/healthz --initial-delay-seconds=30 \--success-threshold=1 --failure-threshold=3
Liveness, Readiness, and Startup Probes (2024)
Top Articles
If I Invest $100 in Bitcoin Today, What Might Happen? [2023] | PrimeXBT 
How to Use A VPN To Watch Netflix & Change Regions
Lengua With A Tilde Crossword
Dairy Queen Lobby Hours
Kraziithegreat
PontiacMadeDDG family: mother, father and siblings
Shs Games 1V1 Lol
Jefferey Dahmer Autopsy Photos
What Happened To Dr Ray On Dr Pol
THE 10 BEST Women's Retreats in Germany for September 2024
How to change your Android phone's default Google account
2024 Fantasy Baseball: Week 10 trade values chart and rest-of-season rankings for H2H and Rotisserie leagues
What happens if I deposit a bounced check?
Gameday Red Sox
Kentucky Downs Entries Today
Otr Cross Reference
Worcester On Craigslist
Moparts Com Forum
Hoe kom ik bij mijn medische gegevens van de huisarts? - HKN Huisartsen
Mail.zsthost Change Password
Missouri Highway Patrol Crash
Mahpeople Com Login
Weathervane Broken Monorail
Aes Salt Lake City Showdown
Mississippi Craigslist
Vadoc Gtlvisitme App
Perry Inhofe Mansion
Chadrad Swap Shop
Unm Hsc Zoom
Wbli Playlist
Makemkv Key April 2023
Sadie Sink Doesn't Want You to Define Her Style, Thank You Very Much
Bismarck Mandan Mugshots
Shih Tzu dogs for sale in Ireland
Marcus Roberts 1040 Answers
Main Street Station Coshocton Menu
All Characters in Omega Strikers
Below Five Store Near Me
Sdn Fertitta 2024
Sig Mlok Bayonet Mount
Ladyva Is She Married
20 Mr. Miyagi Inspirational Quotes For Wisdom
Terrell Buckley Net Worth
Euro area international trade in goods surplus €21.2 bn
Ty Glass Sentenced
Image Mate Orange County
18443168434
Black Adam Showtimes Near Cinemark Texarkana 14
Jovan Pulitzer Telegram
When Is The First Cold Front In Florida 2022
Noaa Duluth Mn
Latest Posts
Article information

Author: Errol Quitzon

Last Updated:

Views: 5853

Rating: 4.9 / 5 (79 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Errol Quitzon

Birthday: 1993-04-02

Address: 70604 Haley Lane, Port Weldonside, TN 99233-0942

Phone: +9665282866296

Job: Product Retail Agent

Hobby: Computer programming, Horseback riding, Hooping, Dance, Ice skating, Backpacking, Rafting

Introduction: My name is Errol Quitzon, I am a fair, cute, fancy, clean, attractive, sparkling, kind person who loves writing and wants to share my knowledge and understanding with you.