WEBVTT

00:02.280 --> 00:04.750
In this video, we're going to walk over

00:05.120 --> 00:08.880
the solution for the lab on services.

00:09.490 --> 00:11.160
The first question is,

00:11.570 --> 00:14.270
how many services exist on the system?

00:14.270 --> 00:18.270
We're going to run
the kubectl get service command,

00:18.540 --> 00:23.300
or you can also run
the kubectl get svc command.

00:23.300 --> 00:24.830
It's a short for service.

00:25.870 --> 00:29.070
We can see that there's just one service.

00:30.100 --> 00:31.260
Select that.

00:33.620 --> 00:36.730
This is a default service
created by Kubernetes.

00:39.450 --> 00:43.250
What is the type
of the default Kubernetes service?

00:43.440 --> 00:45.860
If you look at the type here,
we see that it's cluster IP,

00:45.860 --> 00:48.110
so let's select cluster IP.

00:49.570 --> 00:54.020
We'll look at what this service is,
in particular, later when we talk about

00:54.810 --> 00:58.370
the Kubernetes architecture,
the API server in more detail.

00:58.370 --> 01:02.160
For now, let's just consider it
as any other service.

01:02.290 --> 01:07.050
What is the targetPort configured
on the Kubernetes service?

01:07.960 --> 01:10.840
For this, you've got to look
at the service in more detail.

01:10.840 --> 01:14.970
We're going to do
a kubectl describe command,

01:15.560 --> 01:20.100
and we're going to describe
the service named Kubernetes.

01:22.340 --> 01:24.800
Here, we see the port details.

01:25.360 --> 01:27.070
The port is 443.

01:27.070 --> 01:29.230
The targetPort is 6443.

01:29.230 --> 01:33.420
The question is, what is a targetPort,
so we'll select 6443.

01:35.870 --> 01:38.450
How many labels are configured
on the Kubernetes service?

01:38.450 --> 01:42.040
If you look at this right here,
so there are two labels.

01:42.040 --> 01:45.040
Component is API server
and the provider is Kubernetes.

01:45.630 --> 01:49.000
This service is basically
the Kubernetes API server.

01:49.000 --> 01:51.650
We'll discuss more about the API server

01:51.650 --> 01:56.040
and the service specifically when
we learn about the API server in detail,

01:56.600 --> 01:59.720
and the CK, of course,
when we get to that.

01:59.720 --> 02:02.280
For now, the answer is two.

02:04.680 --> 02:05.800
The next question is,

02:05.800 --> 02:09.560
how many endpoints are attached
on the Kubernetes service?

02:09.680 --> 02:13.260
For now, we have no idea
what the service is

02:13.260 --> 02:15.440
since the service was already created.

02:15.620 --> 02:17.320
We don't really know what it is.

02:17.320 --> 02:20.140
We're exploring
and finding out more about it.

02:20.770 --> 02:24.580
One thing if we want
to look at right here and understand

02:24.580 --> 02:29.050
is how many pods
is the service directing traffic to?

02:29.050 --> 02:34.610
That's what you can see here
in the endpoints section here.

02:34.610 --> 02:38.180
Endpoints, it says,
there's one IP end port

02:38.180 --> 02:40.160
so that's one endpoint.

02:40.160 --> 02:44.080
If there are multiple ports
that the services directing traffic to,

02:44.080 --> 02:46.170
then there would be multiple ports here.

02:46.170 --> 02:48.520
Let me quickly explain what endpoints are

02:48.520 --> 02:51.370
because we have not
really discussed about endpoints.

02:51.370 --> 02:54.190
Here we have a service

02:56.450 --> 02:58.920
and three ports.

03:00.270 --> 03:02.510
What we do usually is
when we create a port,

03:02.510 --> 03:05.140
we know that it has a label to it.

03:05.800 --> 03:09.010
Let's say, for example, it's set to app

03:09.100 --> 03:12.170
and FE for frontend or something.

03:13.530 --> 03:18.010
The way that we create a service
in order to direct traffic to these ports

03:18.010 --> 03:21.400
is we provide the same labels

03:22.530 --> 03:25.010
as selectors to the service.

03:25.810 --> 03:29.650
What the service does is it identifies
all the ports with the same label

03:29.650 --> 03:33.440
and then directs traffic to those ports.

03:33.440 --> 03:36.520
Once it identifies
the port with the labels

03:36.520 --> 03:40.860
that's when the service
has these endpoints.

03:41.420 --> 03:45.310
From the perspective of a service,
endpoints are basically these,

03:45.310 --> 03:49.470
the ports,
the ports that the service has identified

03:49.880 --> 03:52.020
that is going to direct traffic to

03:52.020 --> 03:54.440
based on the selector
specified on the service

03:54.440 --> 03:56.030
and the labels on the ports.

03:56.030 --> 04:00.220
Now, when we create
a service for a set of ports,

04:00.220 --> 04:02.200
now, we might think that

04:02.360 --> 04:05.370
depending on the label
and the selector we specified,

04:05.370 --> 04:08.090
the service is going
to direct traffic to those ports,

04:08.090 --> 04:13.380
but it might be possible
that we have another port

04:13.470 --> 04:17.660
which we accidentally created
with the same kind of label.

04:18.480 --> 04:21.600
The service is then going
to direct traffic to that port as well.

04:22.100 --> 04:27.230
That's when when we look at the output
of the kubectl describe command

