sleep, troubleshooting common YAML issues, updating immutable Pod fields, and understanding how Docker ENTRYPOINT and CMD interact with Kubernetes command and args.
Quick checks
- How many pods exist on the system?
- Run:
- In this environment there’s a single pod.
- What is the command used to run the Pod
ubuntu-sleeper?
- Inspect the pod with:
- Interpretation:
kubectl describeshows the containerCommand:as multiple lines. This corresponds to the array["sleep", "4800"]. Kubernetes expects each element in thecommandarray 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. Addcommand and/or args so the container runs sleep 5000.
Initial minimal file:
- Both
commandandargsin Pod YAML are arrays of strings. commandmaps to the container entrypoint.argsmaps to arguments passed to that entrypoint.- You can either set
commandandargsseparately, or put executable and its arguments together incommand.
command + args:
command:
kubectl describe:
Task: Fix ubuntu-sleeper-3.yaml (numeric element must be a string)
Problematic file (numeric array element is unquoted):- YAML parser treats
1200as a number. Kubernetes expectscommandelements to be strings, so the API server returns an unmarshalling error.
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[*].commandwill give a forbidden error.
- Recommended: edit your local manifest, then delete and recreate the Pod:
- Update
ubuntu-sleeper-3.yaml(change"1200"to"2000"). - Delete and recreate:
- Update
- Alternative: force replace:
This deletes and recreates the resource — useful in some scenarios but be aware it causes Pod termination and recreation.
- 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
- Dockerfile example:
webapp-color/Dockerfile
ENTRYPOINT ["python", "app.py"]defines the executable run at container start:python app.py.
- Dockerfile with both ENTRYPOINT and CMD:
- For this image the default runtime command becomes:
python app.py --color red
ENTRYPOINTsets the executable (python app.py).CMDprovides default arguments appended to theENTRYPOINT.
- Kubernetes Pod manifest that overrides the container command
webapp-color-2:
webapp-color-pod.yaml:
- Kubernetes
container.commandmaps to DockerENTRYPOINT. Ifcommandis provided in the Pod manifest, it replaces the imageENTRYPOINT. - Kubernetes
container.argsmaps to DockerCMD. Ifargsare provided, they replace the imageCMD.
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 poddisplaysCommandandArgsas multi-line lists corresponding to arrays of strings.- In Pod YAML, always represent
commandandargselements as strings (quote numeric-looking values). - To change immutable Pod fields (like
command), update the manifest and recreate the Pod or usekubectl replace --force. - Docker
ENTRYPOINTsets the executable;CMDsets default arguments. Kubernetescommandoverrides ENTRYPOINT andargsoverrides CMD. Useargswhen you want to pass additional arguments to the image’s ENTRYPOINT.