Env. Variables & Probes
Kubernetes allows you to configure runtime behavior of containers using environment variables, and to monitor their health using liveness and readiness probes. These features are essential for building reliable, configurable, and observable applications in the cluster.
Environment Variables
You can pass key-value pairs into containers using environment variables. These can be hardcoded, referenced from ConfigMaps, Secrets, or even dynamically derived from field references.
Static Environment Variables
From ConfigMap
Or individual keys:
From Secret
From Pod Metadata
Probes Overview
Kubernetes uses probes to check if a container is:
- Alive (liveness probe): Whether the app should be restarted
- Ready (readiness probe): Whether the app is ready to receive traffic
- Started (startup probe): Whether the app has finished starting up
Each probe runs a check (HTTP request, TCP socket, or command) and takes action based on success or failure.
Liveness Probe
Restarts the container if the probe fails repeatedly.
Readiness Probe
Used to signal when the container is ready to receive traffic. If the probe fails, the Pod is removed from Service endpoints.
Startup Probe
Useful for applications that take a long time to initialize. Prevents premature liveness failures during startup.
Best Practices
- Use readiness probes to avoid routing traffic to unready pods.
- Use liveness probes for self-healing on deadlocks or hung apps.
- Use startup probes for slow-starting applications.
- Avoid setting
initialDelaySeconds
too low — allow the app to start first. - Prefer HTTP or command probes for rich diagnostics.
Summary
Environment variables allow you to make your containerized applications configurable without rebuilding images. Probes give Kubernetes insight into the health and lifecycle of your applications, enabling smart traffic routing and automated restarts. Together, these tools form the backbone of robust and production-ready workloads.