Explain readiness liveness and reconciliation
Explain readiness liveness and reconciliation
Readiness controls traffic eligibility; liveness detects a process that should restart; startup probes protect slow initialization from premature liveness failures. A temporary dependency outage often makes a service unready, not dead. A controller reconciles observed state toward desired state repeatedly. Its actions must tolerate retries and stale observations.
package main
import ( "fmt" "net/http" "net/http/httptest" "sync/atomic")
type Health struct{ Ready atomic.Bool }
func (h *Health) ready(w http.ResponseWriter, r *http.Request) { if !h.Ready.Load() { w.WriteHeader(http.StatusServiceUnavailable) return } w.WriteHeader(http.StatusOK)}func main() { h := &Health{} for _, ready := range []bool{false, true} { h.Ready.Store(ready) w := httptest.NewRecorder() h.ready(w, httptest.NewRequest("GET", "/ready", nil)) fmt.Println(w.Code) }}An atomic boolean safely publishes an admission decision. In a real service set it after initialization and clear it before draining. Keep liveness cheap and independent of temporary downstream failures when restart cannot help. This is a handler test, not a Kubernetes probe or traffic routing test.
Expected output:
503200Model one reconciliation decision
package main
import ( "fmt")
func action(desired, observed int) string { switch { case observed < desired: return "create" case observed > desired: return "remove" default: return "none" }}func main() { for _, n := range []int{1, 2, 3} { fmt.Println(action(2, n)) }}This decision model is not a real controller. A real reconciler reads current state, acts with ownership and version checks, and requeues on transient failures. Repeating the same observation must not create unlimited resources: use stable identities or idempotent API operations. Re-read state after ambiguous failures.
Expected output:
createnoneremoveConfigure distinct probe endpoints
This container fragment assumes /live returns 200 when the process can make progress and /ready returns 200 when traffic can be accepted. /live must be safe during startup. The startup probe delays other probes until it succeeds. Choose periods and thresholds from observed startup and failure behavior; no cluster execution was performed.
startupProbe: httpGet: path: /live port: 8080 periodSeconds: 2 failureThreshold: 30livenessProbe: httpGet: path: /live port: 8080 periodSeconds: 10readinessProbe: httpGet: path: /ready port: 8080 periodSeconds: 5Try it locally
Model readiness as initialized AND not draining. Print false for uninitialized, true for initialized and false while draining.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Service protocols and cloud 06: Explain readiness liveness and reconciliation
Check the lesson objective before moving on.
What is a readiness failure intended to change?
What should a reconciler do after an ambiguous failure?