Nextgen Blog
HomeLearnAIQuantumRoboticsSecuritySpaceAbout
Nextgen Blog

By Anubhav — full stack engineer, IIT Mandi CSE. Deep dives into AI, software engineering, and the technologies shaping the next generation of tech.

Navigate

  • Home
  • Learn
  • Blog
  • Archive
  • About

Topics

  • Artificial Intelligence
  • Quantum Computing
  • Robotics
  • Cybersecurity
  • Space Tech

Connect

Built with ❤️ & By - Anubhav

© 2026 Nextgen Blog by Anubhav. All rights reserved.

Privacy PolicyTerms of Service
Phase 03 · Networking & ScalingChapter 15 of 33
14.
Phase 03Read time ~14 minDifficulty intermediate

Health Checks & Probes

Warrior, this chapter is critical for production Kubernetes.

In this chapter
  • 01The Three Kubernetes Probes
  • 02Why Are Probes Needed?
  • 03Basic Architecture
  • 04Liveness Probe
  • 05Readiness Probe
  • 06Liveness vs Readiness
  • 07Liveness
  • 08Readiness
  • 09Startup Probe
  • 10Why Startup Probe Matters
  • 11Probe Types
  • 12HTTP
  • 13TCP
  • 14Command
  • 15gRPC
  • 16HTTP Probe
  • 17Node.js Health Endpoint
  • 18Complete Readiness Example
  • 19initialDelaySeconds
  • 20periodSeconds
  • 21timeoutSeconds
  • 22failureThreshold
  • 23successThreshold
  • 24Liveness Example
  • 25Readiness Example
  • 26Startup Probe Example
  • 27Complete Production-Style Example
  • 28/health vs /ready
  • 29/health
  • 30/ready
  • 31Should Readiness Check the Database?
  • 32Liveness Should Be Lightweight
  • 33Readiness Is Different
  • 34Probe Lifecycle
  • 35HTTP Probe Details
  • 36TCP Probe
  • 37Command Probe
  • 38Probe Failure and Services
  • 39Zero-Downtime Deployment
  • 40What If You Have No Readiness Probe?
  • 41Probe vs Container Restart Policy
  • 42Debugging Failed Probes
  • 43Common Probe Mistakes
  • 44Mistake 1 — Wrong port
  • 45Mistake 2 — Wrong path
  • 46Mistake 3 — Liveness too aggressive
  • 47Mistake 4 — Heavy liveness endpoint
  • 48Probes + HPA
  • 49Interview Questions
  • 50Q1. What is a liveness probe?
  • 51Q2. What is a readiness probe?
  • 52Q3. What is a startup probe?
  • 53Q4. Difference between liveness and readiness?
  • 54Q5. Why use startup probes?
  • 55Q6. What happens when readiness fails?
  • 56Q7. What happens when liveness repeatedly fails?
  • 57Q8. What probe should be used for slow applications?
  • 58Q9. Does readiness failure restart a Pod?
  • 59Q10. Should liveness check external dependencies?
  • 60Next → Chapter 15: Horizontal Pod Autoscaler (HPA)
In this chapter (60 sections)
01The Three Kubernetes Probes02Why Are Probes Needed?03Basic Architecture04Liveness Probe05Readiness Probe06Liveness vs Readiness07Liveness08Readiness09Startup Probe10Why Startup Probe Matters11Probe Types12HTTP13TCP14Command15gRPC16HTTP Probe17Node.js Health Endpoint18Complete Readiness Example19initialDelaySeconds20periodSeconds21timeoutSeconds22failureThreshold23successThreshold24Liveness Example25Readiness Example26Startup Probe Example27Complete Production-Style Example28/health vs /ready29/health30/ready31Should Readiness Check the Database?32Liveness Should Be Lightweight33Readiness Is Different34Probe Lifecycle35HTTP Probe Details36TCP Probe37Command Probe38Probe Failure and Services39Zero-Downtime Deployment40What If You Have No Readiness Probe?41Probe vs Container Restart Policy42Debugging Failed Probes43Common Probe Mistakes44Mistake 1 — Wrong port45Mistake 2 — Wrong path46Mistake 3 — Liveness too aggressive47Mistake 4 — Heavy liveness endpoint48Probes + HPA49Interview Questions50Q1. What is a liveness probe?51Q2. What is a readiness probe?52Q3. What is a startup probe?53Q4. Difference between liveness and readiness?54Q5. Why use startup probes?55Q6. What happens when readiness fails?56Q7. What happens when liveness repeatedly fails?57Q8. What probe should be used for slow applications?58Q9. Does readiness failure restart a Pod?59Q10. Should liveness check external dependencies?60Next → Chapter 15: Horizontal Pod Autoscaler (HPA)

