← Về danh sách bài học
Bài 25/25
🔧 Bài 25: Troubleshooting Kubernetes
🎯 Sau bài học này, bạn sẽ:
- Debug pods không start được
- Xử lý các lỗi phổ biến
- Sử dụng kubectl debug
- Troubleshoot networking
1. Debug Workflow
# 1. Xem status pods
kubectl get pods -o wide
# 2. Describe để xem events
kubectl describe pod my-pod
# 3. Xem logs
kubectl logs my-pod
kubectl logs my-pod --previous # crashed container
# 4. Exec vào pod
kubectl exec -it my-pod -- /bin/sh
2. Pod Status Errors
| Status | Nguyên nhân | Fix |
|---|---|---|
Pending |
Không schedule được | Check resources, node selector |
ImagePullBackOff |
Không pull được image | Check image name, imagePullSecrets |
CrashLoopBackOff |
Container crash liên tục | Check logs, command, probes |
CreateContainerError |
Lỗi khi tạo container | Check configMap, secrets mount |
3. kubectl debug
# Debug với ephemeral container
kubectl debug my-pod -it --image=busybox
# Debug copy của pod (không ảnh hưởng original)
kubectl debug my-pod -it --copy-to=my-pod-debug --container=debugger --image=busybox
# Debug node
kubectl debug node/my-node -it --image=busybox
4. Networking Issues
# Test DNS
kubectl run test --image=busybox -it --rm -- nslookup my-service
# Test connectivity
kubectl run test --image=busybox -it --rm -- wget -qO- http://my-service
# Check endpoints
kubectl get endpoints my-service
# Check service
kubectl describe service my-service
⚠️ Common Networking Issues:
• Service selector không match pod labels
• Network Policy block traffic
• Pod không ready (readiness probe fail)
• Service selector không match pod labels
• Network Policy block traffic
• Pod không ready (readiness probe fail)
5. Resource Issues
# Xem resource usage
kubectl top pods
kubectl top nodes
# Xem events
kubectl get events --sort-by='.lastTimestamp'
# Check resource quota
kubectl describe resourcequota -n my-namespace
6. Common Fixes
💡 Quick Fixes:
• OOMKilled: Tăng memory limit
• Evicted: Tăng resources hoặc thêm nodes
• Liveness probe fail: Tăng initialDelaySeconds
• Permission denied: Check SecurityContext, RBAC
• OOMKilled: Tăng memory limit
• Evicted: Tăng resources hoặc thêm nodes
• Liveness probe fail: Tăng initialDelaySeconds
• Permission denied: Check SecurityContext, RBAC
🎉 Chúc Mừng!
Bạn đã hoàn thành khóa học Kubernetes 25 bài!
Giờ bạn đã có kiến thức từ cơ bản đến nâng cao để làm việc với Kubernetes.
📝 Tóm Tắt Toàn Khóa
- ✅ Fundamentals: Pods, Deployments, Services
- ✅ Configuration: ConfigMaps, Secrets, Volumes
- ✅ Networking: Ingress, TLS, Network Policies
- ✅ Scaling: HPA, Probes
- ✅ Helm & GitOps
- ✅ Security: RBAC, Pod Security
- ✅ Observability: Monitoring, Logging
- ✅ Troubleshooting!