Listing Kubernetes Services
To determine how many services exist on the system, run the following commands:The default service is automatically created by Kubernetes and represents the API server.
Checking the Service Type
From the output, you can observe that the service type is ClusterIP:Determining the Target Port
Next, we determine the target port configured on the Kubernetes service by using thekubectl describe command:
Examining Service Labels
Review the labels configured on the Kubernetes service by examining its description. You will see two labels:- component: apiserver
- provider: kubernetes
Inspecting Service Endpoints
Endpoints represent the Pod IPs where the service directs traffic. To inspect them, run:Understanding Endpoints
Endpoints are dynamically determined based on the labels and selectors defined in a service specification. When a service is created, it monitors Pods that match its specified selector. If there is a misconfiguration, the service could unintentionally attach extra endpoints, or conversely, none at all if labels are mismatched. In our example, the service directs traffic to a single endpoint.Exploring Deployments
Next, let’s examine the deployments in the default namespace.Counting Deployments
List the deployments with:Checking the Container Image
To verify the container image used within the deployment, inspect the deployment details:kodekloud/simple-webapp:red.
Accessing the Web Application UI
Attempting to access the web application UI may result in a “bad gateway” error. This occurs because there is no service defined to expose the web application.Without a proper service configuration, your web application will remain inaccessible externally.
Creating a Service for the Web Application
Below is a template for a service definition:- Name:
webapp-service - Type:
NodePort - Port:
8080 - TargetPort:
8080 - NodePort:
30080 - Selector:
name: simple-webapp
service-definition-1.yaml), verify the file content:
Visualizing Service Endpoints
For a better understanding of how services direct traffic to Pods, consider the following hand-drawn diagram. It illustrates a service directing traffic to three distinct Pods labeled “app: FE” and “app: FG”: