Effective Troubleshooting
Diagnostic Workflow for Kubernetes Services
graph TD
A[Service Issue Detected] --> B{Validate Configuration}
B -->|Incorrect| C[Fix Configuration]
B -->|Correct| D[Check Network Connectivity]
D -->|Blocked| E[Inspect Network Policies]
D -->|Open| F[Examine Pod Status]
Essential Troubleshooting Commands
1. Service Inspection
## List all services
kubectl get services
## Detailed service description
kubectl describe service [service-name]
## Check service endpoints
kubectl get endpoints [service-name]
2. Network Diagnostics
Command |
Purpose |
Usage |
kubectl get pods |
List pod status |
Verify pod health |
kubectl logs [pod-name] |
View pod logs |
Identify runtime issues |
kubectl port-forward |
Local port forwarding |
Test service connectivity |
Common Troubleshooting Scenarios
Selector Mismatch Resolution
## Correct Pod Labels
apiVersion: v1
kind: Pod
metadata:
labels:
app: mywebapp
tier: frontend
## Matching Service Selector
spec:
selector:
app: mywebapp
tier: frontend
Advanced Debugging Techniques
Network Policy Verification
## Check network policies
kubectl get networkpolicies
## Describe specific network policy
kubectl describe networkpolicy [policy-name]
1. Connectivity Testing
## Install network debugging tools
sudo apt-get update
sudo apt-get install -y netcat curl
## Test service connectivity
curl http://[service-ip]:[port]
2. Kubernetes Proxy Method
## Start Kubernetes proxy
kubectl proxy
## Access service through localhost
curl http://localhost:8001/api/v1/namespaces/default/services/[service-name]/proxy
Recommended Troubleshooting Workflow
- Validate service configuration
- Check pod status and labels
- Inspect network policies
- Verify service endpoints
- Use diagnostic commands
- Analyze logs and error messages
Best Practices
- Always use
kubectl describe
- Leverage logging and monitoring tools
- Understand network configuration
- Regularly audit service setups
LabEx recommends a systematic approach to service troubleshooting, focusing on methodical diagnosis and resolution of connectivity issues.