Pod Commands and Arguments
What You'll Learn
You'll learn how to override the default commands and arguments defined in a container image when running Pods in Kubernetes.
Why Override Commands?
When you package an application into a container image, it typically includes a default command that runs when the container starts. However, you often need to customize what actually executes or pass different parameters without rebuilding the entire image. Kubernetes lets you override these defaults directly in your Pod specification.
Think of it like a microwave with preset buttons—the image has defaults (popcorn, 2 minutes), but you can override them (popcorn, 3 minutes, high power) each time you use it.
Command vs Args
Kubernetes provides two fields for this:
command: Overrides the container'sENTRYPOINT(the executable that runs)args: Overrides the container'sCMD(arguments passed to that executable)
If you specify command, it completely replaces the image's default entrypoint. If you specify args, it replaces the default arguments but keeps the original command unless you also override it.
Basic Example
apiVersion: v1
kind: Pod
metadata:
name: custom-command-pod
spec:
containers:
- name: my-container
image: busybox
command: ["echo"]
args: ["Hello from Kubernetes"]
This Pod runs echo "Hello from Kubernetes" instead of busybox's default shell.
Practical Use Cases
- Running different modes of the same application (debug vs production)
- Passing environment-specific configuration flags
- Testing different parameters without rebuilding images
Key Takeaway: Use command and args in your Pod spec to customize what runs inside containers without modifying the underlying images, providing flexibility for different execution scenarios.