Kubernetes can restart a crashed container, but there's a deeper problem:

How does Kubernetes know whether your application is actually healthy?

A process can be running but still be broken.

For example:

Node.js process
      │
      ▼
    Running ✅
      │
      └── Database connection broken ❌

Kubernetes needs a way to distinguish:

"Process exists"

from:

"Application is healthy and ready to serve traffic"

That's what probes do.


1. The Three Kubernetes Probes#

Kubernetes provides three major types:

Startup Probe
     ↓
Is my application finished starting?
 
Readiness Probe
     ↓
Can my application receive traffic?
 
Liveness Probe
     ↓
Is my application still healthy/alive?

The easiest way to remember:

Startup = started? Readiness = ready? Liveness = alive?


2. Why Are Probes Needed?#

Imagine your Node.js API takes:

45 seconds

to start because it loads:

  • configuration
  • database connections
  • ML model
  • cache
  • large application initialization

Without proper probes, Kubernetes might assume:

Container started
      ↓
Send traffic immediately

But the application isn't ready.

Users get:

502
503
Connection errors

A readiness probe solves this.


3. Basic Architecture#

                    Kubernetes
                        │
                        ▼
                      Pod
                        │
                  ┌─────┴─────┐
                  │ Container │
                  └─────┬─────┘
                        │
             ┌──────────┼──────────┐
             ▼          ▼          ▼
          Startup    Readiness   Liveness
             │          │          │
          Started?     Ready?     Alive?

4. Liveness Probe#

A liveness probe answers:

"Is this container still functioning?"

Suppose your application gets stuck:

Node.js
   ↓
Process still exists
   ↓
But event loop is stuck

The process may technically still be running.

Kubernetes can use the liveness probe to detect the unhealthy state and restart the container.

Conceptually:

Liveness
   │
   ├── Healthy → Keep running
   │
   └── Failed repeatedly → Restart container

5. Readiness Probe#

Readiness answers:

"Should this Pod receive traffic right now?"

This is different from liveness.

Suppose:

Pod is alive
    ↓
but database isn't connected

You may not want the Service to send user requests to it.

Readiness can report:

Not Ready

Then the Pod is removed from the Service's ready endpoints.

Important:

A failed readiness probe normally does NOT restart the container.

It primarily affects traffic routing.


6. Liveness vs Readiness#

This distinction is extremely important.

Liveness#

"Should Kubernetes restart this container?"

Readiness#

"Should Kubernetes send traffic to this Pod?"

Example:

Pod
 │
 ├── Liveness ❌
 │       ↓
 │    Restart
 │
 └── Readiness ❌
         ↓
    Stop receiving traffic

7. Startup Probe#

Startup probe answers:

"Has my application finished starting?"

This is especially useful for slow-starting applications.

For example:

Container starts
       │
       ├── 5 sec
       ├── 10 sec
       ├── 20 sec
       ├── 30 sec
       └── 45 sec → Application ready

During startup:

Startup probe = failing

Once it succeeds:

Startup probe = successful

then liveness/readiness checks can take over.


8. Why Startup Probe Matters#

Imagine:

livenessProbe:
  httpGet:
    path: /health
    port: 3000
  periodSeconds: 5

Your application needs 30 seconds to start.

Kubernetes checks:

5 sec → fail
10 sec → fail
15 sec → fail
20 sec → fail

Depending on the configured failure threshold, Kubernetes might restart the container before it finishes starting.

Result:

Start
 ↓
Probe fails
 ↓
Restart
 ↓
Start
 ↓
Probe fails
 ↓
Restart

Potentially:

CrashLoopBackOff

A startup probe can prevent this.


9. Probe Types#

A probe can check the application in several ways.

HTTP#

GET /health

TCP#

Can I connect to port 3000?

Command#

Run a command inside container

gRPC#

For applications exposing suitable gRPC health checking.

We'll focus first on HTTP, TCP, and command probes.


10. HTTP Probe#

For a Node.js API, this is very common.

Suppose your application exposes:

GET /health

which returns:

200 OK

Kubernetes:

livenessProbe:
  httpGet:
    path: /health
    port: 3000

Conceptually:

Kubernetes
     │
     │ GET /health
     ▼
Node.js
     │
     └── 200 OK

11. Node.js Health Endpoint#

For Express:

