Skip to main content
This lesson walks through inspecting container commands in Kubernetes Pods, creating Pods that run sleep, troubleshooting common YAML issues, updating immutable Pod fields, and understanding how Docker ENTRYPOINT and CMD interact with Kubernetes command and args.

Quick checks

  1. How many pods exist on the system?
  • Run:
  • In this environment there’s a single pod.
  1. What is the command used to run the Pod ubuntu-sleeper?
  • Inspect the pod with:
Example (relevant excerpt):
  • Interpretation: kubectl describe shows the container Command: as multiple lines. This corresponds to the array ["sleep", "4800"]. Kubernetes expects each element in the command array to be a string.
When kubectl describe prints Command: on separate lines, read that as an array of strings (e.g. ["sleep", "4800"]). Each element in command or args must be a string.

Task: Create a Pod that sleeps for 5000 seconds (modify ubuntu-sleeper-2.yaml)

You are given a minimal Pod manifest. Add command and/or args so the container runs sleep 5000. Initial minimal file:
Notes:
  • Both command and args in Pod YAML are arrays of strings.
  • command maps to the container entrypoint.
  • args maps to arguments passed to that entrypoint.
  • You can either set command and args separately, or put executable and its arguments together in command.
Option A — explicit command + args:
Option B — executable and argument together in command:
Create the Pod:
Verify with kubectl describe:
Relevant excerpt:
Both approaches are valid; pick whichever is clearer for your manifest.

Task: Fix ubuntu-sleeper-3.yaml (numeric element must be a string)

Problematic file (numeric array element is unquoted):
Why it fails:
  • YAML parser treats 1200 as a number. Kubernetes expects command elements to be strings, so the API server returns an unmarshalling error.
Error example:
Fix by quoting numeric-looking values so they become strings:
After fixing:
Always represent command and args elements as strings in YAML. Quote numeric-looking values (e.g. "1200") to avoid JSON/YAML type errors on the API server.

Task: Change ubuntu-sleeper-3 to sleep for 2000 seconds

Why editing in place fails:
  • Many Pod spec fields are immutable after creation. Attempting to edit spec.containers[*].command will give a forbidden error.
Example error when attempting to modify the Pod in-place:
Options to update an immutable field:
  • Recommended: edit your local manifest, then delete and recreate the Pod:
    • Update ubuntu-sleeper-3.yaml (change "1200" to "2000").
    • Delete and recreate:
  • Alternative: force replace:
    This deletes and recreates the resource — useful in some scenarios but be aware it causes Pod termination and recreation.
Note on termination:
  • Deleting a Pod triggers graceful shutdown. The container process receives a SIGTERM and may take time to exit depending on your application.
Pod spec fields such as container command are immutable. To change them, recreate the Pod (delete + create) or use kubectl replace --force -f <file>. Expect the Pod to be terminated and restarted.

Inspect Dockerfiles to understand ENTRYPOINT vs CMD

  1. Dockerfile example: webapp-color/Dockerfile
Contents:
  • ENTRYPOINT ["python", "app.py"] defines the executable run at container start: python app.py.
  1. Dockerfile with both ENTRYPOINT and CMD:
Contents:
  • For this image the default runtime command becomes:
    • python app.py --color red
  • ENTRYPOINT sets the executable (python app.py).
  • CMD provides default arguments appended to the ENTRYPOINT.
  1. Kubernetes Pod manifest that overrides the container command
Example files under webapp-color-2:
webapp-color-pod.yaml:
Important behavior:
  • Kubernetes container.command maps to Docker ENTRYPOINT. If command is provided in the Pod manifest, it replaces the image ENTRYPOINT.
  • Kubernetes container.args maps to Docker CMD. If args are provided, they replace the image CMD.
In the webapp-color-pod.yaml example, command: ["--color", "green"] will cause Kubernetes to try to execute --color as the process (with green as argument), not python app.py --color green. That is likely unintended — to pass --color green to the existing entrypoint, set args instead of command. Summary table (mapping Docker image vs Kubernetes fields) Examples:
  • To append arguments to an image with ENTRYPOINT ["python", "app.py"]:
  • To fully replace what the image runs:

Key takeaways

  • kubectl describe pod displays Command and Args as multi-line lists corresponding to arrays of strings.
  • In Pod YAML, always represent command and args elements as strings (quote numeric-looking values).
  • To change immutable Pod fields (like command), update the manifest and recreate the Pod or use kubectl replace --force.
  • Docker ENTRYPOINT sets the executable; CMD sets default arguments. Kubernetes command overrides ENTRYPOINT and args overrides CMD. Use args when you want to pass additional arguments to the image’s ENTRYPOINT.
Further reading:

Watch Video