Health Probes
Ensure your applications are healthy and recover automatically from failures using Kubernetes health probes. Codiac simplifies probe configuration for both CLI and web UI workflows.
What Are Probes?
Health probes are automated checks that Kubernetes uses to monitor container health and make traffic routing decisions. Probes detect failures early and trigger automatic recovery actions.
Business Value:
- Automatic failure detection: Identify unhealthy containers before they impact users
- Self-healing infrastructure: Kubernetes automatically restarts failed containers
- Zero manual intervention: No pager duty for transient failures
- Improved uptime: Only route traffic to healthy instances
Types of Probes
Codiac supports all three Kubernetes probe types:
1. Liveness Probe
Question: "Is the container alive and functioning?"
- Detects when a container is stuck, deadlocked, or in an unrecoverable state
- Action: Kubernetes restarts the container if liveness probe fails
- Use Case: Detect application crashes, infinite loops, or resource exhaustion
Example Scenario: Your API is running but stuck in an infinite loop. The liveness probe fails, Kubernetes kills the container and starts a fresh instance.
2. Readiness Probe
Question: "Is the container ready to serve traffic?"
- Determines if a container should receive requests
- Action: Kubernetes removes the pod from service endpoints if readiness probe fails
- Use Case: Temporary unavailability (loading data, waiting for dependencies, warming up caches)
Example Scenario: During deployment, your application needs 30 seconds to populate its cache. The readiness probe ensures traffic only flows after the cache is ready.
Readiness probes are also what make zero-downtime rollouts safe: with rollout.maxUnavailable set to 0, an old pod is retired only after its replacement passes readiness. To watch that happen, deploy with codiac asset deploy --follow.
3. Startup Probe
Question: "Has the container finished initializing?"
- Gives slow-starting containers extra time to start before liveness checks begin
- Action: Disables liveness and readiness probes until startup succeeds
- Use Case: Applications with long initialization (loading large datasets, database migrations)
Example Scenario: Your ML model takes 2 minutes to load into memory at startup. The startup probe gives it time to initialize before liveness probes start.
Probe Check Methods
Each probe can use one of three check methods:
| Method | How It Works | Best For |
|---|---|---|
| HTTP GET | Sends HTTP request to a specific path | Web servers, REST APIs |
| TCP Socket | Attempts TCP connection to a port | Databases, non-HTTP services |
| Exec Command | Runs a command inside the container | Custom health logic |
How Probes Work Together
Container Starts
↓
[Startup Probe] ────────> Success ───┐
↓ │
Failure (restart) │
↓
[Liveness Probe] + [Readiness Probe]
↓ ↓
Still alive? Ready for traffic?
↓ ↓
Yes/No Yes/No
Key Rules:
- Liveness and readiness probes don't run until startup probe succeeds (if configured)
- Readiness failures remove pod from load balancer (temporary)
- Liveness failures trigger container restart (permanent fix)
- CLI
- Web UI
Creating Probes with CLI
Use the cod asset probe create command to configure health checks for your assets.
Basic Syntax
cod asset probe create [COMMAND] [FLAGS]
HTTP Probe Example
Configure an HTTP liveness probe that checks /health endpoint:
cod asset probe create \
--asset my-api \
--cabinet prod \
--type liveness \
--method http \
--path /health \
--port 3000 \
--initial-delay 10 \
--period 10 \
--timeout 5 \
--failure-threshold 3
Expected Outcome: Kubernetes will:
- Wait 10 seconds after container starts
- Send HTTP GET to
http://container:3000/healthevery 10 seconds - Timeout after 5 seconds if no response
- Restart container after 3 consecutive failures
TCP Socket Probe Example
Check if a database port is accepting connections:
cod asset probe create \
--asset postgres-db \
--cabinet prod \
--type readiness \
--method tcp \
--port 5432 \
--initial-delay 5 \
--period 5
Exec Command Probe Example
Run a custom health check script:
cod asset probe create \
--asset batch-processor \
--cabinet prod \
--type liveness \
--method exec \
--command "/app/healthcheck.sh" \
--initial-delay 30 \
--period 20 \
--timeout 10
Script Requirements:
- Exit code 0 = healthy
- Any other exit code = unhealthy
Probe Configuration Options
| Flag | Description | Default | Example |
|---|---|---|---|
--asset | Asset name | Required | my-api |
--cabinet | Cabinet name | Required | prod |
--type | Probe type: liveness, readiness, startup | Required | liveness |
--method | Check method: http, tcp, exec | Required | http |
--path | HTTP path (for HTTP method) | / | /health |
--port | Container port to check | Required | 3000 |
--command | Command to execute (for exec method) | - | /app/check.sh |
--initial-delay | Seconds to wait before first probe | 0 | 10 |
--period | Seconds between probes | 10 | 15 |
--timeout | Seconds before probe times out | 1 | 5 |
--success-threshold | Consecutive successes to mark healthy | 1 | 1 |
--failure-threshold | Consecutive failures to mark unhealthy | 3 | 3 |
Best Practice Examples
Fast-Starting Web Application
# Liveness: Check HTTP endpoint every 10s
cod asset probe create \
--asset web-app \
--type liveness \
--method http \
--path /healthz \
--port 8080 \
--period 10 \
--failure-threshold 3
# Readiness: Wait for dependencies
cod asset probe create \
--asset web-app \
--type readiness \
--method http \
--path /ready \
--port 8080 \
--initial-delay 5 \
--period 5
Slow-Starting Database
# Startup: Give it 5 minutes to initialize
cod asset probe create \
--asset postgres \
--type startup \
--method tcp \
--port 5432 \
--initial-delay 0 \
--period 10 \
--failure-threshold 30 # 30 * 10s = 5 min max startup time
# Liveness: Once started, check every 30s
cod asset probe create \
--asset postgres \
--type liveness \
--method tcp \
--port 5432 \
--period 30 \
--failure-threshold 3
Machine Learning Service
# Startup: Allow 3 minutes for model loading
cod asset probe create \
--asset ml-inference \
--type startup \
--method http \
--path /startup \
--port 5000 \
--period 10 \
--failure-threshold 18 # 18 * 10s = 3 min max
# Readiness: Check model is loaded
cod asset probe create \
--asset ml-inference \
--type readiness \
--method http \
--path /ready \
--port 5000 \
--period 5
# Liveness: Ensure model server is responsive
cod asset probe create \
--asset ml-inference \
--type liveness \
--method http \
--path /health \
--port 5000 \
--period 15 \
--timeout 10