app.get("/health", (req, res) => {
  res.status(200).json({
    status: "ok"
  });
});

Then:

GET /health

returns:

{
  "status": "ok"
}

Kubernetes sees:

HTTP 200
↓
Healthy

12. Complete Readiness Example#

readinessProbe:
  httpGet:
    path: /health
    port: 3000
 
  initialDelaySeconds: 5
  periodSeconds: 10
  timeoutSeconds: 2
  failureThreshold: 3
  successThreshold: 1

Let's understand each field.


13. initialDelaySeconds#

initialDelaySeconds: 5

Means:

Wait approximately 5 seconds before starting the probe checks.

Useful when an application needs some time to initialize.

But with a startup probe, you often don't need to rely heavily on a large initial delay for slow applications.


14. periodSeconds#

periodSeconds: 10

Means:

Run the probe approximately every 10 seconds.

Conceptually:

0 sec
 │
10 sec → check
 │
20 sec → check
 │
30 sec → check
 │
40 sec → check

15. timeoutSeconds#

timeoutSeconds: 2

Means:

The probe must respond within about 2 seconds.

If it takes longer:

Probe = failure

16. failureThreshold#

failureThreshold: 3

Means:

How many consecutive failures are required before Kubernetes considers the probe failed according to the probe's semantics.

For readiness:

Failure
Failure
Failure
   ↓
Pod becomes NotReady

For liveness:

Failure
Failure
Failure
   ↓
Container restart

17. successThreshold#

successThreshold: 1

Specifies how many consecutive successful checks are needed to transition a failed probe back to success.

For many HTTP readiness/liveness configurations, the practical value is:

1

18. Liveness Example#

livenessProbe:
  httpGet:
    path: /health
    port: 3000
 
  initialDelaySeconds: 10
  periodSeconds: 10
  timeoutSeconds: 2
  failureThreshold: 3

Meaning approximately:

Start application
       ↓
Wait 10 sec
       ↓
Check /health every 10 sec
       ↓
If 3 consecutive checks fail
       ↓
Kubernetes may restart container

19. Readiness Example#

readinessProbe:
  httpGet:
    path: /ready
    port: 3000
 
  initialDelaySeconds: 5
  periodSeconds: 5
  timeoutSeconds: 2
  failureThreshold: 3

If readiness fails:

Pod
 ↓
NotReady
 ↓
Service stops sending normal traffic

The container can continue running.


20. Startup Probe Example#

startupProbe:
  httpGet:
    path: /health
    port: 3000
 
  periodSeconds: 5
  failureThreshold: 12

This effectively gives the application multiple probe attempts during startup.

Roughly:

5 sec × 12 attempts

before startup is considered failed, subject to probe behavior.

Once startup succeeds:

Startup ✅
    ↓
Liveness + Readiness take over

21. Complete Production-Style Example#

Here's a Node.js Deployment:

apiVersion: apps/v1
kind: Deployment
 
metadata:
  name: node-api
 
spec:
  replicas: 3
 
  selector:
    matchLabels:
      app: node-api
 
  template:
    metadata:
      labels:
        app: node-api
 
    spec:
      containers:
        - name: node-api
          image: my-node-api:1.0
 
          ports:
            - containerPort: 3000
 
          startupProbe:
            httpGet:
              path: /health
              port: 3000
            periodSeconds: 5
            failureThreshold: 12
 
          readinessProbe:
            httpGet:
              path: /ready
              port: 3000
            periodSeconds: 5
            timeoutSeconds: 2
            failureThreshold: 3
 
          livenessProbe:
            httpGet:
              path: /health
              port: 3000
            periodSeconds: 10
            timeoutSeconds: 2
            failureThreshold: 3
 
          resources:
            requests:
              cpu: "250m"
              memory: "256Mi"
 
            limits:
              cpu: "1"
              memory: "512Mi"

This is much closer to a production-style workload than a simple Pod definition.


22. /health vs /ready#

It's often useful to have different endpoints.

/health#

Could answer:

"Is the application process fundamentally healthy?"

Example:

{
  "status": "ok"
}

/ready#

Could answer:

"Can this instance handle requests right now?"

For example, the readiness endpoint might verify important dependencies:

Application
   │
   ├── Database connection
   ├── Required configuration
   └── Critical dependency

But be careful about making health checks too expensive.


23. Should Readiness Check the Database?#

This is an architectural decision.

You might have:

/ready
   ↓
Database check

If the database goes down:

Readiness ❌
   ↓
Pod removed from Service endpoints

This can be useful in some architectures.

