command and args. You will learn how to inspect running Pods, write correct manifests, fix YAML type errors, replace immutable fields, and understand how Docker ENTRYPOINT/CMD interact with Kubernetes command/args.
Related reading:
1) How many pods exist and what command runs the Pod?
There was one Pod on the cluster. Inspect the Podubuntu-sleeper to view the container and the command specified for it:
- The container’s
Commandis shown as an array where the first element is the executablesleepand the second element is the argument4800. - In effect, the container is running the process
sleep 4800.
2) Create a Pod that sleeps for 5,000 seconds (ubuntu-sleeper-2)
You are given a basic manifestubuntu-sleeper-2.yaml. Update it so the container runs sleep for 5000 seconds. Remember that Kubernetes expects command and args arrays to contain strings.
Initial manifest:
command + args:
kubectl describe — you should see Command: sleep and Args: 5000:
command, e.g. command: ["sleep", "5000"]. Using command + args separately often makes intent clearer.
3) Fix the manifest ubuntu-sleeper-3.yaml (type errors in command elements)
A manifest attempted to set the container’s command like this:- YAML parses unquoted numbers as numeric types. Kubernetes expects each element of the
commandarray to be a string; non-string elements cause API server errors.
4) Update the Pod ubuntu-sleeper-3 to sleep for 2000 seconds
Some Pod fields are immutable after creation (for example, the containercommand/entrypoint). Editing the in-cluster object with kubectl edit pod to change the container command will typically be forbidden.
Two safe ways to update an immutable field:
- Edit your local manifest file (source YAML) and recreate the Pod.
- Force replace the Pod using
kubectl replace --force -f <file>, which deletes and recreates the Pod from the provided file.
- Update local manifest to set
argsto2000:
- Replace the Pod by deleting and recreating (force replace):
If you need to change immutable fields of a Pod, update the manifest and recreate the Pod. For production workloads, use controllers (Deployments, StatefulSets, etc.) that support rolling updates and avoid manual Pod replacements.
5) Inspecting Dockerfiles and how runtime commands are composed
Review the Dockerfile at/root/webapp-color/Dockerfile:
ENTRYPOINTis["python", "app.py"].- If the image also has a
CMD, Docker will pass theCMDvalues as arguments to theENTRYPOINTunless overriden at runtime.
CMD (Dockerfile2):
ENTRYPOINT (executable) + CMD (default arguments) by default.
6) Kubernetes manifest: overriding ENTRYPOINT vs. providing args
In thewebapp-color-2 example, the files include:
- Dockerfile2 (as above)
- Kubernetes Pod manifest
webapp-color-pod.yaml:
- In Kubernetes,
spec.containers.commandmaps to Docker’sENTRYPOINT— it replaces the image’sENTRYPOINT. spec.containers.argsmaps to Docker’sCMD— it overrides or supplies arguments passed to the image’sENTRYPOINT.
command: ["--color", "green"], Kubernetes will attempt to run --color as the executable, which will fail (because --color is an argument, not a binary).
If the intent is to run the image’s ENTRYPOINT (python app.py) and pass --color green, use args instead:
Important:
command replaces the container ENTRYPOINT. Use args to supply or override the CMD (i.e., arguments) while preserving the image’s ENTRYPOINT executable.Quick Reference: ENTRYPOINT/CMD vs. Kubernetes command/args
This completes the walkthrough for: inspecting Pods, specifying
command/args in manifests, correcting YAML type errors, updating immutable fields by recreating Pods, and understanding how Docker ENTRYPOINT/CMD interact with Kubernetes command/args.