Health Checks

Understand startup, readiness, and liveness probes for the Node.js order service and verify what happens when readiness checks fail.

🎯 Introduction

The Node.js order service is running in Kubernetes. But does a Pod showing Running necessarily mean it can handle user requests?

No. The application may still be starting and unable to accept requests, or its process may remain alive while it no longer responds correctly. Kubernetes needs more than the existence of a container process to determine availability.

This article addresses one question: how does Kubernetes check whether a Node.js service is working? We will continue with orders, examine three types of checks, then deliberately fail a readiness check to observe the result.


🧱 Why check a running Pod?

Consider three situations the order service might encounter:

Three conditions the order service may encounter

These are different kinds of problems, not three required stages in sequence.

Still starting

Node.js is initializing and cannot respond yet.

startupProbe · Startup probe

Give the app time to start.

Temporarily unable to take orders

The process is running but cannot handle new requests right now.

readinessProbe · Readiness probe

Pause new Service traffic to this Pod.

No longer working

For example, the app hangs and its health endpoint stops responding.

livenessProbe · Liveness probe

Restart the container once successive failures reach the threshold.

Readiness failures affect whether a Pod receives traffic. Repeated startup or liveness failures may restart the container when the threshold is reached.

Each calls for a different response: allow more time for startup, stop sending new requests while it cannot accept orders, or restart the container if it remains stuck.

Kubernetes calls these checks probes. We will cover three:

ProbeWhat it checksAfter repeated failures
startupProbeHas the application finished starting?Restarts the container after the failure threshold is reached
readinessProbeCan it accept requests now?Marks the Pod unready and removes it as a normal Service traffic target
livenessProbeIs the application still functioning?Restarts the container after the failure threshold is reached

The key distinction: a failed readinessProbe does not itself restart the container. A livenessProbe triggers a restart once its failure threshold is reached.

When a startupProbe is configured, Kubernetes waits for it to succeed before running the other two probes. This prevents a slow startup from being treated as a failure too early.


🧩 How does Kubernetes check Node.js?

The order project already has this endpoint:

app.get('/healthz', (req, res) => {
  res.json({ status: 'ok' })
})

When a browser or another program requests /healthz, Express returns a response like this:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{"status":"ok"}

Kubernetes can request the endpoint periodically too. For example, configure it to request /healthz on port 3000 of the order Pod. A 200 response passes the check; HTTP probes generally treat 200–399 as success.

Kubernetes does not create /healthz automatically. It is the Express endpoint we wrote earlier, so no code changes or image rebuild are needed.

To introduce the differences between probes, all three use /healthz in this article. Although they request the same endpoint, Kubernetes handles their results differently.

Suppose the order service takes 30 seconds to start. The startupProbe waits for startup to complete, preventing liveness checks from triggering a premature restart. After it succeeds, the readinessProbe checks whether the service can accept requests, while the livenessProbe continues checking for failures requiring a restart.

In real applications, checking whether a process is alive and whether it can handle business requests may require different endpoints, such as /healthz and /readyz. Our order service currently has no complex initialization or external dependencies, so we use the existing /healthz without changing Express or rebuilding the image.


🛠 Adding health probes to the order service

The three probes have similar configuration. Start with the readiness probe:

readinessProbe:
  httpGet:
    path: /healthz
    port: 3000
  periodSeconds: 5

This tells Kubernetes to request /healthz on the order container's port 3000 roughly every five seconds. A failed check marks the Pod unready, temporarily excluding it as a normal Service traffic target. It does not request a container restart.

Next, combine startup, readiness, and liveness probes. Open deployment.yaml, find the order container under spec.template.spec.containers, and add the probes alongside its existing image, ports, and env settings.

This is partial YAML from the existing Deployment, not a complete file. Retain all existing fields.

spec:
  template:
    spec:
      containers:
        - name: orders
          # Keep existing fields such as image, ports, and env
          startupProbe:
            httpGet:
              path: /healthz
              port: 3000
            periodSeconds: 5
            failureThreshold: 12
          readinessProbe:
            httpGet:
              path: /healthz
              port: 3000
            periodSeconds: 5
          livenessProbe:
            httpGet:
              path: /healthz
              port: 3000
            periodSeconds: 10

startupProbe and livenessProbe also use HTTP requests, but the former handles startup failures and the latter handles runtime failures requiring a restart.

