>_ IzzyLab

Hands-on task

This task is step 5 of the course “Kubernetes: manifests from Namespace to RBAC”

ClusterIP Service

easy~10 min

The Kubernetes cluster in this sandbox (kubectl is already configured) runs a Deployment web: its pods serve a page on port 8080. Next to it is a Deployment client for making requests from inside the cluster. Give the web pods a stable address: prepare in /root/svc.yaml a Service of type ClusterIP named web that listens on port 80 and forwards to targetPort 8080. You don't have to write it by hand — it's easier to generate it with a kubectl command using --dry-run=client -o yaml. Look at the result in the Editor tab and apply it to the cluster: a request from client to http://web must return the page.

What you'll practise:
  • service
  • clusterip
  • kubectl
  • port and targetPort
  • dry-run
  • kubectl apply
  • endpoints

Topic breakdown

A Service in Kubernetes provides a stable access point to a set of pods, and the ClusterIP type is an internal virtual IP reachable only inside the cluster. It's important to distinguish two ports: port is the port the service itself listens on, while targetPort is the port inside the pod where the service forwards traffic; they don't have to match. Like a Deployment, a service is easier to generate with the imperative kubectl create service command and --dry-run=client -o yaml than to write by hand — kubectl sets the type and the app: <name> selector itself, and the port mapping is given by a separate flag in the port:targetPort format. Inside the cluster the service is reachable by name: the cluster DNS turns web into its ClusterIP, and traffic to port goes to the targetPort of one of the pods whose labels match the selector. If targetPort doesn't match the port the application listens on, the service will have endpoints but no answer.

What's checked

  1. Manifest is valid against the schema
  2. The file has a Service web of type ClusterIP
  3. Port 80 → targetPort 8080
  4. Service web has endpoints in the cluster
  5. client gets the page from http://web

What it looks like