WEBVTT

00:00.678 --> 00:03.505
Let's go over the lab

00:03.505 --> 00:05.151
for environment variables.

00:05.544 --> 00:07.163
The first question is how many pods

00:07.163 --> 00:08.404
exist on the system?

00:10.800 --> 00:12.836
You see that there's just one pod.

00:15.769 --> 00:17.318
Now, what is the environment variable

00:17.318 --> 00:20.681
name set on the container in the pod?

00:21.020 --> 00:24.063
Let's take a closer look at the pod.

00:32.744 --> 00:35.185
Here, we see the environment variable

00:35.229 --> 00:38.004
is defined here and it's app color set to pink,

00:38.004 --> 00:39.878
so it's APP_COLOR.

00:43.784 --> 00:44.727
Now, what is the value set

00:44.727 --> 00:46.850
on the environment variable APP_COLOR?

00:46.967 --> 00:48.349
It is pink.

00:52.608 --> 00:54.373
Now view the web application UI

00:54.373 --> 00:56.007
by clicking on the web APP_COLOR,

00:56.150 --> 00:57.343
the pink here.

00:57.624 --> 00:58.780
Clicking on this opens up

00:58.780 --> 00:59.626
the web application

00:59.626 --> 01:03.563
and it is indeed pink in color.

01:06.126 --> 01:07.510
Now update the environment variable

01:07.510 --> 01:10.412
on the pod to display a green background

01:10.606 --> 01:13.008
and delete and recreate the pod required.

01:14.943 --> 01:19.968
We are going to do a kubectl edit pod

01:20.821 --> 01:26.596
and webapp-color pod.

01:26.930 --> 01:29.951
Now we know that it may not allow us--

01:30.067 --> 01:31.243
of course, it's not going to allow us

01:31.243 --> 01:34.802
to edit this on the pod,

01:35.992 --> 01:36.833
but we don't really care

01:36.833 --> 01:39.071
because we just need the edited

01:39.088 --> 01:41.610
or updated manifest file that we can

01:41.619 --> 01:43.460
then use to replace the pod.

01:44.356 --> 01:47.343
I'm just going to set it to green here

01:47.369 --> 01:50.232
and try and save, but it's going to come back

01:50.232 --> 01:52.693
saying it's forbidden, which is fine.

01:52.899 --> 01:54.734
Just going to exit out of that

01:55.224 --> 01:57.200
but here we have the file,

01:58.589 --> 02:00.744
which has our edits.

02:01.854 --> 02:02.741
If you look at it,

02:02.775 --> 02:04.215
you have the value green here.

02:04.494 --> 02:10.235
Let's use that to replace with force

02:10.453 --> 02:15.333
to kill the existing pod.

02:16.123 --> 02:18.482
Let's run that and wait for that pod

02:19.440 --> 02:20.480
to be deleted

02:22.746 --> 02:25.192
and the new pod to be created.

02:29.665 --> 02:30.991
Let's check the work.

02:31.920 --> 02:32.921
That's done.

02:33.503 --> 02:36.746
Let's click on the link here

02:36.746 --> 02:39.372
and we see that it is green.

02:40.487 --> 02:41.663
Let's proceed.

02:45.224 --> 02:47.740
The next question is about config maps.

02:48.000 --> 02:50.198
How many config maps exist

02:50.305 --> 02:51.585
in the default namespace?

02:56.538 --> 03:00.392
We're going to do a kubectl get config map

03:02.654 --> 03:05.750
and we see that there are two.

03:10.756 --> 03:12.300
The next question is to identify

03:12.300 --> 03:14.414
the database host from the config map

03:14.603 --> 03:15.389
to be config.

03:15.389 --> 03:19.076
We're going to do a kubectl describe

03:19.464 --> 03:21.648
and use the short form for config map,

03:21.648 --> 03:22.637
which is CM.

03:23.044 --> 03:26.334
Then db-config is the name

03:26.334 --> 03:27.170
of the config map.

03:27.270 --> 03:29.721
Here, you can see information

03:29.721 --> 03:31.112
that's in the config map.

03:31.112 --> 03:33.464
You have the db host, the db name,

03:33.624 --> 03:36.033
db port and what we are asked here

03:36.033 --> 03:37.454
is to identify the db host,

03:37.454 --> 03:39.970
which happens to be SQL 01.example.com.

03:40.979 --> 03:42.113
Let's select that.

03:44.227 --> 03:45.563
Now create a new config map

03:45.563 --> 03:47.527
for the webapp-color pod

03:47.740 --> 03:49.452
using the spec given below.

03:49.983 --> 03:52.140
We now have to create a new config map.

03:52.266 --> 03:53.820
We're going to do a kubectl

03:53.922 --> 03:56.080
create config map.

03:56.550 --> 03:58.327
Let's take a look at the help.

03:59.488 --> 04:01.246
Here is the syntax.

04:01.917 --> 04:03.745
I'm just showing these help commands

04:03.776 --> 04:07.524
so you could follow the same approach

