|
| 1 | +# Kubernetes Troubleshooting Workflow |
| 2 | + |
| 3 | +This workflow guides you through troubleshooting Kubernetes-related incidents. |
| 4 | + |
| 5 | +## Step 1: Assess the Situation |
| 6 | + |
| 7 | +### 1.1 Gather Initial Information |
| 8 | + |
| 9 | +- Identify which namespace/service is affected |
| 10 | +- Check if it's a pod, deployment, service, or ingress issue |
| 11 | +- Determine the severity and user impact |
| 12 | + |
| 13 | +**Actions:** |
| 14 | + |
| 15 | +- Use MCP tools to query cluster status |
| 16 | +- Check recent deployments or changes |
| 17 | +- Review alert details |
| 18 | + |
| 19 | +### 1.2 Check Pod Status |
| 20 | + |
| 21 | +Use MCP tools or commands to check pod status: |
| 22 | + |
| 23 | +**MCP Actions:** |
| 24 | + |
| 25 | +- Use `k8s` MCP server `list_pods` to see pod status |
| 26 | +- Use `k8s` MCP server `get_pod_logs` to check recent logs |
| 27 | +- Use `k8s` MCP server `describe_pod` for detailed pod information |
| 28 | + |
| 29 | +**Manual Commands (if MCP not available):** |
| 30 | + |
| 31 | +```bash |
| 32 | +kubectl get pods -n <namespace> |
| 33 | +kubectl describe pod <pod-name> -n <namespace> |
| 34 | +kubectl logs <pod-name> -n <namespace> --tail=100 |
| 35 | +``` |
| 36 | + |
| 37 | +## Step 2: Diagnose the Issue |
| 38 | + |
| 39 | +### 2.1 Check Pod States |
| 40 | + |
| 41 | +Identify the pod state: |
| 42 | + |
| 43 | +- **Pending**: Pod can't be scheduled |
| 44 | +- **CrashLoopBackOff**: Pod keeps crashing |
| 45 | +- **ImagePullBackOff**: Can't pull container image |
| 46 | +- **Running but unhealthy**: Pod running but failing health checks |
| 47 | +- **Terminating**: Pod stuck in termination |
| 48 | + |
| 49 | +### 2.2 Common Issues and Solutions |
| 50 | + |
| 51 | +#### Issue: Pod in CrashLoopBackOff |
| 52 | + |
| 53 | +**Diagnosis:** |
| 54 | + |
| 55 | +1. Check pod logs for errors |
| 56 | +2. Review container exit codes |
| 57 | +3. Check resource limits |
| 58 | +4. Verify environment variables and configs |
| 59 | + |
| 60 | +**Resolution:** |
| 61 | + |
| 62 | +- Fix application errors in logs |
| 63 | +- Adjust resource requests/limits if OOMKilled |
| 64 | +- Fix configuration issues |
| 65 | +- Check for missing dependencies or secrets |
| 66 | + |
| 67 | +**MCP Actions:** |
| 68 | + |
| 69 | +- Use `k8s` MCP `get_pod_logs` to view crash logs |
| 70 | +- Use `k8s` MCP `get_pod_events` to see recent events |
| 71 | + |
| 72 | +#### Issue: ImagePullBackOff |
| 73 | + |
| 74 | +**Diagnosis:** |
| 75 | + |
| 76 | +1. Check if image exists and is accessible |
| 77 | +2. Verify image pull secrets |
| 78 | +3. Check network connectivity to registry |
| 79 | + |
| 80 | +**Resolution:** |
| 81 | + |
| 82 | +- Verify image tag exists |
| 83 | +- Add/update imagePullSecrets if needed |
| 84 | +- Check registry authentication |
| 85 | +- Verify network policies allow registry access |
| 86 | + |
| 87 | +**MCP Actions:** |
| 88 | + |
| 89 | +- Use `k8s` MCP `describe_pod` to see image pull errors |
| 90 | +- Use `k8s` MCP `list_secrets` to check image pull secrets |
| 91 | + |
| 92 | +#### Issue: Pod Pending |
| 93 | + |
| 94 | +**Diagnosis:** |
| 95 | + |
| 96 | +1. Check node resources (CPU, memory) |
| 97 | +2. Review node selectors and affinity rules |
| 98 | +3. Check for taints and tolerations |
| 99 | +4. Verify persistent volume claims |
| 100 | + |
| 101 | +**Resolution:** |
| 102 | + |
| 103 | +- Scale cluster if resources exhausted |
| 104 | +- Adjust node selectors/affinity |
| 105 | +- Add tolerations if needed |
| 106 | +- Fix PVC issues |
| 107 | + |
| 108 | +**MCP Actions:** |
| 109 | + |
| 110 | +- Use `k8s` MCP `describe_pod` to see scheduling events |
| 111 | +- Use `k8s` MCP `get_nodes` to check node resources |
| 112 | +- Use `k8s` MCP `get_pvc` to check volume claims |
| 113 | + |
| 114 | +#### Issue: Service Not Accessible |
| 115 | + |
| 116 | +**Diagnosis:** |
| 117 | + |
| 118 | +1. Check service endpoints |
| 119 | +2. Verify service selector matches pod labels |
| 120 | +3. Check ingress configuration |
| 121 | +4. Review network policies |
| 122 | + |
| 123 | +**Resolution:** |
| 124 | + |
| 125 | +- Fix label mismatches |
| 126 | +- Update service selectors |
| 127 | +- Fix ingress rules |
| 128 | +- Adjust network policies |
| 129 | + |
| 130 | +**MCP Actions:** |
| 131 | + |
| 132 | +- Use `k8s` MCP `get_service_endpoints` to check endpoints |
| 133 | +- Use `k8s` MCP `describe_service` for service details |
| 134 | +- Use `k8s` MCP `get_ingress` to check ingress rules |
| 135 | + |
| 136 | +## Step 3: Check Resource Constraints |
| 137 | + |
| 138 | +### 3.1 Resource Limits |
| 139 | + |
| 140 | +Check if pods are hitting resource limits: |
| 141 | + |
| 142 | +**MCP Actions:** |
| 143 | + |
| 144 | +- Use `k8s` MCP `get_pod_metrics` to see current usage |
| 145 | +- Use `k8s` MCP `describe_pod` to check limits/requests |
| 146 | + |
| 147 | +**Manual Commands:** |
| 148 | + |
| 149 | +```bash |
| 150 | +kubectl top pod <pod-name> -n <namespace> |
| 151 | +kubectl describe pod <pod-name> -n <namespace> | grep -A 5 "Limits\|Requests" |
| 152 | +``` |
| 153 | + |
| 154 | +### 3.2 Node Resources |
| 155 | + |
| 156 | +Check cluster-wide resource availability: |
| 157 | + |
| 158 | +**MCP Actions:** |
| 159 | + |
| 160 | +- Use `k8s` MCP `get_node_metrics` to see node usage |
| 161 | +- Use `k8s` MCP `get_nodes` to check allocatable resources |
| 162 | + |
| 163 | +## Step 4: Check Dependencies |
| 164 | + |
| 165 | +### 4.1 ConfigMaps and Secrets |
| 166 | + |
| 167 | +Verify required configs and secrets exist: |
| 168 | + |
| 169 | +**MCP Actions:** |
| 170 | + |
| 171 | +- Use `k8s` MCP `get_configmap` to check configs |
| 172 | +- Use `k8s` MCP `get_secret` to verify secrets |
| 173 | + |
| 174 | +**Manual Commands:** |
| 175 | + |
| 176 | +```bash |
| 177 | +kubectl get configmap -n <namespace> |
| 178 | +kubectl get secret -n <namespace> |
| 179 | +``` |
| 180 | + |
| 181 | +### 4.2 Service Dependencies |
| 182 | + |
| 183 | +Check if dependent services are running: |
| 184 | + |
| 185 | +**MCP Actions:** |
| 186 | + |
| 187 | +- Use `k8s` MCP `list_services` to see all services |
| 188 | +- Use `k8s` MCP `get_service_endpoints` to verify endpoints |
| 189 | + |
| 190 | +## Step 5: Review Recent Changes |
| 191 | + |
| 192 | +### 5.1 Check Deployment History |
| 193 | + |
| 194 | +Look for recent changes that might have caused the issue: |
| 195 | + |
| 196 | +**MCP Actions:** |
| 197 | + |
| 198 | +- Use `k8s` MCP `get_deployment_history` to see rollout history |
| 199 | +- Use `k8s` MCP `get_events` to see recent cluster events |
| 200 | + |
| 201 | +**Manual Commands:** |
| 202 | + |
| 203 | +```bash |
| 204 | +kubectl rollout history deployment/<deployment-name> -n <namespace> |
| 205 | +kubectl get events -n <namespace> --sort-by='.lastTimestamp' |
| 206 | +``` |
| 207 | + |
| 208 | +### 5.2 Rollback if Needed |
| 209 | + |
| 210 | +If recent deployment caused the issue: |
| 211 | + |
| 212 | +**MCP Actions:** |
| 213 | + |
| 214 | +- Use `k8s` MCP `rollback_deployment` to rollback |
| 215 | + |
| 216 | +**Manual Commands:** |
| 217 | + |
| 218 | +```bash |
| 219 | +kubectl rollout undo deployment/<deployment-name> -n <namespace> |
| 220 | +``` |
| 221 | + |
| 222 | +## Step 6: Verify Resolution |
| 223 | + |
| 224 | +### 6.1 Check Pod Status |
| 225 | + |
| 226 | +Verify pods are running and healthy: |
| 227 | + |
| 228 | +**MCP Actions:** |
| 229 | + |
| 230 | +- Use `k8s` MCP `list_pods` to verify status |
| 231 | +- Use `k8s` MCP `get_pod_metrics` to check resource usage |
| 232 | + |
| 233 | +### 6.2 Test Functionality |
| 234 | + |
| 235 | +- Verify service endpoints respond |
| 236 | +- Check application logs for errors |
| 237 | +- Test critical user flows |
| 238 | + |
| 239 | +**MCP Actions:** |
| 240 | + |
| 241 | +- Use `k8s` MCP `port_forward` to test locally if needed |
| 242 | +- Use monitoring MCP to check service metrics |
| 243 | + |
| 244 | +## Step 7: Document Resolution |
| 245 | + |
| 246 | +### 7.1 Update Incident Log |
| 247 | + |
| 248 | +Create or update incident log: `incidents/YYYY-MM-DD-HHMM-k8s-<issue>.md` |
| 249 | + |
| 250 | +Include: |
| 251 | + |
| 252 | +- Root cause |
| 253 | +- Steps taken to resolve |
| 254 | +- Any rollbacks performed |
| 255 | +- Follow-up actions needed |
| 256 | + |
| 257 | +### 7.2 Update Runbooks |
| 258 | + |
| 259 | +If this was a new issue pattern: |
| 260 | + |
| 261 | +- Add to service-specific runbook |
| 262 | +- Document the solution for future reference |
| 263 | + |
| 264 | +## Quick Reference Commands |
| 265 | + |
| 266 | +```bash |
| 267 | +# Get pod status |
| 268 | +kubectl get pods -n <namespace> |
| 269 | + |
| 270 | +# Describe pod details |
| 271 | +kubectl describe pod <pod-name> -n <namespace> |
| 272 | + |
| 273 | +# View logs |
| 274 | +kubectl logs <pod-name> -n <namespace> --tail=100 -f |
| 275 | + |
| 276 | +# Check events |
| 277 | +kubectl get events -n <namespace> --sort-by='.lastTimestamp' |
| 278 | + |
| 279 | +# Check resource usage |
| 280 | +kubectl top pod <pod-name> -n <namespace> |
| 281 | + |
| 282 | +# Check service endpoints |
| 283 | +kubectl get endpoints <service-name> -n <namespace> |
| 284 | + |
| 285 | +# Rollback deployment |
| 286 | +kubectl rollout undo deployment/<deployment-name> -n <namespace> |
| 287 | + |
| 288 | +# Scale deployment |
| 289 | +kubectl scale deployment/<deployment-name> --replicas=<count> -n <namespace> |
| 290 | +``` |
| 291 | + |
| 292 | +## Common MCP Tools Reference |
| 293 | + |
| 294 | +If you have a Kubernetes MCP server configured, use these tools: |
| 295 | + |
| 296 | +- `k8s_list_pods` - List pods in namespace |
| 297 | +- `k8s_get_pod_logs` - Get pod logs |
| 298 | +- `k8s_describe_pod` - Get detailed pod information |
| 299 | +- `k8s_get_pod_events` - Get events for a pod |
| 300 | +- `k8s_get_service_endpoints` - Check service endpoints |
| 301 | +- `k8s_rollback_deployment` - Rollback a deployment |
| 302 | +- `k8s_get_nodes` - Check node status and resources |
| 303 | +- `k8s_get_pvc` - Check persistent volume claims |
0 commit comments