This article reviews a lab exercise on Kubernetes container commands and arguments, including pod inspection, YAML modifications, and Dockerfile interactions.
In this lesson, we review a lab exercise focused on Kubernetes container commands and arguments. We will examine existing pods, modify YAML configurations to change container commands and arguments, and explore how Dockerfiles and Kubernetes manifests interact to determine container startup behavior.
Begin by checking the number of pods running on the system. In this example, one pod is active. Next, inspect the pod named “ubuntu-sleeper” to determine the command used to run it:
Copy
Ask AI
kubectl describe pod ubuntu-sleeper
The output reveals:
Copy
Ask AI
Command: $ sleep 4800
This indicates that the container runs with the command sleep 4800. Running the describe command again confirms the same details:
Creating and Modifying a Pod to Sleep for 5000 Seconds
The next task is to create a pod using the Ubuntu image that executes a container with a 5000-second sleep duration. Start by modifying an existing pod definition file named “ubuntu-sleeper-2”. The basic YAML structure is:
Both methods are valid because the first element (i.e., “sleep”) specifies the command and the remaining elements act as arguments. For simplicity, the first approach is recommended. After saving the file, create the pod and verify that it runs with the proper command and argument.
The next task is to update the pod “ubuntu-sleeper-3” so that it sleeps for 2000 seconds instead of 1200 seconds. Attempting a direct edit with:
Copy
Ask AI
command: - "sleep" - "2000"
results in an error because container commands are immutable fields. To apply the change, update the local manifest file and use a forced replace command:
This command deletes the existing pod and creates a new one with the updated command. Expect a brief delay as the old pod terminates and the new pod starts.
In this configuration, the container’s built-in command defined in the Dockerfile is overridden by the manifest, and the container starts with --color green instead of --color red.
The final task is to create a pod that, by default, displays a blue background but needs to be updated to display green. This is achieved by overriding the startup arguments at runtime with kubectl run and using a double dash (”—”) to separate kubectl options from container arguments. Execute the following command:
Copy
Ask AI
kubectl run webapp-green --image=kodekloud/webapp-color -- --color green
All options after the double dash (--) are passed directly to the container, ensuring that the application starts with the --color green parameter. Verify that the pod is running and that the application displays the green color configuration.This concludes the lab exercise on container commands and arguments in Kubernetes. Each section demonstrated how to define, override, and troubleshoot container startup behaviors using YAML definitions and command-line overrides. Happy Kubernetes managing!For more information on Kubernetes fundamentals, check out the Kubernetes Basics documentation.