04:27.900 --> 04:31.660
that we can identify
the additional endpoints

04:31.820 --> 04:35.780
apart from what we thought
we had configured.

04:36.810 --> 04:39.370
When look at the kubectl
described command for the service,

04:39.370 --> 04:41.370
we're going to see
that there are four endpoints.

04:42.110 --> 04:45.210
In fact, our application

04:46.440 --> 04:50.140
had a replica set
perhaps that just had three endpoints

04:50.140 --> 04:51.640
that are three ports.

04:51.640 --> 04:56.670
That's where the endpoint can help.

04:58.680 --> 05:02.370
Just to just to give you a bit context,
let's say we create--

05:02.370 --> 05:05.980
We have a single pod,
and we create a service.

05:05.980 --> 05:09.840
We set a label to FE,

05:09.950 --> 05:15.730
but we accidentally
set the selector to say FR,

05:15.730 --> 05:17.150
something that's different.

05:17.260 --> 05:20.280
Then when we try to access the service,

05:20.840 --> 05:23.710
we're not able
to get through to the application.

05:23.710 --> 05:28.110
That's when you look
at the description of the service

05:28.110 --> 05:30.920
and you realize
that the endpoints are zero.

05:31.230 --> 05:34.440
That means the service
has not identified any ports.

05:35.710 --> 05:39.050
Then that's when we can look
at the labels and selectors

05:39.050 --> 05:43.210
in more detail to identify the root cause.

05:44.600 --> 05:45.740
That's what endpoints are.

05:47.540 --> 05:50.140
It's a specification of all the ports

05:50.680 --> 05:52.670
that that particular service
has identified

05:52.670 --> 05:56.410
based on the selectors
and the labels set on those ports.

05:57.390 --> 05:58.860
In this case,

05:59.710 --> 06:04.000
this particular run service
has just one endpoint.

06:04.000 --> 06:06.080
We're going to select one here.

06:12.690 --> 06:16.090
The next question is how many deployments
exist on the system now

06:16.090 --> 06:18.110
in the current(default) namespace?

06:19.020 --> 06:25.520
Let's identify deploy.

06:25.650 --> 06:28.270
There's just one deployment,
so we're going to select one.

06:30.660 --> 06:31.810
The next question is,

06:31.810 --> 06:34.670
what is the image used
to create the pods in the deployment?

06:34.670 --> 06:36.010
We're going to look

06:38.850 --> 06:41.540
at the deployment in a bit more detail.

06:43.720 --> 06:47.610
We see the image is
kodekloud/simple-webapp:red.

06:47.720 --> 06:49.050
That's this one.

06:52.280 --> 06:54.690
Are you able to access the Web App UI?

06:54.690 --> 06:58.560
Try accessing the Web Application UI
using the tab at the top.

06:58.560 --> 07:01.130
There's the link here and click on it,

07:01.130 --> 07:04.030
we see that it gives us
a bad gateway error.

07:04.730 --> 07:07.760
The answer is no,
we're not able to access the web app UI.

07:11.340 --> 07:13.100
That's really because there's no service.

07:13.100 --> 07:16.530
We have to create a new service
to access the web application

07:16.530 --> 07:19.740
using the service-definition-1.yaml file.

07:19.930 --> 07:23.330
There is a service
definition-1.yaml file here.

07:24.440 --> 07:25.410
We look at it.

07:25.410 --> 07:29.690
This is, basically,
a kind of file with the basic framework

07:29.690 --> 07:31.280
to create a service.

07:32.240 --> 07:34.040
We will use that

07:34.600 --> 07:37.660
and update the details
that are given here.

07:38.320 --> 07:40.670
We're going to give it a name.

07:40.670 --> 07:43.490
Set the NodePort
and all the different ports,

07:43.490 --> 07:45.520
and also specify the selector.

07:46.340 --> 07:50.820
Now, if you're not sure
about getting this framework,

07:50.820 --> 07:53.720
you could go
to the Kubernetes documentation pages,

07:54.010 --> 07:57.620
search for service, and select service.

07:57.950 --> 08:03.880
Here, you get a sample
that you can then copy and use.

08:05.290 --> 08:08.760
We will talk about
imperative ways or commands

08:08.760 --> 08:11.920
to create service
in the upcoming lectures.

08:11.920 --> 08:13.960
For now, let's just go with this.

08:13.960 --> 08:17.370
The name is web app-service.

08:18.750 --> 08:21.300
Type is NodePort.

08:25.020 --> 08:28.190
TargetPort is 8080.

08:28.840 --> 08:30.840
Port is 8080,

08:32.930 --> 08:35.570
nodePort is 30080,

08:36.410 --> 08:40.080
and the selector name is simple-webapp.

08:42.250 --> 08:45.960
Let's create that service.

08:52.580 --> 08:53.980
That's done.

08:54.120 --> 08:55.170
Let's check.

08:57.970 --> 09:00.830
Let's try to access this now.

09:02.640 --> 09:03.970
That's working.

09:06.500 --> 09:11.390
As I said, in the upcoming lectures,

09:11.640 --> 09:15.380
there is a section where
we talk about imperative commands,

09:15.530 --> 09:19.090
and we'll discuss
how we can create a service.

09:19.090 --> 09:20.680
There are different ways
of creating a service

09:20.680 --> 09:23.780
and we'll discuss that when we get there.

09:24.570 --> 09:26.760
For now, that's the end of this lab.

