[No Audio]
Hello, everyone. As usual, let's start this demo
with a list of available Pods. We have two Pods,
cmd, and lifecyc-pods. One of them is completed
and the other one is still running. Now let's open
the YAML file environment-pod.yaml with nano.
Again, the YAML is pretty similar to
previous demos, so we should focus on the changes.
The names of pod and container, are env-pod,
and env-container. Just like our usual
naming convention. If you take a look at the
image, we have not simply provided a name with
label, we have the whole path or URL of the image.
We have done this, because this time, we don't want
to use Docker Image registry, we want to use
Google Container Registry, which is another place
to find container images. In this demo, we are
using one of the sample Google images called node-hello.
This node hello is more or less like Hello World
of Docker Image registry, and this one is
built on top of alpine base image. With that said,
let's get to the cream of this demo, which is env
or env field, which is used to provide
environment variables to the container. If the
container does not have the environment variables
provided within this field, it adds it along with
its default environment variables. And if an
environment variable with the same name has
already been set up by the Docker Image, the
running container replaces it by the values we provide.
So take this example. Let's say we have a
Docker Image and we provide it environment variables
A, B, and C equals P, Q, and R respectively.
If we are providing the same environment variables with
different values using Kubernetes YAML file, just
like Docker, only the running container will
reflect the changed value. Which means that the
values will reflect on a copy of the image and the
original image will remain unchanged.
So the original images, environment variables would still
be A, B, C equals P,Q, and R, but a copy of it will
have it as A, B, C equals S, T, and U, or anything
else which we provide. In this case, we are
providing to environment variables, POD_GREETING
and POD_FAREWELL, and their values are suitable to
the name as well. POD_GREETING is 'Welcome!', and POD_FAERWELL is,
'We don't want you to go!' with a sad smiley.
With that said, let's save and exit our file.
Let's create the Pod using kubectl create -f command.
Let's see if it is running or not.
The Pod seems to be Running. Now let's get a
description of this Pod using kubectl describe pod
followed by its name env-pod.
Here is the description of this Pod. Let's straightaway
jump to the Environment section and we have two
entries in this field, POD_GREETING and POD_FAREWELL.
Exactly the ones which we had set up.
Let's clear it and execute this Pod using kubectl exec -it
followed by Pod name followed by
the command which we want to run. You may notice
that this command is pretty similar to what Docker
has provided for executing a container as well.
Now we are in root directory of our container.
Let's print our environment variables. And there
we go, we have a long list of environment
variables. This answers more than one questions.
First of all, what about the environment variables
that we had set up? Well, here they are.
Both POD_GREETING and POD_FAREWELL are present.
And second, when we executed the container, why did we
get to root at env pod, not env container.
Well the reason is, we are still in the root directory
of the container itself. But the HOSTNAME is env-pod,
which you can see in this environment
variable. With that out of the way.
Let's exit this container and get back to our terminal.