Goal: Learn to diagnose Service issues quickly by following the same workflow every time.
kubectl get svc kubectl get endpoints kubectl describe svckubectl get pods --show-labels kubectl describe pod
kubectl get endpoints NAME webapp-svc ENDPOINTS
kubectl describe svc webapp-svc Selector: app=banana
kubectl get pods --show-labels webapp-pod app=webapp
Practice troubleshooting a Service that exists, has endpoints, but forwards traffic to the wrong container port.
# Create an nginx pod kubectl run nginx --image=nginx --port=80 # Create a Service with the WRONG target port kubectl expose pod nginx \ --name=nginx-svc \ --port=80 \ --target-port=9999 # Create a temporary test pod kubectl run test \ --image=busybox:1.35 \ --restart=Never \ -- sleep 3600
kubectl exec test -- wget -qO- nginx-svc
Connection refused OR Request times out OR No output is returned
The test pod acts as a client inside the cluster. It attempts to access the Service using Kubernetes DNS.
kubectl get svc nginx-svc kubectl describe svc nginx-svc kubectl get endpoints nginx-svc
Notice the Service is forwarding traffic to port 9999.
Port: 80/TCP TargetPort: 9999/TCP
kubectl get endpoints nginx-svc nginx-svc 10.244.0.5:9999
kubectl edit svc nginx-svc
Change:
targetPort: 9999
To:
targetPort: 80
kubectl get endpoints nginx-svc
nginx-svc 10.244.0.5:80
kubectl exec test -- wget -qO- nginx-svc
The nginx welcome page should now be returned.
kubectl get svc kubectl describe svc kubectl get endpoints kubectl get pods --show-labels kubectl describe pod kubectl exec test -- wget -qO-
Learn how to troubleshoot a Service that has no endpoints because the backing Pod is repeatedly crashing and never becomes Ready.
Create a Deployment:
kubectl create deployment web --image=busybox
Edit the Deployment:
kubectl edit deployment web
Modify the container definition so it immediately exits:
containers:
- image: busybox
name: busybox
command:
- /bin/sh
- -c
- exit 1
Create a Service:
kubectl expose deployment web \
--port=80 \
--target-port=80
Check the Service endpoints:
kubectl get endpoints web
Expected output:
NAME ENDPOINTS AGE
web <none> ...
Check the Pods:
kubectl get pods
Expected output:
NAME READY STATUS RESTARTS
web-xxxxxxxxxx-xxxxx 0/1 CrashLoopBackOff ...
View the container logs:
kubectl logs <pod-name>
Example output:
container exited with code 1
Inspect Pod events:
kubectl describe pod <pod-name>
Look for messages similar to:
Back-off restarting failed container
<none>.
Service
↓
Selector matches Pod
↓
Pod exists
↓
Pod Ready?
↓
NO
↓
No Endpoints
Remember: Services only send traffic to Ready Pods. A Pod in CrashLoopBackOff never becomes healthy enough to join the endpoint list.
| Status | Container Started? | Most Likely Cause |
|---|---|---|
| ImagePullBackOff | No | Image cannot be downloaded. |
| CrashLoopBackOff | Yes | Application starts and then crashes. |
kubectl describe pod.kubectl create deployment web --image=nginx kubectl expose deployment web --port=80 kubectl set image deployment/web \ nginx=nginx:doesnotexist
kubectl get pods web-oldpod Running web-newpod ImagePullBackOff
kubectl get endpoints web 192.168.x.x:80
1. kubectl get svc 2. kubectl get endpoints 3. kubectl describe svc4. kubectl get pods --show-labels 5. kubectl describe pod 6. kubectl logs
Service ↓ Selector ↓ Ready Pods ↓ Endpoints ↓ Traffic
Endpoints:↓ Check Selector Selector Correct? ↓ Check Pod Health ImagePullBackOff? CrashLoopBackOff? Pending? NotReady? Endpoints Exist ↓ Check TargetPort TargetPort Correct? ↓ Check Application