⚡ ~/naveed K8s Hub
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
Phase 1 — Fundamentals Module 03 of 24 Free & Open Access

Kubernetes Services & Cluster Networking Basics

A Kubernetes Service gives a changing set of Pods one stable virtual IP and DNS name. kube-proxy and CoreDNS make that work across the ClusterIP, NodePort and LoadBalancer types. This module shows how traffic finds Pods and how to debug a Service that has no endpoints.

Last updated: · By Naveed Ahmed, Certified Kubernetes Administrator

03 - Services & Cluster Networking Basics

Why this matters

Pods are ephemeral and get new IPs constantly. Services give you a stable way to reach a set of pods. This is the #1 source of "why can't my app talk to X" debugging.

Read this first — Definitions & Explanations

Why Services exist

Pods are mortal — they die, get rescheduled, change IPs. A Service gives a stable virtual IP (ClusterIP) and DNS name that fronts a set of Pods selected by labels.

ClusterIP

Default Service type. Reachable inside the cluster only. Other Pods call my-svc.my-ns.svc.cluster.local.

NodePort

Exposes the Service on a static port on each node’s IP. Useful for labs/demos; less common as a public production entry by itself.

LoadBalancer

Cloud providers allocate an external load balancer that fronts the Service. On bare minikube this may be emulated (e.g. tunnel/metallb patterns depending on setup).

ExternalName

Maps a Service name to an external DNS name (CNAME-style). No proxying of Pods — just DNS aliasing.

Headless Service (clusterIP: None)

No virtual ClusterIP. DNS returns Pod IPs directly. Common with StatefulSets when clients need to address individual Pods.

Endpoints / EndpointSlices

Track which Pod IPs/ports are currently valid backends for a Service. Ready Pods appear here; not-ready Pods usually do not receive traffic.

kube-proxy’s role

Implements Service routing on nodes so packets to a Service IP get forwarded to an endpoint Pod. Modes: iptables (common) or IPVS (better at huge Service scale).

Label selectors

Services find Pods with matching labels (app=web). If labels don’t match, the Service has no endpoints — traffic goes nowhere.

Official docs (read for detail)

Key Concepts

YouTube search terms

Hands-on lab (on prod-sim)

kubectl create deployment web --image=nginx --replicas=3
kubectl expose deployment web --port=80 --type=ClusterIP
kubectl get svc web
kubectl get endpointslices -l kubernetes.io/service-name=web

# Prove DNS resolution works cluster-internally
kubectl run tmp --rm -it --image=busybox --restart=Never -- \
  sh -c "nslookup web.default.svc.cluster.local; wget -qO- web"

# Watch iptables rules kube-proxy generated for this Service (on any node)
minikube ssh -p prod-sim
  sudo iptables -t nat -L | grep -A5 web
  exit

# NodePort — reach the service from outside the cluster network via node IP
kubectl expose deployment web --port=80 --type=NodePort --name=web-nodeport
kubectl get svc web-nodeport   # note the NodePort e.g. 30xxx
minikube ip -p prod-sim
curl http://$(minikube ip -p prod-sim):<nodeport>

# Break the selector on purpose and watch endpoints go empty
kubectl patch svc web -p '{"spec":{"selector":{"app":"doesnotexist"}}}'
kubectl get endpointslices -l kubernetes.io/service-name=web   # empty now
kubectl patch svc web -p '{"spec":{"selector":{"app":"web"}}}'  # fix it back

Common mistakes and how to avoid them

  • Using a selector that does not match the Pod labels. The Service ends up with no endpoints and traffic goes nowhere. Compare the Service selector with kubectl get pods --show-labels.
  • Confusing port, targetPort and nodePort. port is what the Service listens on, targetPort is the container port, and nodePort is opened on every node. A wrong targetPort gives connection refused.
  • Exposing every service as type LoadBalancer. Each one provisions a cloud load balancer and adds cost. Keep internal services on ClusterIP and put an Ingress in front of HTTP services.
  • Relying on Pod IPs. They change whenever a Pod is replaced. Connect through the Service name, which CoreDNS resolves to a stable cluster IP.
  • Forgetting the namespace in DNS names. Inside one namespace db works. Across namespaces use db.NAMESPACE or the full db.NAMESPACE.svc.cluster.local.

Quick answers

What are the Service types in Kubernetes?

ClusterIP exposes the Service on an internal virtual IP and is the default. NodePort opens a port on every node. LoadBalancer asks the cloud provider for an external load balancer. ExternalName returns a DNS alias, and a headless Service, with clusterIP: None, returns Pod IPs directly.

How does a Pod reach a Service by name?

CoreDNS resolves service.namespace.svc.cluster.local to the Service's cluster IP. kube-proxy on each node then forwards traffic sent to that IP to one of the healthy backend Pods listed in the Service's EndpointSlices. Inside the same namespace the short name alone is enough.

Why does my Service have no endpoints?

Its selector matches no Ready Pods. Either the labels differ, the Pods are in another namespace, or readiness probes are failing. Check kubectl get endpoints NAME, then compare the Service selector with kubectl get pods --show-labels.

Notes

(fill in your own words after watching + labbing)

📋 Self-Assessment Mastery Checklist (4 Competencies)
🧠 Practice Exam Questions (Module 03 MCQs)
⚡ Take Quiz & Save Progress in Tracker

Review these sample exam questions out loud, test your retrieval, and then unlock official scoring in the interactive tracker.

Question 1: A ClusterIP Service provides:
  • A. Public internet access by default
  • B. Stable virtual IP reachable inside the cluster
  • C. Node filesystem mounts
  • D. TLS certificates
✓ Correct Answer: B (Stable virtual IP reachable inside the cluster)
Option B ('Stable virtual IP reachable inside the cluster') is the standard production architectural best practice.
Question 2: Which Service type exposes the Service on each Node's IP at a static port?
  • A. ClusterIP
  • B. NodePort
  • C. ExternalName
  • D. Headless only
✓ Correct Answer: B (NodePort)
Option B ('NodePort') is the standard production architectural best practice.
Question 3: kube-proxy's role in Services is to:
  • A. Store Service objects in etcd
  • B. Program packet forwarding to endpoints
  • C. Schedule Pods
  • D. Issue API tokens
✓ Correct Answer: B (Program packet forwarding to endpoints)
Option B ('Program packet forwarding to endpoints') is the standard production architectural best practice.
Question 4: A Headless Service (clusterIP: None) is often used for:
  • A. DNS-based discovery of Pod IPs
  • B. Replacing Ingress
  • C. Node upgrades
  • D. etcd encryption
✓ Correct Answer: A (DNS-based discovery of Pod IPs)
Option A ('DNS-based discovery of Pod IPs') is the standard production architectural best practice.
Question 5: Endpoints / EndpointSlices track:
  • A. Nodes only
  • B. Ready backend Pods for a Service
  • C. ConfigMap keys
  • D. PVC claims
✓ Correct Answer: B (Ready backend Pods for a Service)
Option B ('Ready backend Pods for a Service') is the standard production architectural best practice.
← Previous Module (02) Pods & Workload Controllers Next Module (04) → ConfigMaps & Secrets