liveBook · Manning

Health check

As explained in Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform

A health check is an automated assessment of whether a running service or workload is functioning and available according to defined criteria.

A health check automatically assesses whether a running microservice is available and functioning according to operational criteria. In production, it supports continuous monitoring and helps detect problems after deployment and during updates. section 11.2 section 11.6

Kubernetes separates two useful questions:

  • A readiness probe reports that a microservice has started and can accept requests. section 11.2.8
  • A liveness probe reports that a microservice remains alive and continues accepting requests. section 11.2.8
  • Kubernetes can use these results to identify unhealthy workloads and restart misbehaving pods. section 11.2.8 section 11.6

Gateway probes

A Deployment can configure the gateway with an HTTP readiness probe at /ready and an HTTP liveness probe at /alive. The readiness check waits five seconds before beginning its queries, while both probes target the container's configured port. section 11.2.8

Listing 11.1 Adding Kubernetes probes for the gateway microservice
apiVersion: apps/v1
kind: Deployment
metadata:
  name: gateway
spec:
  replicas: 1
  selector:
    matchLabels:
      app: gateway
  template:
    metadata:
      labels:
        app: gateway
    spec:
      containers: 
      - name: gateway
        image: $CONTAINER_REGISTRY/gateway:$VERSION
        imagePullPolicy: IfNotPresent
        readinessProbe:                #1
          httpGet:
            path: /ready               #2
            port: {{PORT}}
          initialDelaySeconds: 5       #1
        livenessProbe:                 #3
          httpGet:
            path: /alive               #4
            port: {{PORT}}             #3
        env:
        - name: PORT
          value: "4000"
        - name: RABBIT
          value: amqp://test:test@rabbit:5672

Inspect the complete Kubernetes Deployment manifest for configuring readiness and liveness probes on the gateway microservice. section 11.2.8

Health checks also handle dependency timing. A microservice can remain unavailable until an upstream service such as RabbitMQ is ready, avoiding premature connection failures during startup, restart, or maintenance. section 11.2.8

How Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform covers it

How deep it goes
Defines readiness and liveness probes and shows their Kubernetes configuration, but does not detail probe implementation logic.
Examples
Uses gateway HTTP endpoints, Kubernetes Deployment YAML, RabbitMQ startup, and Kubernetes pod restarts as concrete examples.
What it assumes
Assumes familiarity with microservices and Kubernetes workloads while introducing readiness and liveness from their operational roles.
What you can do after
Operate/configure Kubernetes probes that delay traffic until readiness and restart workloads that fail liveness checks.
How it connects
Connects health checks with microservices, Kubernetes, upstream dependencies, fault tolerance, automatic restarts, and observability.

Also explained in

Compare how 9 books explain health check →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform. The section links point to the parts of the book it draws on.