-This is the solution video for the commands and arguments lab.
For the first question, we have to find the number
of pods on the system.
Let's go to the terminal and type kubectl get pods.
You can see that there is already a pod deployed, which
is called ubuntu-sleeper.
The answer is one.
Next, find out the command used to run the pod ubuntu-sleeper.
To find this we can run the command kubectl describe pod and
the pod name, ubuntu-sleeper, and let's look for the command.
That is set to sleep 4,800.
Select that from the options.
Next, we have to create a pod with the ubuntu image to run our
container to sleep for 5,000 seconds.
To do this, we'll modify a file that has been provided already, and
it's called ubuntu-sleeper-2.yaml.
Go to the terminal.
First, let's copy the name of the YAML file, and we
are in the /root directory.
Edit this file, and we are going to add a command section here, and
the value should be sleep 5,000.
Save this file, and let's try to create the pod.
Looks like I've made a mistake.
There is an unknown field called commands, so
there's a typo in the file.
It should be command, not commands.
Let's correct that and try that again.
This time the pod has been created.
We can validate that the pod has been created correctly with the command by
using the kubectl describe, and yes, it has the command for sleep 5,000.
Let's go ahead and check the solution.
Moving on the next question, we have to create a pod using another
file called ubuntu-sleeper-3.yaml.
There is something wrong with it, so we have to fix it.
Let's copy the YAML file, and we'll attempt to create the pod using
kubectl apply and look for errors.
There is an error here, so let's go and check the YAML file.
You'll see that in the command section the seconds have not
been described correctly, so it should be within double-quotes.
Let's change that.
Save the file and try again.
Let's move on to the next question.
We have to update the pod ubuntu-sleeper-3 to
sleep for 2000 seconds.
First, let's delete the existing pod, ubuntu-sleeper-3.
Wait for the pod to be terminated completely.
Once that is done, will edit the file again and change the command to 2000.
This can take a few seconds, so be patient.
The pod has been terminated.
Let's update the file and change the seconds from 1200 to 2000.
Now see this file and recreate the pod using kubectl apply.
Moving on.
Now we have to inspect the Dockerfile, which is located
at /root/webapp-color and find out the command that is
run at the container startup.
To do this we will open the Dockerfile in that location and
look for the entry point, which is defined within the Dockerfile.
If you look at the bottom here, the entry point is set to python app.py.
Let's choose that as our answer.
Now we have to inspect another Dockerfile called the Dockerfile2
given at the same location.
We have to find the command that will run at the container startup.
Same as before. Let's inspect the Dockerfile2.
In this case you'll notice that the Dockerfile2 has
both entry point and command.
Effectively, the command that would be run during container startup
is python app.py --color red.
Now let's inspect the two files under the directory webapp-color-2.
What is the command that will be run during the container startup?
Let's go and check those two files.
Copy the directory name.
Go back to root, and let's go inside this directory and list the files.
There is a Dockerfile2, and there is a YAML file for that pod.
First let's inspect the Dockerfile2.
It's same as the last question.
It has got an entry point python app.py, and it has got
a command section --color red.
Now let's inspect the YAML file, which will be used to create the pod.
The pod will make use of the image created from that Dockerfile.
In this case, you'll see that the pod has just one command
field, which is --color green.
If you remember from the lecture, you'll know that the command field
in the Kubernetespod definition file will override the entry point.
There is no argument section provided here.
Effectively, the command that will be run during the startup
of this pod is --color green.
Let's select that as our answer.
For the next question, we have to do the same thing in another
directory called webapp-color-3, and find out the command that will
run during the container startup.
Let's copy that directory and change directory into webapp-color-3,
and let's check out the files.
First thing as before, we'll check out the Dockerfile and
it's exactly the same as before.
There's an entry point, python app.py, and the command,
which comes after that is --color, and the value is red.
Now, let's check out the pod definition file.
Here you'll notice that the pod definition has both command
and arguments, so effectively, it will override everything
that is there in the Dokerfile.
During the startup, the command that would be run is python
app.py followed by the arguments, which is color is equal to pink.
Let's choose that as the answer, python, app.py,
color is equal to pink.
Finally, we have to create a pod with the given specification.
By default, it displays a blue background.
Set the given command line arguments to change it to green.
The pod name is webapp-green.
Image is kodekloud/webapp-color, and we have have to provide the command
line arguments of --color=green.
Let's do that.
Go back to the terminal, and let's create a pod definition
file using kubectl run. Name of the pod --image.
It is called cloud webapp-color.
We'll use the --dry-run and -0 yaml to create a pod definition file.
Let's store it in pod.yaml.
I forgot, --restart is equal to never.
Make sure that you add that in.
Now let's update the pod.yaml file.
Under the container section, I'm going to add a new field
for arguments is equal to color as equal to green.
I can just copy it from the question, --color is equal to green.
Now let's create this pod, and check that it has been created correctly.
Run our kubectl describe and inspect the arguments.
Let us say two --color=green.
Let's validate the answer.
That's correct.
Thank you for joining me in this lab solution video.
I'll see you on the next one.