Skip to main content
In this lesson we walk through the solution for the lab on Kubernetes Services. Each step shows the commands and outputs you would run in the cluster, explains the result, and demonstrates how to expose a Deployment using a Service.

1) List Services in the current namespace

Run:
Example output:
  • There is only one Service in the default namespace: the built-in Kubernetes API server Service.
  • The TYPE column shows this Service is ClusterIP.

Quick answers

2) Inspect the default Kubernetes Service (details)

Describe the Service to view port and endpoint details:
Example describe output:
  • TargetPort is 6443/TCP.
  • Endpoints show 10.53.180.9:6443, which is a single endpoint for this Service.
  • Labels are listed under Labels in the describe output.

What are Endpoints?

Endpoints are the network addresses (IP:port) of Pods that a Service routes to. Kubernetes automatically maintains Endpoints to reflect the pods matched by the Service’s selector. If no Pods match, the Endpoints list is empty; if multiple Pods match, Endpoints contains multiple entries.
Endpoints are not objects you normally edit. Kubernetes dynamically manages Endpoints to match the set of Pods selected by a Service’s selector.
Here is a simple diagram showing a Service selecting multiple Pods by label:
A simple blue hand-drawn diagram showing one triangular node at the top branching with arrows down to three round nodes (like apples) below. Handwritten annotations on the right read something like "app: FE" and "app: FC."
In the kubernetes Service example above, only one endpoint is present.

3) How many Deployments are present?

List Deployments:
Example output:
  • There is one Deployment: simple-webapp-deployment.

4) Which image does the Deployment use?

Describe the Deployment:
Example describe output:
  • Container image: kodekloud/simple-webapp:redis.
  • Container port: 8080/TCP.

5) Is the web UI accessible?

Attempting to access the app (for example via a NodePort on the node IP) produced a “Bad Gateway” error. The UI was not reachable because there was no Service routing external traffic to the Deployment’s Pods yet. You must create a Service that selects the Deployment’s Pods.

6) Create a Service to expose the web application

A NodePort Service manifest that exposes the Deployment’s Pods on port 8080 looks like this:
Save as service-definition-1.yaml and create it:
Example output:
After this Service is created, access the app using the node IP and NodePort, e.g.:
This should route traffic to the Pods on port 8080.

7) Tip: generate skeleton manifests with kubectl

You can use kubectl’s imperative commands with --dry-run=client -o yaml to produce skeleton YAML you can edit before applying. Examples:
These commands output YAML that you can modify and apply with:

References

Watch Video