study.

Send HTTP Requests through a Service Name · Kubernetes

Use a stable service name instead of changing Pod IPs.

← Kubernetes

Learn with progress and quizzes

First, understand the concepts.

Selecting targets

A Service selector must match Pod labels. Matching a Deployment name alone does not connect a backend.

ClusterIP and DNS

ClusterIP provides an internal access point. A client in the same namespace can resolve a short name such as web.

Inspect real backends

EndpointSlices show backend addresses and readiness. If resolution succeeds but requests fail, investigate backends and ports separately.

Why it matters

Hard-coding Pod IPs requires updating clients after replacements. A Service name provides a stable entry point in front of changing backends.

Work through the reasoning

Trace name to backend

The client resolves a Service name and contacts its address. Matching, ready Pods normally form the backends. Inspect EndpointSlices to see addresses selected at that moment.

Verify an actual response

The lab sends HTTP from a client Pod in the same namespace. Record Service existence separately from receiving HTML; the latter exercises more of the request path.

Learn by doing.

Use kubectl, a personal practice Kubernetes cluster, and a POSIX shell. Check the context and use the dedicated namespace in each lab. Cleanup deletes all resources in that practice namespace.

Create a web Deployment and Service, then request it from a temporary BusyBox Pod. Start the client after the Service exists.

kubectl config current-context
kubectl create namespace study-k8s-service --dry-run=client -o yaml | kubectl apply -f -
kubectl create deployment web --image=nginx:stable-alpine -n study-k8s-service --dry-run=client -o yaml | kubectl apply -f -
kubectl rollout status deployment/web -n study-k8s-service --timeout=120s
kubectl expose deployment web --port=80 --target-port=80 -n study-k8s-service --dry-run=client -o yaml | kubectl apply -f -
kubectl run client --image=busybox:1.36 --restart=Never -n study-k8s-service --command -- wget -qO- http://web
kubectl wait --for=jsonpath='{.status.phase}'=Succeeded pod/client -n study-k8s-service --timeout=90s
kubectl logs client -n study-k8s-service
kubectl get endpointslices -n study-k8s-service -l kubernetes.io/service-name=web
kubectl get pods -n study-k8s-service -o wide

How to check your result

Expect nginx HTML. Compare EndpointSlice addresses with Pod IPs. For DNS errors investigate cluster DNS; for connection failures inspect selectors, readiness, and targetPort.

Clean up practice resources

Run after checking the result. Confirm these resources belong to your practice run and contain no data you need to keep.

kubectl delete namespace study-k8s-service

Apply what you learned

A replacement Pod gets a new IP. What stays in client configuration and what should you observe?

Reveal the reasoning after trying

Keep the Service name and port. Observe backend address changes and readiness in EndpointSlices, and confirm the new Pod’s labels still match. Avoid manually embedding the replacement IP in clients.

Ready to check your understanding?

What primarily connects Pods to a Service?

  1. Matching Service and Pod names
  2. A selector matching Pod labels
  3. A Service name in Pod logs
  4. An image tagged latest
Reveal the reasoning after trying

A selector matching Pod labels

The selector chooses matching Pods by label. Readiness and port configuration must also allow requests.

Official documentation · Send HTTP Requests through a Service Name