WEBVTT

00:01.540 --> 00:04.640
In this video,
we will go over the practice test

00:04.720 --> 00:06.350
for imperative commands.

00:06.520 --> 00:09.030
In this lab,
we will get hands-on practice

00:09.080 --> 00:11.370
with creating Kubernetes objects
imperatively.

00:11.500 --> 00:16.760
This is more to help with your exams.

00:18.160 --> 00:20.450
You must be very familiar
with imperative commands

00:20.900 --> 00:22.560
while you're preparing for the exam.

00:24.720 --> 00:25.560
Let's proceed.

00:27.060 --> 00:31.180
The first task is to deploy
a pod named nginx-pod

00:31.250 --> 00:33.440
using the nginx:alpine image.

00:34.200 --> 00:36.000
That we've done before.

00:36.160 --> 00:36.720
It's easy.

00:36.890 --> 00:40.260
It's kubectl run to create a pod.

00:41.520 --> 00:49.820
The name is nginx-pod
and the image is nginx:alpine.

00:52.890 --> 00:53.550
Check it.

00:55.640 --> 00:58.320
That's correct.

00:58.520 --> 01:02.640
The next one, deploy a redis pod
using the redis:alpine image

01:03.050 --> 01:05.470
with the labels set to tier=db.

01:05.830 --> 01:10.550
That's the similar task
but with an additional field.

01:11.650 --> 01:13.680
If you look
at the kubectl run command,

01:14.560 --> 01:18.330
let's see if there is an option
to specify the labels.

01:19.500 --> 01:22.470
If you look at this,
there are some examples here.

01:22.680 --> 01:23.940
This is what we just did.

01:25.420 --> 01:29.340
Here, you have an option
to specify the labels,

01:29.430 --> 01:33.830
so --labels=
and then here's the key-value pairs.

01:33.890 --> 01:38.190
You can specify multiple labels
separated by a comma.

01:38.560 --> 01:40.350
We're going to use that approach.

01:42.140 --> 01:45.300
Let's run the kubectl run command.

01:47.240 --> 01:50.080
The name of the pod is redis.

01:50.720 --> 01:55.960
Image is redis:alpine.

01:58.730 --> 02:05.160
We're going to add some labels
and then the label is tier=db.

02:16.020 --> 02:17.250
That's good.

02:18.170 --> 02:21.170
The next one is to create a service

02:21.960 --> 02:25.080
called redis-service
to expose the redis application

02:25.140 --> 02:28.830
within the cluster on port 6379.

02:30.030 --> 02:31.700
The service name
has to be redis-service.

02:31.760 --> 02:34.440
The type is ClusterIP,
and the port is 6379.

02:35.480 --> 02:40.250
For this, we could run
the kubectl create service command.

02:42.390 --> 02:43.420
Let's look at the help.

02:46.160 --> 02:49.200
If it is within the cluster,
then there's cluster IP

02:49.280 --> 02:58.740
so we could run the cluster IP,
kubectl create service clusterip.

03:02.470 --> 03:03.220
Let's look at the help.

03:06.480 --> 03:08.920
Then, you specify the name

03:09.000 --> 03:17.320
of the service and the port here
which happens to be 6379.

03:20.890 --> 03:24.480
One other thing here is that
we want to expose

03:24.890 --> 03:26.690
the redis application.

03:28.160 --> 03:29.270
With this command,

03:30.040 --> 03:33.130
there is no way
to specify a selector.

03:33.680 --> 03:41.560
There is something
that we discussed in this lecture.

03:43.960 --> 03:47.140
If you look at this,
there are three ways

03:47.170 --> 03:48.880
to create a service.

03:50.270 --> 03:54.230
This is to create a service
named redis-service of ClusterIP.

03:56.120 --> 03:58.830
We could do
a kubectl create service command

03:59.350 --> 04:02.330
but then you cannot really specify
the selectors,

04:04.060 --> 04:08.320
or you could do
a kubectl expose command.

04:08.620 --> 04:12.220
Ideally, for most use cases,

04:12.360 --> 04:14.900
you could use
the kubectl expose command

04:15.480 --> 04:20.480
because it will automatically
detect the labels,

04:20.760 --> 04:23.160
and then use that as selectors
for the service.

04:24.030 --> 04:25.520
That's the most ideal.

04:25.590 --> 04:28.100
The only time you should use
kubectl create service

