WEBVTT

00:01.133 --> 00:01.713
In this video,

00:01.793 --> 00:05.553
we're going to go over the solution
for the lab on ReplicaSets.

00:05.633 --> 00:08.523
Let's start with the first question.

00:08.603 --> 00:11.913
The first question is,
how many pods exist on the system?

00:11.993 --> 00:16.743
Just like before,
we were on the kubectl get pods command.

00:17.153 --> 00:21.070
There are no pods at the moment,
so select zero.

00:24.473 --> 00:29.343
The next question, is how many ReplicaSets
exist on the system?

00:29.423 --> 00:31.433
We run the kubectl

00:33.923 --> 00:35.841
get ReplicaSet command.

00:39.413 --> 00:40.413
It's zero.

00:45.593 --> 00:52.433
Some changes we're made,
and let's check the ReplicaSet now.

00:52.673 --> 00:55.263
We see that there's one created.

00:55.343 --> 00:57.176
Let's just select one.

01:01.763 --> 01:06.723
Now the question is, how many pods
are desired in the new ReplicaSet?

01:06.803 --> 01:09.220
We know that from the output,

01:09.713 --> 01:14.883
the desired number of pods
in the ReplicaSet is number four.

01:14.963 --> 01:16.643
Let's select four.

01:19.913 --> 01:25.413
Now, what is the image used
to create the pods in the new ReplicaSet?

01:25.493 --> 01:31.113
We can find that out by looking
at the ReplicaSet in a bit more detail.

01:31.193 --> 01:35.343
For that we know we have to run
the kubectl describe command.

01:35.423 --> 01:41.423
We're going to run describe ReplicaSet,
and then new ReplicaSet.

01:42.263 --> 01:49.223
Hit the top key to auto-complete
the names of what you're looking for.

01:49.943 --> 01:56.903
In this output, we see the pod
template and the image that's used.

01:57.323 --> 02:00.533
It's busybox 777.

02:01.283 --> 02:02.963
That's the question.

02:05.273 --> 02:08.190
Here is the answer, so busybox 777.

02:09.893 --> 02:13.503
How many pods are ready
in the new ReplicaSet?

02:13.583 --> 02:14.673
If you look at the output here,

02:14.753 --> 02:18.873
it says the number of pods
that are ready are zero.

02:18.953 --> 02:24.620
You can also see the same kind of here,
the pod status, zero running.

02:26.303 --> 02:27.403
It is zero.

02:31.823 --> 02:35.490
Now, why do you think
the pods are not ready?

02:40.100 --> 02:43.863
We'll need to look
at one of these pods in a bit more detail.

02:43.943 --> 02:44.763
Of course, it's obvious,

02:44.843 --> 02:50.177
but I just want to show
you if you're not sure what the error is,

02:50.303 --> 02:54.303
then you've got to look
at one of these pods in a bit more detail.

02:54.383 --> 02:57.623
Let's run the kubectl describe command

02:59.903 --> 03:06.293
and look at any one of the pods
in a bit more detail.

03:09.443 --> 03:15.623
You see it's basically because it failed
to pull the image busybox 777.

03:18.293 --> 03:20.373
The repository does not exist.

03:20.453 --> 03:24.187
There's no image by the name busybox 777.

03:24.267 --> 03:25.867
That's a reason.

03:26.393 --> 03:28.073
Let's check that.

03:30.233 --> 03:35.033
Now, the question
is to delete one of the pod.

03:37.343 --> 03:38.283
Sorry.

03:38.363 --> 03:39.563
Let's clear.

03:41.213 --> 03:43.296
Run the get pods command.

03:43.553 --> 03:48.443
We've got to delete any one of these pods.

03:54.113 --> 03:56.243
Okay, so that's done.

03:59.453 --> 04:01.453
How many pods exist now?

04:03.173 --> 04:06.257
Let's run the get pods command again.

04:09.353 --> 04:14.003
We see
that there's still four parts running.

04:14.633 --> 04:18.633
Even though we deleted one,
the one that we deleted is not here,

04:18.713 --> 04:25.613
the one that starts with W-K,
but there are still four pods.

04:27.113 --> 04:28.953
That exercise was just to show

04:29.033 --> 04:33.003
that even if you delete
a pod part of ReplicaSet,

04:33.083 --> 04:35.853
it's automatically
going to recreate a new one.

04:35.933 --> 04:37.987
If you look at the age here,
you can see that

04:38.067 --> 04:42.033
the new one that was created
was just 17 seconds ago,

04:42.113 --> 04:43.487
as opposed to the other ones

04:43.567 --> 04:47.493
that have been running
for three minutes or more.

04:47.573 --> 04:51.033
Why are there still four pods
even after you deleted it?

04:51.113 --> 04:54.483
It's not because I didn't delete
it properly.

04:54.563 --> 04:56.943
It's not because you cannot delete
a pod from a ReplicaSet.

04:57.023 --> 04:59.220
It's because Replica ensures

04:59.300 --> 05:02.800
that the desired number of pods always run.

05:05.903 --> 05:08.553
The next one is to create a ReplicaSet using

05:08.633 --> 05:12.467
the replicaset definition
file located at root.

05:13.343 --> 05:16.073
Let's look at where that is.

05:16.553 --> 05:19.053
There's one here,
and there's an issue with the file,

05:19.133 --> 05:20.733
so we have to try and fix it.

05:20.813 --> 05:23.783
Let's first try to create it.

05:23.873 --> 05:28.567
Kubectl create -f /root

05:29.367 --> 05:33.023
replicaset definition 1.YAML.

05:39.503 --> 05:44.403
The error is that it's unable
to recognize this file,

05:44.483 --> 05:47.733
no matches
for kind ReplicaSet in version v1.

05:47.813 --> 05:49.683
There's something wrong here.

05:49.763 --> 05:51.920
Either the kind ReplicaSet is incorrect,

05:52.000 --> 05:54.853
or the version we want is incorrect.

05:54.933 --> 05:56.850
Let's look at the file,

06:00.863 --> 06:04.503
and we see that the API version
is v1 and kind is ReplicaSet.

06:04.583 --> 06:10.023
As we learned from the previous video,
the API version is incorrect.

06:10.103 --> 06:14.620
If you're not sure what it is,
one way to find

06:14.700 --> 06:16.773
that out is using
the kubectl explain command.

06:16.853 --> 06:20.453
Run the Kubectl explain replicaset command.

06:28.343 --> 06:30.213
Here, you can see the version.

06:30.293 --> 06:31.623
The version is supposed to be apps/v1.

06:31.703 --> 06:34.223
That's the problem.

06:35.267 --> 06:37.601
Let's go ahead and fix that.

06:45.900 --> 06:47.423
Apps/v1

06:51.833 --> 06:56.693
and let's try and do that again.

07:04.913 --> 07:06.913
It is now being created.

07:10.253 --> 07:12.503
Let's go to the next one.

07:15.773 --> 07:20.093
Next task is to fix
the issue in the second file

07:20.603 --> 07:22.353
and create the ReplicaSet.

07:22.433 --> 07:25.583
Let's try that.

07:27.967 --> 07:29.883
Let's just first try to

07:33.983 --> 07:34.983
create it.

07:37.313 --> 07:40.730
Okay, it says, "There's an invalid value.

07:40.883 --> 07:43.263
Selector does not match template labels."

07:43.343 --> 07:46.553
Let's take a look at the file here.

07:49.823 --> 07:53.823
We see the API version is app/v1,
which is correct,

07:53.903 --> 07:56.093
the kind is ReplicaSet.

07:56.303 --> 07:58.173
That also seems to be correct.

07:58.253 --> 08:00.383
The metadata is the name.

08:01.493 --> 08:06.693
Then you have the spec section,
so we have replicas, we have selector.

08:06.773 --> 08:11.607
There is something wrong here,
which is why it didn't work.

08:11.963 --> 08:13.643
Let's find that out.

08:16.823 --> 08:20.333
Here, it says, "Invalid value.

08:21.113 --> 08:24.863
Selector does not match
the template labels."

08:32.063 --> 08:36.333
Basically,
the issue here is that you have the labels

08:36.413 --> 08:39.413
specified here called tier frontend,

08:39.503 --> 08:45.253
and then the label for the pod
that the replicas will create is Nginx.

08:45.533 --> 08:47.703
These two should match, otherwise,

08:47.783 --> 08:53.033
the replica set cannot basically
manage the pod that it creates.

08:53.573 --> 08:59.273
We've got to either change
this to frontend or change this to Nginx.

08:59.903 --> 09:02.343
At the end, both of them should match.

09:02.423 --> 09:04.673
Let's change this to Nginx.

