In this video, we're going to walk over
the solution for the lab on services.
The first question is,
how many services exist on the system?
We're going to run the kubectl get service command,
or you can also run the kubectl get svc command.
It's a short for service.
We can see that there's just one service.
Select that.
This is a default service created by Kubernetes.
What is the type of the default Kubernetes service?
If you look at the type here, we see that it's cluster IP,
so let's select cluster IP.
We'll look at what this service is, in particular, later when we talk about
the Kubernetes architecture, the API server in more detail.
For now, let's just consider it as any other service.
What is the targetPort configured on the Kubernetes service?
For this, you've got to look at the service in more detail.
We're going to do a kubectl describe command,
and we're going to describe the service named Kubernetes.
Here, we see the port details.
The port is 443.
The targetPort is 6443.
The question is, what is a targetPort, so we'll select 6443.
How many labels are configured on the Kubernetes service?
If you look at this right here, so there are two labels.
Component is API server and the provider is Kubernetes.
This service is basically the Kubernetes API server.
We'll discuss more about the API server
and the service specifically when we learn about the API server in detail,
and the CK, of course, when we get to that.
For now, the answer is two.
The next question is,
how many endpoints are attached on the Kubernetes service?
For now, we have no idea what the service is
since the service was already created.
We don't really know what it is.
We're exploring and finding out more about it.
One thing if we want to look at right here and understand
is how many pods is the service directing traffic to?
That's what you can see here in the endpoints section here.
Endpoints, it says, there's one IP end port
so that's one endpoint.
If there are multiple ports that the services directing traffic to,
then there would be multiple ports here.
Let me quickly explain what endpoints are
because we have not really discussed about endpoints.
Here we have a service
and three ports.
What we do usually is when we create a port,
we know that it has a label to it.
Let's say, for example, it's set to app
and FE for frontend or something.
The way that we create a service in order to direct traffic to these ports
is we provide the same labels
as selectors to the service.
What the service does is it identifies all the ports with the same label
and then directs traffic to those ports.
Once it identifies the port with the labels
that's when the service has these endpoints.
From the perspective of a service, endpoints are basically these,
the ports, the ports that the service has identified
that is going to direct traffic to
based on the selector specified on the service
and the labels on the ports.
Now, when we create a service for a set of ports,
now, we might think that
depending on the label and the selector we specified,
the service is going to direct traffic to those ports,
but it might be possible that we have another port
which we accidentally created with the same kind of label.
The service is then going to direct traffic to that port as well.
That's when when we look at the output of the kubectl describe command
that we can identify the additional endpoints
apart from what we thought we had configured.
When look at the kubectl described command for the service,
we're going to see that there are four endpoints.
In fact, our application
had a replica set perhaps that just had three endpoints
that are three ports.
That's where the endpoint can help.
Just to just to give you a bit context, let's say we create--
We have a single pod, and we create a service.
We set a label to FE,
but we accidentally set the selector to say FR,
something that's different.
Then when we try to access the service,
we're not able to get through to the application.
That's when you look at the description of the service
and you realize that the endpoints are zero.
That means the service has not identified any ports.
Then that's when we can look at the labels and selectors
in more detail to identify the root cause.
That's what endpoints are.
It's a specification of all the ports
that that particular service has identified
based on the selectors and the labels set on those ports.
In this case,
this particular run service has just one endpoint.
We're going to select one here.
The next question is how many deployments exist on the system now
in the current(default) namespace?
Let's identify deploy.
There's just one deployment, so we're going to select one.
The next question is,
what is the image used to create the pods in the deployment?
We're going to look
at the deployment in a bit more detail.
We see the image is kodekloud/simple-webapp:red.
That's this one.
Are you able to access the Web App UI?
Try accessing the Web Application UI using the tab at the top.
There's the link here and click on it,
we see that it gives us a bad gateway error.
The answer is no, we're not able to access the web app UI.
That's really because there's no service.
We have to create a new service to access the web application
using the service-definition-1.yaml file.
There is a service definition-1.yaml file here.
We look at it.
This is, basically, a kind of file with the basic framework
to create a service.
We will use that
and update the details that are given here.
We're going to give it a name.
Set the NodePort and all the different ports,
and also specify the selector.
Now, if you're not sure about getting this framework,
you could go to the Kubernetes documentation pages,
search for service, and select service.
Here, you get a sample that you can then copy and use.
We will talk about imperative ways or commands
to create service in the upcoming lectures.
For now, let's just go with this.
The name is web app-service.
Type is NodePort.
TargetPort is 8080.
Port is 8080,
nodePort is 30080,
and the selector name is simple-webapp.
Let's create that service.
That's done.
Let's check.
Let's try to access this now.
That's working.
As I said, in the upcoming lectures,
there is a section where we talk about imperative commands,
and we'll discuss how we can create a service.
There are different ways of creating a service
and we'll discuss that when we get there.
For now, that's the end of this lab.