Let's go over the lab
for environment variables.
The first question is how many pods
exist on the system?
You see that there's just one pod.
Now, what is the environment variable
name set on the container in the pod?
Let's take a closer look at the pod.
Here, we see the environment variable
is defined here and it's app color set to pink,
so it's APP_COLOR.
Now, what is the value set
on the environment variable APP_COLOR?
It is pink.
Now view the web application UI
by clicking on the web APP_COLOR,
the pink here.
Clicking on this opens up
the web application
and it is indeed pink in color.
Now update the environment variable
on the pod to display a green background
and delete and recreate the pod required.
We are going to do a kubectl edit pod
and webapp-color pod.
Now we know that it may not allow us--
of course, it's not going to allow us
to edit this on the pod,
but we don't really care
because we just need the edited
or updated manifest file that we can
then use to replace the pod.
I'm just going to set it to green here
and try and save, but it's going to come back
saying it's forbidden, which is fine.
Just going to exit out of that
but here we have the file,
which has our edits.
If you look at it,
you have the value green here.
Let's use that to replace with force
to kill the existing pod.
Let's run that and wait for that pod
to be deleted
and the new pod to be created.
Let's check the work.
That's done.
Let's click on the link here
and we see that it is green.
Let's proceed.
The next question is about config maps.
How many config maps exist
in the default namespace?
We're going to do a kubectl get config map
and we see that there are two.
The next question is to identify
the database host from the config map
to be config.
We're going to do a kubectl describe
and use the short form for config map,
which is CM.
Then db-config is the name
of the config map.
Here, you can see information
that's in the config map.
You have the db host, the db name,
db port and what we are asked here
is to identify the db host,
which happens to be SQL 01.example.com.
Let's select that.
Now create a new config map
for the webapp-color pod
using the spec given below.
We now have to create a new config map.
We're going to do a kubectl
create config map.
Let's take a look at the help.
Here is the syntax.
I'm just showing these help commands
so you could follow the same approach
in your exams to get the commands easily.
Here, we're given the data,
which is APP_COLOR equals darkblue.
This is what needs to go
within the config map.
We don't want the "from file" option.
What we want is the "from literal" option.
So something like this,
we can use that command
and we're just going to replace
the name with webapp-config-map.
This is going to be
APP_COLOR equals darkblue.
Let's verify.
The config map is created.
You have the data, app color
and it's set to dark blue.
Let's proceed.
Now, update the environment variable
on the pod to use the newly created
config map.
Now we've got to go and update the pod.
We have to do a kubectl edit pod
webapp-color.
Here, we have the environment available.
Currently, the environment variable
is set directly as name and value here.
What we want to do is we want
to get rid of this.
We want to get the environment variables
from config map so we have to use
the envFrom syntax.
If you're not sure how that works,
we go to Kubernetes documentation
and look at config map.
Look at examples.
Here, you have configure a pod
to use a config map .
That's what basically what we want.
Here, you have a config map creation steps.
What we want to do is find out
how to use config map
as environment variables
using config map data, something like this.
You can either do it this format
where you have specified
environment variable each one,
and then you use a value from
and then specify the config map.
Or you could fit in an entire
config map itself using the envFrom.
That's what we're going to choose here.
Something like this.
We need envFrom and then configmapref.
We're going to copy that.
Here, we're going to get rid of this.
Place that here.
This should be
webapp-config-map.
Then let's go ahead and try and save that.
[?]
We're just going to exit from that.
We'll use this file to recreate.
We're going to force replace
and then pass on the file.
Let's wait for the part to be deleted
and recreate it.
Okay, so that's done.
Let's verify that it's done correctly.
Here, we see the containers,
the webapp-color
and we have the environment variables
from the config map configured here.
Let's go ahead and check our work.
That's correct.
Let's verify that it is dark blue.
Yes.
The webapp has now changed
its color to dark blue.
Okay, so that's the end of this lab.