liveBook · Manning

Chapter 6: Managing the pod life cycle and container health

What you will learn in chapter 6 of Kubernetes in Action, Second Edition

This chapter introduction previews a deeper look at pod and container operation, including status, health, lifecycle hooks, and life cycles.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This chapter introduction previews a deeper look at pod and container operation, including status, health, lifecycle hooks, and life cycles.

6.1 Understanding the pod’s status

This section identifies where to read a pod’s status and which status fields matter for understanding its life cycle.

Key terms: Pod object, status section, phase, conditions, container states

6.1.1 Understanding the pod phase

The section introduces the pod phase as a quick summary of a pod’s state, shows where to inspect it, and cautions that kubectl’s STATUS column does not always show the phase.

Key terms: pod phase, Pod object, status section, kubectl get pods, STATUS column, kubectl describe, status.phase

6.1.2 Understanding pod conditions

This section explains how pod conditions give a more detailed view of a pod’s state than its phase and how to inspect those conditions.

Key terms: pod phase, pod conditions, PodScheduled, Initialized, Ready, ContainersReady, kubectl describe, status.conditions, status, reason

6.1.3 Understanding the container status

This section explains what individual container statuses reveal and how to inspect them in a pod.

Key terms: container status, state, lastState, containerID, imageID, ready, kubectl get pods, kubectl describe, initContainerStatuses

6.2 Keeping containers healthy

This section introduces the question of how to keep pods healthy and their containers running when containers die.

6.2.1 Understanding container auto-restart

This section explains how Kubernetes responds when a container terminates, how a pod’s restart policy affects that response, and why repeated terminations delay restarts.

Key terms: Kubelet, Pod object, container restart, container filesystem, restartPolicy, pod spec, exit code, exponential back-off, CrashLoopBackOff, Waiting

6.2.2 Checking the container’s health using liveness probes

This section explains why liveness probes are needed, what Kubernetes does when one fails, and how the three probe types determine success.

Key terms: unresponsive, liveness probe, restart policy, regular containers, init containers, HTTP GET probe, TCP Socket probe, Exec probe

6.2.3 Creating an HTTP GET liveness probe

Shows how to add HTTP GET liveness probes to both containers in a pod and configure their targets and failure timing.

Key terms: HTTP GET probe, path, port, HTTP status, Envoy proxy, /ready, admin port, initialDelaySeconds, periodSeconds, timeoutSeconds

6.2.4 Observing the liveness probe in action

Shows how to observe successful and failing liveness probes, a container restart after repeated failures, and evidence of how the container shut down.

Key terms: liveness probe, container logs, /tmp/envoy.admin.log, Warning event, failureThreshold, RESTARTS, exit code zero, exit code 137, SIGTERM, --previous

6.2.5 Using the exec and the tcpSocket liveness probe types

Explains how tcpSocket and exec liveness probes check container health when an application has no HTTP health-check endpoint.

Key terms: tcpSocket liveness probe, TCP port, failureThreshold, exec liveness probe, exit code, timeoutSeconds

6.2.6 Using a startup probe when an application is slow to start

Explains how a startup probe lets a slow-starting application warm up without delaying detection of health problems after startup.

Key terms: liveness probe, periodSeconds, failureThreshold, initialDelaySeconds, startup probe

6.2.7 Creating effective liveness probe handlers

This section explains how to design liveness checks that detect a stuck application without causing unnecessary restarts or consuming excessive resources.

Key terms: liveness probe, probe handler, health-check endpoint, /healthz, internal components, backend service, HTTP GET probe, exec liveness probe, failureThreshold, retry loop

6.3 Executing actions at container start-up and shutdown

Introduces container lifecycle hooks, when they run, where they are configured, and which handlers they support.

Key terms: lifecycle hooks, post-start hooks, pre-stop hooks, regular containers, init containers, HTTP GET, tcpSocket handlers

6.3.1 Using post-start hooks to perform actions when the container starts

This section explains how post-start hooks run initialization actions when a container starts, using exec and HTTP GET examples, and shows how their timing and failures affect the container.

Key terms: post-start lifecycle hook, exec, httpGet, fortune, nginx:alpine, postStart, Waiting, ContainerCreating, Pending, FailedPostStartHook

6.3.2 Using pre-stop hooks to run a process just before the container terminates

This section explains how pre-stop hooks run before container termination, how they can support graceful shutdown, and why they are not a substitute for correct signal handling.

Key terms: pre-stop hook, SIGTERM, nginx -s quit, graceful shutdown, exec, httpGet, sleep, FailedPreStopHook, ENTRYPOINT, CMD

6.4 Understanding the pod life cycle

Introduces the three stages of a pod’s life cycle, from initialization through running to termination.

Key terms: initialization stage, run stage, termination stage, init containers, regular containers

6.4.1 Understanding the initialization stage

This section explains how a pod starts its init containers, pulls their images, handles failures, and may occasionally run them again.

Key terms: init containers, initContainers, regular containers, imagePullPolicy, Always, image registry, restart policy, OnFailure, Never, Init:Error

6.4.2 Understanding the run stage

This section traces what happens to regular pod containers during the run stage, from image pulling and startup through health checks, termination, and possible restart.

Key terms: init containers, regular containers, post-start hook, imagePullPolicy, main container process, startup probe, liveness probe, failure threshold, restartPolicy, Terminated state

6.4.3 Understanding the termination stage

Explains how deleting a pod terminates its containers, how the deletion grace period controls shutdown time, and why handling SIGTERM matters.

Key terms: Terminating, pre-stop hook, SIGTERM, KILL signal, deletion grace period, metadata.deletionGracePeriodSeconds, spec.terminationGracePeriodSeconds, --grace-period, pre-stop hooks, kiada-ssl Pod

6.4.4 Visualizing the full life cycle of the pod’s containers

This section summarizes the pod’s initialization and normal operation, emphasizing when native sidecar containers start and terminate.

Key terms: restartPolicy, Always, sidecar container, initContainers, regular containers

6.5 Summary

Summarizes how to inspect pod status, understand container replacement and health checks, and manage container startup and graceful shutdown.

Where this is used later

Concepts explained in this chapter

← Chapter 5: Running applications with pods Chapter 7: Organizing pods and other resources using namespaces and labels →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.