[No Audio]
Let's start this demo by printing a list of
available Pods using kubectl get pods.
We only have 1 Pod, lifecyc-pod, which is from the
previous demo, because we have deleted the
imperative and declarative Pods. Don't worry,
we will go through how to delete Pods as well.
But for now, let's go to the file command-pod.yaml.
The YAML file looks pretty similar compared to
previous two demos as well. So let's focus on the
changes here. First of all, the names of the pod
and container have changed. The pod is named cmd-pod,
and the container is named cmd-container.
Makes sense. Then, in spec field, after
name and image of the container, we have command
field, command field indicates the entrypoint
command in the Docker Image. If we do not provide
any command or value to the command field,
Kubernetes uses default entrypoint of Docker Image.
But we can change it by providing command
and its arguments. Instead of keeping the
container up by running a loop of bash command,
we are just asking it to print a couple of
environment variables. So the command is printenv,
and its arguments are HOSTNAME, and
KUBERNETES_PORT. You may notice, that
the command and the arguments are written in
between double inverted commas and they're
encapsulated by square brackets. The arguments are
separated by a comma. Let's exit the file and
make a Pod. Run kubectl create -f command-pod.yaml.
The port should have been created.
Let's test it with kubectl get pods.
Here we go, but check it out. This pod is not in
Running state, it is in the Completed state.
The reason is, we have not provided any endless loop
command like bash, we had just asked it to print a
couple of environment variables, which it did
successfully within a few milliseconds maybe. So by
the time we run the command kubectl get pods, the
container had already finished its task and the
Pod was in Completed state. Let's have a
description of this Pod using kubectl describe pod cmd-pod.
Here is our long, well-structured
description. I'm pretty sure you can comprehend
most of the parts easily, so let's directly jump
to the command and arguments section. The command
is the same what we had provided, which is printenv,
and its arguments are HOSTNAME and KUBERNETES_PORT.
Now if we jump to Events, we can
also see that the container had started 35 seconds ago,
whereas it finished 34 seconds ago. So within
one second all of the commands were performed.
We can also verify this by looking at the log of the Pod.
Simply write kubectl logs and then the Pod name
which is cmd-pod. And there you go,
we have our HOSTNAME and KUBERNETES_PORT both printed.