Kubernetes and Cloud Native Associate (KCNA)Kubernetes FundamentalsEasy

A developer is writing a YAML manifest for a Pod and wants to ensure that a specific container within the Pod continues to run even if the initial command fails or completes. Which field should they configure to achieve this behavior?

  1. Aspec.initContainers
  2. Bspec.containers[].livenessProbe
  3. Cspec.restartPolicy
  4. Dspec.containers[].readinessProbe
Show answer & explanation

Correct answer: C. spec.restartPolicy

The `restartPolicy` field at the Pod level determines how Kubernetes handles container restarts. Setting it appropriately ensures the desired behavior for container lifecycle management within a Pod.

Why the other options are wrong

  • A. Init containers run to completion before app containers start; they don't control the restart policy of main containers.
  • B. Liveness probes are used to determine if a container is still healthy, not to control its restart behavior after termination.
  • D. Readiness probes indicate if a container is ready to serve traffic, not how it restarts after it exits.

Pod restartPolicy

The `restartPolicy` field in a Pod's specification defines how Kubernetes handles container restarts after they terminate.

  • Can be 'Always', 'OnFailure', or 'Never'.
  • Defaults to 'Always' for Deployments and DaemonSets.
  • Defaults to 'OnFailure' for Jobs.
  • Applies to all containers in the Pod.

Memory trick: Always Restart, On Failure, or Never - it's a Policy!

More Kubernetes Fundamentals questions