liveBook · Manning

Container auto-restart

As explained in Kubernetes in Action, Second Edition

A container restart is the termination and subsequent creation or execution of a replacement instance of a container by its runtime or orchestrator.

Container auto-restart keeps a Pod’s containers running while the Pod exists. When a container’s main process terminates, the Kubelet starts it again, allowing an application to recover without special application code. Other containers in the same Pod continue running when one container fails. section 6.2.1

Watching a failed container recover

Run kubectl get pods -w, then terminate the Envoy container through its administration endpoint with curl -X POST http://localhost:9901/quitquitquit. The Pod briefly changes from Running to NotReady, shows only one ready container, and returns to Running with RESTARTS increased to 1. Kubernetes records the restart through events. section 6.2.1

A liveness probe can also trigger a restart. Kubernetes waits until the probe reaches its failureThreshold; after three consecutive failures in the example, it stops and restarts Envoy. Repeated failures produce an exponential back-off and may appear as CrashLoopBackOff. section 6.2.4

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains restart policies, readiness changes, probe thresholds, exit states, events, and exponential back-off.
Examples
Demonstrates Envoy termination, curl administration requests, kubectl watches, event streams, and failed liveness checks.
What it assumes
Assumes a running Kubernetes Pod and basic use of kubectl, curl, and a container administration endpoint.
What you can do after
Diagnose container recovery with kubectl status, event, manifest, and log commands.
How it connects
Connects container restarts with Kubernetes Pods, Kubelet, liveness probes, readiness, restart policies, events, and CrashLoopBackOff.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.