Latest
Kubernetes 1 min read

Connect to Pods with Kubernetes Services and DNS

Connect to Pods with Kubernetes Services and DNS
Kubernetes · November 28, 2026

Version note: examples use the Kubernetes v1.35 documentation snapshot, not necessarily the newest release. Check current support and component compatibility. These commands were not tested on a live cluster.

What this guide covers

A Service gives a changing group of Pods a stable network address. CoreDNS resolves the Service name. EndpointSlices list the Pod addresses available behind that Service.

Before you start

Use a cluster with working Pod networking and DNS. Create network-lab. These commands test traffic inside the cluster, not an external website.

Step 1: Create the application and Service

Save this as network.yaml, then apply it with kubectl apply -f network.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  namespace: network-lab
spec:
  replicas: 2
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: web
          image: nginx:1.28.0
          ports:
            - name: http
              containerPort: 80
          readinessProbe:
            httpGet:
              path: /
              port: http
            periodSeconds: 5
          resources:
            requests:
              cpu: 100m
              memory: 64Mi
            limits:
              memory: 128Mi
---
apiVersion: v1
kind: Service
metadata:
  name: web
  namespace: network-lab
spec:
  type: ClusterIP
  selector:
    app: web
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: http

The Service selector must match the Pod labels. Its target port must reach the application’s listening port.

Step 2: Test from a client Pod

Run:

kubectl -n network-lab rollout status deployment/web --timeout=120s
kubectl -n network-lab run dns-check --image=busybox:1.37.0 \
  --restart=Never --rm -it -- sh
# Inside the client Pod:
nslookup web.network-lab.svc.cluster.local
wget -qO- http://web.network-lab.svc.cluster.local
cat /etc/resolv.conf

The first command waits for the application. The run command opens a shell in a temporary client Pod. Run nslookup and wget inside that shell, then type exit. The lookup should return a Service address and wget should return the web page.

Step 3: Check each part if traffic fails

Run these from your normal terminal:

kubectl -n network-lab get pods -l app=web -o wide
kubectl -n network-lab get service web -o wide
kubectl -n network-lab get endpointslices -l kubernetes.io/service-name=web -o yaml
kubectl -n kube-system get deployment coredns
kubectl -n kube-system get daemonset kube-proxy

No endpoints usually means a selector or readiness problem. A failed lookup points to DNS. A resolved name with a failed connection needs a port, policy or routing check. Some clusters replace kube-proxy with another implementation; use that component’s checks instead.

Check the result

Check name lookup and HTTP response separately. Port forwarding from your laptop is useful but does not independently test normal in-cluster Service routing.

References

PB
Written by

Parul Bedi

Notes and guides by Parul Bedi.

Up next

Install SonarQube on Ubuntu Step by Step

Sonar November 30, 2026 4 min read
Open post

Conversation

0 comments

No comments yet. Start the conversation below.

Leave a comment

Replying to a comment.
Be kind. Markdown is not supported in comments.