04:28.150 --> 04:31.560
is when you need to specify
a particular NodePort.

04:34.720 --> 04:37.230
Here you have an example
of creating a NodePort service.

04:37.690 --> 04:38.500
There are two ways to do it

04:38.650 --> 04:40.800
with the expose command
and the create service command.

04:40.910 --> 04:44.590
As of this recording,
there is no way to specify a NodePort

04:44.700 --> 04:46.870
in the command,
so you have to export that

04:46.920 --> 04:49.170
to a YAML file and edit it
before creating it,

04:49.440 --> 04:54.450
or if you go the other approach,
you cannot specify the selectors.

04:55.800 --> 04:57.220
That's the challenge here.

04:57.380 --> 04:59.630
Here, what we're going to do

04:59.670 --> 05:03.040
is we're going to use
the exposed command.

05:07.640 --> 05:12.480
If you look at the help,
these are some examples.

05:12.830 --> 05:16.850
We're going to specify expose
and the application is redis.

05:17.160 --> 05:18.970
We don't know if it's a pod
or a deployment.

05:19.040 --> 05:20.470
Let's find that out first.

05:23.460 --> 05:24.440
It's a pod.

05:24.520 --> 05:25.440
It's a redis pod.

05:25.760 --> 05:27.750
We're going to do kubectl expose.

05:28.080 --> 05:30.970
Instead of rc,
we're going to do a pod or a po.

05:33.440 --> 05:35.800
Remember that this is the name
of the pod and not the service

05:35.910 --> 05:38.320
that we want to create,
so the pod has to be redis.

05:38.920 --> 05:41.870
This should be a way
to specify the name of the service

05:41.920 --> 05:43.040
which is using name.

05:43.150 --> 05:46.370
We're going to use name
and specify it as redis-service.

05:46.440 --> 05:48.220
Of course, we also have to specify

05:48.310 --> 05:53.570
the port and the port is this one
which is 6379.

05:54.300 --> 05:56.160
That's what we are going to do.

05:57.660 --> 06:01.830
kubectl expose redis

06:03.820 --> 06:09.800
and then we're going to specify
the port which is 6379.

06:10.230 --> 06:16.740
You also need to specify a name
that will be redis-service.

06:21.260 --> 06:26.130
I missed specifying pod,
so let me put that in.

06:28.710 --> 06:29.650
Let's check it out.

06:30.780 --> 06:37.210
get service redis,
so that's the redis-service.

06:43.050 --> 06:44.570
Let's see if it's got

06:44.620 --> 06:47.560
the right labels and selectors
and also the endpoint.

06:48.130 --> 06:52.360
The labels is a tier=db,
so it's automatically picked that up.

06:53.340 --> 06:56.540
The endpoints indicates
that it's automatically

06:56.640 --> 06:58.810
discovered the pod.

07:00.420 --> 07:01.200
Let's check.

07:03.550 --> 07:04.300
That's good.

07:08.670 --> 07:09.770
The next one is to create

07:09.820 --> 07:14.260
a deployment named webapp
using the image with three replicas.

07:14.820 --> 07:21.210
We're going to do
a kubectl create deployment command,

07:22.830 --> 07:25.250
and the name of the deployment
is webapp.

07:26.660 --> 07:30.320
Image, it's going to copy and paste.

07:34.420 --> 07:41.590
Replicas is three.

07:46.620 --> 07:49.630
Oops, I forgot to specify the dashes.

07:52.790 --> 07:55.600
We're going to check.

08:10.290 --> 08:11.760
There's zero of three ready.

08:13.430 --> 08:14.430
Okay, three of three ready.

08:20.850 --> 08:25.130
The next one is to create a new pod
called custom-nginx

08:25.220 --> 08:29.800
using the nginx image
and expose it on container port 8080.

08:30.800 --> 08:34.730
We know that, to create a pod,
we have kubectl run command,

08:35.240 --> 08:38.280
and the name of the pod
is custom-nginx.

08:39.960 --> 08:43.200
The image is nginx.

08:45.930 --> 08:50.090
We have to expose it
on container port 8080.

08:51.130 --> 08:55.000
We're talking about specifying
the port on the container.

08:55.080 --> 08:58.880
We just use port
and specify the port number.

08:59.020 --> 08:59.760
We're not really talking

08:59.790 --> 09:01.720
about exposing the port
by creating a service.

09:01.910 --> 09:05.800
This is just specifying
what port the container

09:06.370 --> 09:07.290
runs the service on.

09:07.480 --> 09:09.390
You can do that with the port option.

09:11.950 --> 09:13.100
Let's check our work.

09:14.140 --> 09:14.680
That's correct.

09:16.910 --> 09:20.850
The next one is to create
a new namespace called dev-ns.

09:20.900 --> 09:23.320
That's pretty easy
and straightforward.

09:23.710 --> 09:29.510
kubectl create namespace dev-ns.

09:35.390 --> 09:36.720
The next one is to create

09:36.760 --> 09:42.250
a new deployment called redis-deploy
in the dev-ns namespace.

09:42.530 --> 09:45.760
We're going to do
kubectl create deployment

09:47.280 --> 09:51.390
and the name is redis-deploy.

09:53.140 --> 09:56.120
The image is redis.

09:57.200 --> 10:01.280
Replicas is two.

10:02.660 --> 10:05.990
You could do =2 or space 2,
either of that work.

10:08.820 --> 10:11.580
The namespace is dev-ns.

10:14.270 --> 10:18.760
Let's make sure that worked
as expected.

10:26.620 --> 10:31.340
We have the redis-deploy
within the dev-ns namespace,

10:32.240 --> 10:33.700
and it has two replicas.

10:35.360 --> 10:36.100
Let's check our work.

10:36.780 --> 10:37.610
That's correct.

10:39.620 --> 10:43.180
The final question is to create a pod

10:43.280 --> 10:47.640
called httpd using the image
httpd:alpine in the default namespace

10:48.040 --> 10:51.810
and then create a service
of type ClusterIP by the same name.

10:52.210 --> 10:55.360
The target port for the service
should be 80.

10:55.570 --> 10:58.500
I'll try to do this
with as few steps as possible.

10:58.800 --> 11:00.260
There are two ways of doing this.

11:00.330 --> 11:02.640
One is you could first

11:02.720 --> 11:10.260
do a kubectl run command
and create the pod,

11:10.380 --> 11:13.330
and then we know that we could use
the kubectl expose command

11:13.780 --> 11:17.960
to create a service
but we can actually combine them both

11:19.090 --> 11:20.280
in the run command itself.

11:22.440 --> 11:24.020
Let's first create a pod.

11:24.370 --> 11:26.410
We do a kubectl run httpd.

11:26.710 --> 11:27.790
That's the name of the pod.

11:27.950 --> 11:31.370
The image is supposed
to be httpd:alpine,

11:32.080 --> 11:35.680
and then we have a default namespace.

11:35.720 --> 11:37.550
We don't have to specify
the namespace.

11:39.410 --> 11:42.510
The target port is 80.

11:44.900 --> 11:46.960
What we're asked to do
is also create a service.

11:47.710 --> 11:51.180
One of the options
for the run command,

11:52.370 --> 11:55.330
we look into help
is the expose option.

11:56.240 --> 11:59.400
If you look right here,
it has the expose option,

11:59.660 --> 12:01.120
and it's by default set to false.

12:01.160 --> 12:02.210
If it's set to true,

12:03.680 --> 12:06.930
create a ClusterIP service
associated with the pod.

12:07.440 --> 12:09.320
It requires the pod field.

12:09.990 --> 12:15.510
It's automatically going to create
a service with the ClusterIP as type,

12:16.160 --> 12:20.650
and it's going to expose
the pod internally.

12:23.430 --> 12:25.510
That's what we have to do.

12:25.630 --> 12:33.250
We're going to use the same command
but we're going to add

12:33.410 --> 12:37.360
the expose=true option
to the end of it.

12:40.160 --> 12:42.560
It's created a pod and a service.

12:43.080 --> 12:44.110
Let's just verify that.

12:47.230 --> 12:48.840
We have the httpd pod.

12:51.150 --> 12:54.830
We have the httpd service.

12:55.710 --> 13:02.970
If we look at the service
in more detail,

13:03.610 --> 13:07.810
you see that it has got
the selector: run=httpd,

13:08.450 --> 13:14.220
and then it also has the endpoint
discovered.

13:18.280 --> 13:19.110
That's correct.

13:20.040 --> 13:23.160
That's the end of this lab.

