Skip to main content
In this lesson we’ll walk through the solution for the Services lab. You’ll learn how to inspect Services, interpret their fields (Type, ClusterIP, TargetPort, Endpoints), and create a NodePort Service to expose a Deployment.

Quick answers (at a glance)


Inspect Services

List Services in the current namespace:
This environment contains only the default kubernetes Service. The TYPE column shows this is a ClusterIP Service.

Examine Service details

Describe the Service to see detailed fields, including TargetPort, labels, and Endpoints:
From the describe output:
  • TargetPort is 6443.
  • The Service has two labels:
    • component=apiserver
    • provider=kubernetes
  • Endpoints shows 10.53.180.9:6443 — a single IP:port, so the Service currently has one endpoint.

What are Endpoints?

When a Service routes traffic to Pods, Kubernetes matches the Service selector to Pod labels. The collection of Pod IPs and ports identified by that selector are called Endpoints. If the selector matches multiple Pods, Endpoints will list each IP:port. If no Pods match, Endpoints will be empty and the Service won’t forward traffic. The following diagram illustrates a Service selecting Pods (based on labels) and creating Endpoints for them.
A blue hand-drawn diagram showing a top triangular node with arrows pointing down to four round nodes in a row. Each round node has a small inner circle and there are handwritten labels on the right reading "app: FE" and "app: FC."
Example scenarios:
  • If a Service selector is incorrect (matches no Pod labels), Endpoints will be empty and the Service will not forward traffic.
  • If a Pod accidentally has labels that match an existing Service, that Pod will become an endpoint for that Service.
In this environment the kubernetes Service has a single endpoint.

Check for Deployments

List Deployments in the default namespace:
There is one Deployment: simple-webapp-deployment. Describe the Deployment to see the Pod template and image used:
The Deployment’s container image is kodekloud/simple-webapp:red.

Is the web UI reachable?

Not yet. Attempting to access the web app UI before creating a Service results in a “Bad Gateway” or connection failure because no Service is exposing the Pods.

Create a Service to expose the web application

You can create a NodePort Service that exposes the Deployment’s Pods so the UI is reachable from a node IP and port. Example Service manifest:
Apply the Service manifest:
After creating the Service, the web application becomes reachable via the node IP and the configured NodePort, for example: http://<node-ip>:30080. Tip: if you need to test from inside the cluster, you can curl the Service ClusterIP and port or use a pod to curl the NodePort from another node.

Generate Service YAML imperatively (dry-run)

Use kubectl to generate manifests without creating resources by using --dry-run=client -o yaml. These commands print YAML you can edit and apply:
These are useful for quickly scaffolding Service manifests you can customize.
If you are unsure about the fields required in a Service manifest, consult the Kubernetes Service documentation for examples of ClusterIP, NodePort, and LoadBalancer Services.

Watch Video