Container configuration and lifecycle
From an image to a running process
A container image contains the packaged application and its default startup configuration. A Pod manifest can select an image and override the process it launches. In this lesson use ordinary application containers with no per-container restart rules or special sidecar behavior. Those advanced cases are covered separately.
Inspect a short-lived container
Here is an offline Pod manifest. Assume the fictional tools image contains /bin/echo. The image is intentionally unavailable, so the example describes expected behavior only; it is not deployable.
apiVersion: v1kind: Podmetadata: name: greeting namespace: book-labspec: automountServiceAccountToken: false restartPolicy: Never containers: - name: greet image: example.invalid/tools:1 imagePullPolicy: Never command: ["/bin/echo"] args: ["Hello, catalog"] env: - name: APP_MODE value: "demo" resources: requests: {cpu: 25m, memory: 16Mi} limits: {cpu: 50m, memory: 32Mi}If a reviewed replacement image provided this executable, the process would print Hello, catalog and exit with code 0. command selects the executable and args supplies its arguments. These fields generally replace the image entrypoint and default arguments respectively. This command is launched directly, not interpreted as shell text. For shell features such as pipes, an explicit shell executable is needed and the image must supply it. APP_MODE is a string in the process environment; echo does not use it.
Image identity and pull behavior
An image tag is a movable reference; a digest identifies specific image content. A lab intended to reproduce results should use a reviewed pinned image, rather than assuming a tag still points to the same artifact. A digest does not establish that the image is secure. imagePullPolicy: Never requires an already available image; it is not an instruction to fetch one. IfNotPresent permits retrieval when absent; Always resolves the image reference at launch and can reuse locally cached content. Actual defaults depend on the image reference and are set when the object is created. The fixture uses Never to emphasize its offline-only design.
Choose a restart policy
The Pod-level restartPolicy controls ordinary container restarts on the same node, in the absence of container-specific overrides. Always restarts after both successful and failed exits; OnFailure restarts after failures (for example exit code 1), but not after success; Never does not restart after exit. The default Pod-level policy is Always. A restart is not a new Pod. A successful one-shot task is normally a better fit for a Job controller, studied later. A restart can be delayed by backoff; none of these policies guarantees that an application becomes healthy.
Predict six outcomes
The following offline decision table assumes a single ordinary application container, a functioning node and no other constraints. It records whether the exit calls for a restart, not when it will occur.
Policy Exit 0 Exit 1Always restart restartOnFailure stop restartNever stop stopUnder Never, a Pod whose only container exits successfully can reach Succeeded; a failed exit can lead to Failed. With Always, a short successful command can repeatedly run instead of staying completed. Repeated failure is not fixed simply by requesting another restart.
Practice
Compare greeting.yaml and the six cases in restart-cases.json in the fixture directory. Predict the result of each case and explain the choice for a one-time report. Inspect the argument boundaries: the greeting is one argument containing a space, not two. Do not execute or pull the illustrative image.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Container configuration and lifecycle — knowledge check
Apply the lesson concepts to original offline scenarios.
What is the process argument in the greeting manifest?
Which policy calls for a restart following both exit 0 and exit 1?
Which policy restarts a failed ordinary container but not a successful one?
What does imagePullPolicy Never require?
What does pinning an image digest establish?