0
0
Kubernetesdevops~5 mins

Debugging service connectivity in Kubernetes - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes your app cannot talk to another app inside Kubernetes. Debugging service connectivity helps find why the connection fails and fix it quickly.
When your frontend app cannot reach the backend service inside the cluster.
When a pod cannot connect to a database service running in Kubernetes.
When you want to check if a service is exposing the right ports and endpoints.
When network policies might be blocking traffic between pods.
When you want to verify DNS resolution of service names inside the cluster.
Commands
Check which pods are running to confirm your app and service pods are up.
Terminal
kubectl get pods
Expected OutputExpected
NAME READY STATUS RESTARTS AGE frontend-5d8f7c9d7f-abc12 1/1 Running 0 10m backend-6f7d8c9d7f-def34 1/1 Running 0 10m
List services to verify the backend service is created and exposing the correct ports.
Terminal
kubectl get svc
Expected OutputExpected
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE backend ClusterIP 10.96.123.45 <none> 8080/TCP 10m kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 1d
From the frontend pod, try to connect to the backend service using curl to test connectivity.
Terminal
kubectl exec frontend-5d8f7c9d7f-abc12 -- curl -sS backend:8080
Expected OutputExpected
Hello from backend!
-- - Separates kubectl exec options from the command to run inside the pod
Show detailed info about the backend service to check endpoints and ports.
Terminal
kubectl describe svc backend
Expected OutputExpected
Name: backend Namespace: default Labels: <none> Annotations: <none> Selector: app=backend Type: ClusterIP IP: 10.96.123.45 Port: 8080/TCP Endpoints: 10.244.1.5:8080 Session Affinity: None Events: <none>
Check the IP addresses of pods behind the backend service to ensure they are ready.
Terminal
kubectl get endpoints backend
Expected OutputExpected
NAME ENDPOINTS AGE backend 10.244.1.5:8080 10m
Key Concept

If you remember nothing else from this pattern, remember: test connectivity from inside the pod using service names and verify service endpoints.

Common Mistakes
Trying to curl the service from outside the cluster without port forwarding or ingress.
Services of type ClusterIP are only reachable inside the cluster, so external curl will fail.
Use kubectl exec to run curl inside a pod or use port forwarding to access the service externally.
Assuming the service IP is the pod IP and trying to connect directly to pod IPs.
Pods can change IPs and are not stable endpoints; services provide stable access.
Always use the service name or ClusterIP to connect to pods.
Not checking if the backend pods are ready before testing connectivity.
If pods are not ready or crashed, the service will have no endpoints and connections fail.
Use kubectl get pods and kubectl describe pods to confirm pod readiness.
Summary
Check pods and services to confirm your apps are running and exposed.
Use kubectl exec with curl inside a pod to test service connectivity by name and port.
Describe the service and check endpoints to verify backend pods are correctly linked.