09:05.273 --> 09:06.673
Save this file

09:08.843 --> 09:10.523
and run it again.

09:12.113 --> 09:13.913
That's now created.

09:18.863 --> 09:20.946
Let's go to the next one.

09:22.223 --> 09:26.283
Now, we've got to delete
the two newly created ReplicaSets.

09:26.363 --> 09:29.780
Let's first look at the status right now.

09:29.993 --> 09:35.133
You can also run just rs instead
of ReplicaSet, which is the short form.

09:35.213 --> 09:37.473
Now we've got to delete
both of these ReplicaSets,

09:37.553 --> 09:43.943
so kubectl Delete rs replicaset one

09:46.643 --> 09:47.553
and two.

09:47.633 --> 09:51.503
You can also give multiple
in the same command.

09:54.803 --> 09:56.553
Okay, so that's done.

09:57.533 --> 10:02.950
Now, fix the original ReplicaSet
to use the correct busybox image.

10:03.983 --> 10:07.463
We know that the first one which is--

10:09.623 --> 10:10.623
We now only have one

10:10.703 --> 10:14.793
and we know that there are none
of the pods are in a ready state,

10:14.873 --> 10:20.213
and we also know
that because the image name is incorrect,

10:20.543 --> 10:21.993
so we've got to now fix that.

10:22.073 --> 10:22.923
For this,

10:23.003 --> 10:26.170
let's go with the kubectl edit command

10:26.467 --> 10:30.543
and edit the new ReplicaSet.

10:33.500 --> 10:37.493
Let's go into the container section

10:38.573 --> 10:43.103
and change the image name to just busybox.

10:44.543 --> 10:46.043
Save that file.

10:48.623 --> 10:54.543
Let's check status of pods
now and the ReplicaSet.

10:57.367 --> 10:58.967
It's still zero.

10:59.303 --> 11:03.513
Let's just give it some time
for it to delete the old pods

11:03.593 --> 11:06.843
and create new ones with the new image.

11:13.103 --> 11:15.713
Describe rs.

11:20.483 --> 11:24.873
When you update a ReplicaSet,
even though the image name is updated,

11:24.953 --> 11:28.370
the pods are not automatically recreated.

11:29.663 --> 11:33.033
You have to either delete
and recreate the entire ReplicaSet

11:33.113 --> 11:36.003
or you have to delete
all the pods so that the ReplicaSet

11:36.083 --> 11:39.500
creates new pods with the new image name.

11:40.013 --> 11:43.853
Let's go back and run kubectl get pods.

11:44.453 --> 11:48.003
You see
they're all still in the error state.

11:48.083 --> 11:51.917
We're just
going to go through and delete them.

11:58.583 --> 12:02.813
We're going to use the name for each one.

12:11.453 --> 12:15.203
Now we just wait
all of them to be terminated.

12:16.233 --> 12:18.317
Let's run get pods again.

12:23.813 --> 12:28.563
It's in the creating state,
and it's in the running state.

12:28.643 --> 12:31.653
Let's check the status
of the ReplicaSet now.

12:31.733 --> 12:35.483
You can see
that they're all in a ready state.

12:39.067 --> 12:41.150
Let's go to the next one.

12:42.173 --> 12:47.693
Now, we've got to scale
the ReplicaSet to five pods.

12:48.367 --> 12:52.343
Let's run the kubectl scale command, and

12:56.303 --> 12:59.553
specify the number of replicas to five.

13:02.393 --> 13:07.653
Let's check the status and we can see
that a new pod has been added.

13:07.733 --> 13:11.103
We can also do that using the edit command.

13:11.183 --> 13:17.513
We can do our kubectl edit rs
and specify the name of the ReplicaSet.

13:18.263 --> 13:23.963
Then go here and just change
this number to the desired number,

13:24.473 --> 13:29.807
and then save the file,
but we're not going to do that right now.

13:32.733 --> 13:33.933
That's done.

13:35.993 --> 13:41.453
Now, the task is to scale
the ReplicaSet down to two pods.

13:41.963 --> 13:43.743
This time let's use the other approach.

13:43.823 --> 13:45.991
Let's edit the ReplicaSet.

13:46.703 --> 13:51.173
Go to the number here and set it to two.

13:56.213 --> 13:57.113
Okay.

13:57.193 --> 13:58.393
Let's check.

14:01.000 --> 14:06.233
That's it for this lab,
and next we'll look at deployments.

