Reviewing an Existing Pod
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: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:-
Define the entire command (including its argument) as a single array:
-
Specify separate fields for the command and its arguments:
Correcting a YAML Error with Command Arguments
Next, consider the file “ubuntu-sleeper-3.yaml”. The original file defines the pod as follows:All elements in the command array must be provided as strings.
Attempting to Update an Immutable Field in a Pod
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:Inspecting Dockerfiles and Container Commands
Dockerfile in /root/webapp-color
Examine the following Dockerfile, which sets up a Python web application:python app.py on startup.
Dockerfile2 with a CMD Override
Consider Dockerfile2, which includes both an ENTRYPOINT and a CMD instruction:Overriding Container Commands via Kubernetes Manifests
webapp-color-2 Directory
The directory “webapp-color-2” contains the following files:- Dockerfile2
- webapp-color-pod.yaml
--color green instead of --color red.
webapp-color-3 Directory
In the “webapp-color-3” directory, the provided files are: Dockerfile2:Creating a Pod with Overridden Startup Arguments
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 withkubectl run and using a double dash (”—”) to separate kubectl options from container arguments. Execute the following command:
--) 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.