But blindly checking every dependency in every probe can create problems.

For example:

Database temporarily slow
       ↓
Every Pod becomes NotReady
       ↓
No traffic
       ↓
Recovery becomes harder

So health endpoints should be designed deliberately.


24. Liveness Should Be Lightweight#

This is a very important production principle.

Don't make your liveness endpoint perform:

10 database queries
+
Redis call
+
External API call
+
LLM request

That's dangerous.

Imagine:

External API down
      ↓
Liveness fails
      ↓
Kubernetes restarts all Pods
      ↓
Pods restart
      ↓
External API still down
      ↓
Restart again

You've turned a dependency outage into a restart storm.

A liveness check should generally answer whether the application itself is functioning, not whether every external dependency in the world is healthy.


25. Readiness Is Different#

Readiness can be more dependency-aware.

For example:

Database unavailable
       ↓
Pod alive
       ↓
Pod not ready
       ↓
Don't send new traffic

This can be preferable to repeatedly restarting healthy application processes.


26. Probe Lifecycle#

A useful mental model:

              Container starts
                    │
                    ▼
              Startup Probe
                    │
             ┌──────┴──────┐
             │             │
           Fail          Success
             │             │
          Restart          ▼
                       Readiness
                           │
                    ┌──────┴──────┐
                    │             │
                  Ready         NotReady
                    │             │
                    ▼             ▼
               Service       No traffic
               traffic
                    │
                    ▼
                Liveness
                    │
              ┌─────┴─────┐
              │           │
            Healthy      Failed
              │           │
              ▼           ▼
           Continue     Restart

This is one of the most useful diagrams in this chapter.


27. HTTP Probe Details#

Example:

httpGet:
  path: /health
  port: 3000
  scheme: HTTP

You can specify:

HTTP
HTTPS

depending on how the application is configured.

You can also specify HTTP headers when needed.


28. TCP Probe#

Sometimes your application doesn't expose a health HTTP endpoint.

You can use:

livenessProbe:
  tcpSocket:
    port: 3000
 
  periodSeconds: 10

Kubernetes attempts to establish a TCP connection.

If the port isn't accepting connections:

Probe fails

TCP probes tell you that something is accepting a connection, but they don't necessarily prove the application is functioning correctly.


29. Command Probe#

You can execute a command inside the container:

livenessProbe:
  exec:
    command:
      - cat
      - /tmp/healthy

If the command exits successfully:

Probe succeeds

Otherwise:

Probe fails

This can be useful for certain applications but should be used thoughtfully.


30. Probe Failure and Services#

This is one of the most important interactions.

Suppose:

3 Pods

Initially:

Pod A → Ready
Pod B → Ready
Pod C → Ready

Service:

Service
 ├── A
 ├── B
 └── C

Now Pod B readiness fails:

Pod B → NotReady

Service effectively has:

Service
 ├── A
 └── C

Pod B is still running, but normal Service traffic isn't directed to it while it's not ready.


31. Zero-Downtime Deployment#

Now you can understand why readiness probes matter during a rolling update.

Suppose:

Version 1
Pod A
Pod B
Pod C

Deployment starts:

Version 2
Pod D

But Pod D is still starting:

Pod D
NotReady

Service continues sending traffic to:

A
B
C

Once D becomes ready:

A
B
C
D

Then Kubernetes can gradually remove old Pods.

This is how readiness helps make rolling updates safer.


32. What If You Have No Readiness Probe?#

Kubernetes may consider the container ready according to its default readiness behavior once the container is running.

That means a newly started application could potentially receive traffic before it's truly prepared to handle requests.

For production services, a properly designed readiness check is often valuable.


33. Probe vs Container Restart Policy#

Don't confuse:

RestartPolicy

with:

Probes

RestartPolicy defines restart behavior when a container terminates.

Probes determine health conditions and can trigger actions such as:

Liveness failure → container restart
Readiness failure → remove from ready endpoints
Startup failure → container restart

34. Debugging Failed Probes#

Suppose:

Pod
   ↓
CrashLoopBackOff

First:

kubectl describe pod <pod-name>

Look at:

Events

You may see:

Liveness probe failed

Then:

kubectl logs <pod-name>

And for the previous container:

kubectl logs <pod-name> --previous

Also inspect:

kubectl get pod <pod-name>

35. Common Probe Mistakes#

Mistake 1 — Wrong port#

Application:

3000

Probe:

port: 8080

Result:

Probe fails

Mistake 2 — Wrong path#

Application has:

/health

Probe checks:

/healthy

Result:

404

