Appearance

DNS and service exposure

Find a Service by name inside Kubernetes and choose how callers outside the cluster can connect.

What you will understand

  • Read a client Pod’s DNS search domains and resolve a Service in its namespace.
  • Connect the front door of a ClusterIP, NodePort, or LoadBalancer Service to the intended caller.
  • Recognize what a port-forward proves when diagnosing a backend.

Builds on: Services and EndpointSlices

Which callers can resolve a Service name

The catalog frontend can reach service-demo from a Pod, but typing the same name on your laptop does not open the catalog. Those callers are in different networks and use different DNS settings. Service DNS gives clients inside the cluster a name for a Service. A typical fully qualified name is service-demo.default.svc.cluster.local, with the Service name, namespace, and configured cluster domain. From the same namespace, a client can usually use service-demo because the Pod’s resolver searches there.

A normal ClusterIP Service resolves to its cluster IP. Once your client knows the address, it still needs a viable network path, the right port, and a ready backend. Switch the caller in the scene to see how the same Service name is treated from inside and outside the cluster.

Resolve service-demo before opening a connection

The caller’s namespace and DNS search rules determine what a short Service name resolves to.

  1. Client PodResolve the short name
    Cluster DNSThe resolver tries the caller’s namespace using its search settings.
  2. Cluster DNSReturn the Service address
    Client PodThe client learns the virtual IP of the Service.
  3. Client PodConnect to the Service port
    Ready backendDNS lookup is finished. Node forwarding takes the connection to the selected endpoint.
Follow the sequence

The caller’s namespace and DNS search rules determine what a short Service name resolves to.

The diagram uses the common cluster.local domain for illustration; the actual cluster domain is configurable.

Inspect the DNS lookup

A client in kv-lab looks up the short Service name m06. Follow the DNS answer, then retry the request after the Service selector stops matching.

1 / 6

From Pod resolverTo CoreDNS

Expand the short Service name

The client asks for m06. Its resolver tries the namespace search suffix kv-lab.svc.cluster.local and sends the resulting DNS query to CoreDNS.

Name being looked up
Before
m06
After
m06.kv-lab.svc.cluster.local.
Expand the short Service name

The client asks for m06. Its resolver tries the namespace search suffix kv-lab.svc.cluster.local and sends the resulting DNS query to CoreDNS.

Uses the lab’s names and an illustrative IPv4 ClusterIP. The Pod uses the standard cluster DNS search list. DNS caching and packet forwarding implementation details are omitted.

When nslookup returns the expected Service IP but HTTP fails, what should you check next?
Reveal prediction answer

Check the Service port and target port, then compare its selector with the Pod labels and read its EndpointSlices for eligible addresses.

Run nslookup and an HTTP request from the same client Pod before and after repairing the selector.

Compare DNS and HTTP in the Service lab
Explore another case

Open Inspect the DNS lookup to follow a short name from the client’s DNS search list to CoreDNS and then trace the connection to a backend. The final step shows which part breaks when the Service selector stops matching.

Check DNS from a client Pod

Use the service-demo Service and Deployment from the previous lesson. The client created here stays running long enough to execute several commands. Inside it, /etc/resolv.conf shows the search suffixes and the resolver address. Compare the result of nslookup with wget. A DNS answer tells you the name resolved. A successful HTTP response proves that the connection also reached a backend that could answer.

kubectl run discovery-client --image=busybox:1.36.1 --restart=Never \
  --command -- sleep 3600
kubectl wait --for=condition=Ready pod/discovery-client --timeout=90s
kubectl exec discovery-client -- cat /etc/resolv.conf
kubectl exec discovery-client -- nslookup service-demo
kubectl exec discovery-client -- wget -qO- http://service-demo:8080/

Choose an entry point for external callers

A NodePort Service opens a chosen port across eligible node addresses in addition to providing an internal ClusterIP. A caller with network access to a node can connect to that node’s IP and the allocated port. A LoadBalancer Service requests a front door from a supporting cloud provider or cluster add-on. On a basic kind cluster, that external address can stay pending because no implementation is providing it.

apiVersion: v1
kind: Service
metadata:
  name: node-entry-demo
spec:
  type: NodePort
  selector:
    app: service-demo # Existing web Pods from the prior lesson.
  ports:
    - name: http
      port: 8080
      targetPort: http
      # Omit nodePort: the API allocates from its configured range.

Three ways to expose a Service

Choose the entry point based on where the client runs and what your cluster can provision.

  1. ClusterIP for in-cluster clients

    A cluster workload can use the Service virtual IP when the network implementation supports that path. A laptop does not automatically have that route.

  2. NodePort at a node address

    An external caller needs a reachable node address and allocated node port. Network rules and local VM/container boundaries still apply.

  3. Provider-managed load balancer

    A provider/controller provisions an external frontend and connects it to a supported backend path. Creating the Service object alone is not provisioning software.

A common LoadBalancer-to-NodePort path is shown; implementations may instead target Pods directly.

Save the file as node-entry-demo.yaml. Look for the allocated NodePort and the node IPs. In kind, the nodes are containers. Whether your laptop can reach a node address or NodePort depends on its network and any configured host port mappings. For a local debug connection, kubectl port-forward listens on your laptop and forwards through the Kubernetes API path to a selected Pod. Leave the command running and try http://localhost:8080 in another terminal or browser tab.

kubectl apply -f node-entry-demo.yaml
kubectl get service node-entry-demo
kubectl get nodes -o wide
# A debugging tunnel to a selected backend, without external provisioning:
kubectl port-forward service/service-demo 8080:8080

Test the actual path your client uses

Compare a request from inside the cluster and a request from your machine in the local Service networking lab. If a port-forward works while in-cluster requests fail, keep debugging the Service and client path. Stop the forward when finished, and clean up discovery-client after completing the next lesson or its practice.

Check your understanding

Port-forward works from your laptop. Does that tell you an application in another namespace can resolve the Service and reach it?

The forward gives your laptop a working tunnel to one selected backend. Test from a client in the other namespace using the namespace-qualified Service name to check its DNS settings, network policy, Service routing, and backend availability.

Primary documentation

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu