6 Managing the lifecycle of the Pod’s containers


This chapter covers

  • Inspecting the pod’s status
  • Keeping containers healthy using liveness probes
  • Using lifecycle hooks to perform actions at container startup and shutdown
  • Understanding the complete lifecycle of the pod and its containers

After reading the previous chapter, you should be able to deploy, inspect and communicate with pods containing one or more containers. In this chapter, you’ll gain a much deeper understanding of how the pod and its containers operate.

6.1       Understanding the pod's status

After you create a pod object and it runs, you can see what’s going on with the pod by reading the pod object back from the API. As you’ve learned in chapter 4, the pod object manifest, as well as the manifests of most other kinds of objects, contain a section, which provides the status of the object. A pod’s status section contains the following information:

  • the IP addresses of the pod and the worker node that hosts it
  • when the pod was started
  • the pod’s quality-of-service (QoS) class
  • what phase the pod is in,
  • the conditions of the pod, and
  • the state of its individual containers.

The IP addresses and the start time don’t need any further explanation, and the QoS class isn’t relevant now - you’ll learn about it in chapter 19. However, the phase and conditions of the pod, as well as the states of its containers are important for you to understand the pod lifecycle.

6.1.1   Understanding the pod phase

6.1.2   Understanding pod conditions

6.1.3   Understanding the status of the containers

6.2       Keeping containers healthy

6.2.1   Understanding container auto-restart

6.2.2   Checking the container’s health using liveness probes

6.2.3   Creating an HTTP GET liveness probe

6.2.4   Observing the liveness probe in action

6.2.5   Using the exec and the tcpSocket liveness probe types

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

6.2.7   Creating effective liveness probe handlers

6.3       Executing actions at container start-up and shutdown

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

6.3.2   Running a process just before the container terminates

6.4       Understanding the pod lifecycle

6.4.1   Understanding the initialization stage

6.4.2   Understanding the run stage

6.4.3   Understanding the termination stage

6.4.4   Visualizing the full lifecycle of the pod’s containers

6.5       Summary