04:07.597 --> 04:12.339
in your exams to get the commands easily.

04:12.955 --> 04:14.535
Here, we're given the data,

04:14.535 --> 04:16.545
which is APP_COLOR equals darkblue.

04:16.545 --> 04:17.878
This is what needs to go

04:17.910 --> 04:19.086
within the config map.

04:19.481 --> 04:22.727
We don't want the "from file" option.

04:22.727 --> 04:24.492
What we want is the "from literal" option.

04:24.492 --> 04:25.910
So something like this,

04:26.753 --> 04:28.176
we can use that command

04:31.464 --> 04:33.883
and we're just going to replace

04:34.732 --> 04:41.105
the name with webapp-config-map.

04:45.241 --> 04:46.846
This is going to be

04:50.598 --> 04:52.361
APP_COLOR equals darkblue.

04:53.369 --> 04:54.404
Let's verify.

05:02.193 --> 05:04.009
The config map is created.

05:04.360 --> 05:07.018
You have the data, app color

05:07.161 --> 05:08.310
and it's set to dark blue.

05:12.412 --> 05:13.323
Let's proceed.

05:13.696 --> 05:15.229
Now, update the environment variable

05:15.229 --> 05:17.107
on the pod to use the newly created

05:17.107 --> 05:17.944
config map.

05:18.465 --> 05:21.934
Now we've got to go and update the pod.

05:21.934 --> 05:25.544
We have to do a kubectl edit pod

05:26.773 --> 05:28.329
webapp-color.

05:33.330 --> 05:34.853
Here, we have the environment available.

05:35.132 --> 05:36.933
Currently, the environment variable

05:36.962 --> 05:40.901
is set directly as name and value here.

05:41.127 --> 05:42.419
What we want to do is we want

05:42.499 --> 05:43.490
to get rid of this.

05:43.786 --> 05:46.589
We want to get the environment variables

05:46.649 --> 05:48.952
from config map so we have to use

05:48.952 --> 05:53.820
the envFrom syntax.

05:54.606 --> 05:56.533
If you're not sure how that works,

05:56.698 --> 06:00.863
we go to Kubernetes documentation

06:02.096 --> 06:04.307
and look at config map.

06:09.112 --> 06:10.484
Look at examples.

06:20.979 --> 06:23.970
Here, you have configure a pod

06:23.970 --> 06:25.059
to use a config map .

06:25.408 --> 06:27.136
That's what basically what we want.

06:35.718 --> 06:38.790
Here, you have a config map creation steps.

06:40.324 --> 06:43.083
What we want to do is find out

06:43.699 --> 06:46.278
how to use config map

06:46.278 --> 06:47.847
as environment variables

06:49.517 --> 06:52.179
using config map data, something like this.

06:54.002 --> 06:57.389
You can either do it this format

06:57.389 --> 06:59.129
where you have specified

06:59.129 --> 07:00.960
environment variable each one,

07:00.960 --> 07:02.065
and then you use a value from

07:02.065 --> 07:03.675
and then specify the config map.

07:04.203 --> 07:05.873
Or you could fit in an entire

07:05.903 --> 07:09.801
config map itself  using the envFrom.

07:09.801 --> 07:13.202
That's what we're going to choose here.

07:13.202 --> 07:14.336
Something like this.

07:15.842 --> 07:21.376
We need envFrom and then configmapref.

07:21.401 --> 07:22.499
We're going to copy that.

07:26.412 --> 07:28.892
Here, we're going to get rid of this.

07:33.532 --> 07:34.392
Place that here.

07:36.695 --> 07:39.216
This should be

07:43.310 --> 07:47.413
webapp-config-map.

07:49.515 --> 07:51.747
Then let's go ahead and try and save that.

07:52.516 --> 07:53.275
[?]

07:53.284 --> 07:55.498
We're just going to exit from that.

07:56.203 --> 08:02.237
We'll use this file to recreate.

08:04.167 --> 08:05.500
We're going to force replace

08:06.346 --> 08:07.626
and then pass on the file.

08:11.248 --> 08:13.052
Let's wait for the part to be deleted

08:13.052 --> 08:14.751
and recreate it.

08:17.100 --> 08:18.545
Okay, so that's done.

08:19.015 --> 08:23.248
Let's verify that it's done correctly.

08:29.330 --> 08:31.534
Here, we see the containers,

08:31.563 --> 08:33.025
the webapp-color

08:33.025 --> 08:34.841
and we have the environment variables

08:35.202 --> 08:38.676
from the config map configured here.

08:41.435 --> 08:43.789
Let's go ahead and check our work.

08:44.349 --> 08:46.252
That's correct.

08:46.732 --> 08:51.393
Let's verify that it is dark blue.

08:51.762 --> 08:52.286
Yes.

08:52.480 --> 08:54.208
The webapp has now changed

08:54.208 --> 08:55.944
its color to dark blue.

08:56.603 --> 08:59.115
Okay, so that's the end of this lab.

