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
Nearly half of young adults have 'money dysmorphia,' survey finds. Here are the symptoms
14 Reasons You Feel Cold All the Time
Lorton Transfer Station
Angela Babicz Leak
Tabc On The Fly Final Exam Answers
Unblocked Games Premium Worlds Hardest Game
What Are the Best Cal State Schools? | BestColleges
St Petersburg Craigslist Pets
Horoscopes and Astrology by Yasmin Boland - Yahoo Lifestyle
Craigslist Kennewick Pasco Richland
DL1678 (DAL1678) Delta Historial y rastreo de vuelos - FlightAware
How To Get Free Credits On Smartjailmail
Gunshots, panic and then fury - BBC correspondent's account of Trump shooting
Cinepacks.store
Jasmine
Bill Devane Obituary
Ohiohealth Esource Employee Login
Methodist Laborworkx
Dump Trucks in Netherlands for sale - used and new - TrucksNL
Dexter Gomovies
Price Of Gas At Sam's
Used Sawmill For Sale - Craigslist Near Tennessee
360 Tabc Answers
U Break It Near Me
Ubg98.Github.io Unblocked
Accident On The 210 Freeway Today
Kirksey's Mortuary - Birmingham - Alabama - Funeral Homes | Tribute Archive
Rufus Benton "Bent" Moulds Jr. Obituary 2024 - Webb & Stephens Funeral Homes
Reicks View Farms Grain Bids
2011 Hyundai Sonata 2 4 Serpentine Belt Diagram
10-Day Weather Forecast for Santa Cruz, CA - The Weather Channel | weather.com
Bfri Forum
The value of R in SI units is _____?
Melissa N. Comics
Σινεμά - Τι Ταινίες Παίζουν οι Κινηματογράφοι Σήμερα - Πρόγραμμα 2024 | iathens.gr
Joplin Pets Craigslist
Ark Unlock All Skins Command
Skip The Games Ventura
Afspraak inzien
Pitchfork's Top 200 of the 2010s: 50-1 (clips)
Dee Dee Blanchard Crime Scene Photos
Jasgotgass2
Www Usps Com Passport Scheduler
Ig Weekend Dow
Chathuram Movie Download
If You're Getting Your Nails Done, You Absolutely Need to Tip—Here's How Much
Rocky Bfb Asset
Exploring the Digital Marketplace: A Guide to Craigslist Miami
Studentvue Calexico
Victoria Vesce Playboy
Cvs Coit And Alpha
Canonnier Beachcomber Golf Resort & Spa (Pointe aux Canonniers): Alle Infos zum Hotel
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.