Focus on three configuration details:

  • httpGet: Checks the application by requesting the specified HTTP path.
  • periodSeconds: The interval between regular checks, in seconds.
  • failureThreshold: How many consecutive failures trigger the probe's failure action. For example, a startup threshold of 12 with checks every 5 seconds allows roughly one minute for startup checks.

There is no need to configure every possible parameter. For now, understand when Kubernetes checks, what it checks, and what happens on failure.

Save the file and run this in its directory:

kubectl apply -f deployment.yaml -n course
kubectl rollout status deployment/orders -n course

Simulated output:

deployment.apps/orders configured
deployment "orders" successfully rolled out

The Deployment has been updated and this rollout met its readiness requirements. Next, inspect the Pods:

kubectl get pods -n course -l app=orders

Simulated output; names and ages will differ:

NAME                        READY   STATUS    RESTARTS   AGE
orders-7c8d9f6b5-a1b2c     1/1     Running   0          42s
orders-7c8d9f6b5-d3e4f     1/1     Running   0          40s

STATUS=Running indicates that the container is running; READY=1/1 means this single-container Pod is currently ready. These are different conditions.


🔎 What happens when readiness checks fail?

What if we change only readinessProbe to request /not-found, a path Express does not provide?

Kubernetes receives 404 and decides the Pod is temporarily unsuitable for Service traffic. However:

  • The Node.js process itself may still be running normally.
  • livenessProbe still checks the correct /healthz, so the readiness failure does not trigger a restart.
  • During a rolling update of this two-replica Deployment, old ready Pods may continue serving requests while new Pods remain unready and prevent the rollout from completing.

With two ready order Pods initially and the default Deployment rolling update strategy, you might see:

NAME                        READY   STATUS    RESTARTS   AGE
orders-7c8d9f6b5-a1b2c     1/1     Running   0          15m
orders-7c8d9f6b5-d3e4f     1/1     Running   0          15m
orders-6b9f7d5c4-xyz12     0/1     Running   0          30s

The first two are old Pods with successful checks, still able to receive requests. The third is a new Pod that cannot become ready because of the incorrect path. The default rolling update attempts to retain available old Pods, so a failed rollout does not necessarily interrupt the existing service immediately.

0/1 and Running are compatible: Node.js is running, but the new Pod has not passed readiness checks. These names and counts are just one simulated possibility; inspect your own cluster's output.

Use this command to investigate probe failures:

kubectl describe pods -n course -l app=orders

The relevant Pod's Events may include:

Warning  Unhealthy  Readiness probe failed: HTTP probe failed with statuscode: 404

404 means the requested /not-found endpoint does not exist, not that the order service crashed. Readiness probe failed identifies the failed check. Restore readinessProbe to the application's /healthz path and reapply the Deployment so new Pods can pass the check and become ready.


❓ Questions and answers

Q: Why are the other probes needed when startupProbe is configured?

It only determines whether startup has completed. Later, the application may temporarily stop accepting requests or develop a fault requiring a restart.

Q: Does a readiness failure automatically restart the order container?

No. Readiness failure itself does not restart the container. It mainly determines whether the Pod should receive Service traffic; liveness checks detect faults requiring restarts.

Q: Can a probe check the database?

You can design readiness checks around business requirements, but do not equate a temporary database outage with a dead process. Doing so in a liveness check may cause unnecessary repeated restarts. Here we use /healthz to learn the basic behavior.


🧪 Exercise

Verify a readiness failure, then recover:

  1. Change the path of only readinessProbe in deployment.yaml to /not-found. Keep /healthz for the other two probes.
  2. Run kubectl apply -f deployment.yaml -n course, then inspect new Pods' READY values with kubectl get pods -n course -l app=orders. Do not keep waiting for a successful kubectl rollout status: the incorrect readiness check prevents normal completion.
  3. Run kubectl describe pods -n course -l app=orders and find Readiness probe failed.
  4. Restore /healthz, apply the configuration again, then run kubectl rollout status deployment/orders -n course to confirm recovery.

Success criteria: Explain why a new Pod can show Running with 0/1, and distinguish the consequences of readiness and liveness failures.


🎉 You now understand each probe's role and can use a deliberate configuration error to see why a running container is not necessarily ready to accept requests.