Probe fails.


Mistake 3 — Liveness too aggressive#

Example:

Application startup = 30 sec
 
Liveness starts immediately
Probe every 2 sec

Potentially:

Start
 ↓
Fail
 ↓
Restart
 ↓
Start
 ↓
Fail

Use startup probes or appropriate initial startup configuration.


Mistake 4 — Heavy liveness endpoint#

Don't make liveness call:

Database
Redis
External APIs
LLM

unless there's a deliberate reason.


36. Probes + HPA#

Remember Chapter 13?

We learned:

CPU
Memory
Requests
Limits

Next you'll learn:

HPA

Health probes complement autoscaling.

For example:

HPA
 ↓
More Pods
 
Readiness
 ↓
Only healthy Pods receive traffic

Together:

Traffic increases
      ↓
HPA creates Pods
      ↓
New Pods start
      ↓
Readiness = NotReady
      ↓
Application initializes
      ↓
Readiness = Ready
      ↓
Service sends traffic

This is a powerful production pattern.


37. Interview Questions#

Q1. What is a liveness probe?#

It determines whether a container is still functioning and can cause the container to be restarted when the probe repeatedly fails.

Q2. What is a readiness probe?#

It determines whether a Pod should receive traffic. A failed readiness probe normally removes the Pod from ready Service endpoints without restarting the container.

Q3. What is a startup probe?#

It determines whether a slow-starting application has completed initialization and protects it from premature liveness/readiness failures.

Q4. Difference between liveness and readiness?#

Liveness
→ Restart?
 
Readiness
→ Traffic?

Q5. Why use startup probes?#

For applications that take significant time to initialize.

Q6. What happens when readiness fails?#

The Pod is marked not ready and normally stops receiving traffic through Services.

Q7. What happens when liveness repeatedly fails?#

Kubernetes can restart the container.

Q8. What probe should be used for slow applications?#

A startup probe is often appropriate.

Q9. Does readiness failure restart a Pod?#

Normally, no.

Q10. Should liveness check external dependencies?#

Usually keep it lightweight and focused on whether the application itself is functioning; blindly making it depend on external systems can cause unnecessary restarts.


🧠 Chapter 14 Cheat Sheet#

STARTUP
   ↓
"Has the application started?"
 
READINESS
   ↓
"Can it receive traffic?"
 
LIVENESS
   ↓
"Is it still functioning?"

Probe types:

HTTP
TCP
Command
gRPC

Important behavior:

Startup failure
     ↓
Restart
 
Readiness failure
     ↓
No normal Service traffic
 
Liveness failure
     ↓
Restart container

🎯 Production Request Flow#

You can now visualize a much more realistic system:

                         USER
                           │
                           ▼
                       INTERNET
                           │
                           ▼
                        INGRESS
                           │
                           ▼
                        SERVICE
                           │
                    ┌──────┼──────┐
                    ▼      ▼      ▼
                  Pod A  Pod B  Pod C
                    │      │      │
                  Ready  Ready  NotReady
                    │      │       X
                    │      │
                    └──────┴───────┐
                                   │
                              Application
                                   │
                         ┌─────────┴─────────┐
                         │                   │
                     Liveness            Readiness
                         │                   │
                      Restart?            Traffic?

And for startup:

Container starts
      │
      ▼
Startup Probe
      │
      ▼
Application initialized
      │
      ├───────────────┐
      ▼               ▼
 Readiness         Liveness
    │                 │
 Traffic?           Alive?

Next → Chapter 15: Horizontal Pod Autoscaler (HPA)#

This is where Kubernetes becomes truly elastic.

You'll learn:

HPA
CPU-based scaling
Memory-based scaling
minReplicas
maxReplicas
target utilization
metrics-server
kubectl autoscale
autoscaling/v2
Scaling behavior
Scale up / scale down
HPA + Deployment + Service

And we'll build this:

                Traffic
                   │
                   ▼
                Service
                   │
        ┌──────────┼──────────┐
        ▼          ▼          ▼
      Pod 1      Pod 2      Pod 3
                   ▲
                   │
                  HPA
                   │
          CPU/Memory Metrics
                   │
                   ▼
          Increase/Decrease
             Pod replicas

The key idea:

Deployment tells Kubernetes how many Pods you want; HPA dynamically changes that number based on workload metrics.

Finished this chapter?

Mark it as complete to track your mastery.

Previous ChapterChapter 13 — Resource Requests & LimitsNext ChapterChapter 15 — Horizontal Pod Autoscaler (HPA)
PrevNext