kubectl expose deployment nginx \ --name=nginx-svc \ --port=80 \ --target-port=80
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
spec:
type: ClusterIP
selector:
app: nginx
ports:
- port: 80
targetPort: 80
Remember:
spec: type selector ports
| Problem | First Command |
|---|---|
| Pod Pending | kubectl describe pod <pod> |
| CrashLoopBackOff | kubectl logs <pod> |
| ImagePullBackOff | kubectl describe pod <pod> |
| Service Not Working | kubectl get endpoints <svc> |
| PVC Pending | kubectl describe pvc <pvc> |
| Network Issue | kubectl get networkpolicy -A |
| Error | Likely Cause |
|---|---|
| manifest unknown | Bad tag |
| repository not found | Bad image name |
| unauthorized | Missing imagePullSecret |
| no such host | Bad registry |
| FailedToRetrieveImagePullSecret | Secret does not exist |
If:
kubectl get endpoints nginx-svc <none>
Think:
Selector mismatch
Check:
kubectl describe svc nginx-svc kubectl get pods --show-labels
Pod Problem? ↓ kubectl describe pod Container Problem? ↓ kubectl logs Service Problem? ↓ kubectl get endpoints Storage Problem? ↓ kubectl describe pvc Network Problem? ↓ kubectl get networkpolicy
Goal: Break every item intentionally and fix it without looking at notes.
ImagePullBackOffmanifest unknown
kubectl describe pod
repository not found
FailedToRetrieveImagePullSecret
command: ["false"]Practice:
kubectl logs pod kubectl logs pod --previous
resources:
requests:
memory: 500Gi
Expected:
Insufficient memory
node(s) had taintFix:
tolerations:
Pod Label: app: nginx Service Selector: app: webExpected:
kubectl get endpoints service-name <none>Practice:
kubectl describe svc service-name kubectl get pods --show-labels
Service: targetPort: 8080 Container: containerPort: 80Expected:
Endpoints exist Traffic fails
image: nginx:999Practice:
kubectl describe deployment kubectl get rs kubectl get podsFollow:
Deployment ↓ ReplicaSet ↓ Pod
kubectl scale deployment nginx --replicas=5
kubectl get pvc kubectl describe pvc
PV: ReadWriteOnce PVC: ReadOnlyMany
PV: fast PVC: slow
kubectl get networkpolicy -A kubectl describe networkpolicy
kubectl exec -it pod -- sh wget curl
kubectl run dns-test --image=busybox --restart=Never -it -- shTest:
nslookup kubernetes.default
kubectl get nodes kubectl describe nodeNode commands:
sudo systemctl status kubelet sudo systemctl restart kubelet
kubectl drain node1 --ignore-daemonsets kubectl uncordon node1
kubectl describe pod kubectl logs kubectl logs --previous kubectl get endpoints kubectl describe pvc kubectl get networkpolicy -A kubectl describe node kubectl get pods -o wide kubectl get pods --show-labels kubectl get rs kubectl describe deployment
ImagePullBackOff → kubectl describe pod CrashLoopBackOff → kubectl logs manifest unknown → bad tag repository not found → bad image unauthorized → imagePullSecret FailedToRetrieveImagePullSecret → secret missing Insufficient memory → scheduling issue node(s) had taint → toleration needed endpoints→ selector mismatch PVC Pending → PV / AccessMode / StorageClass issue
Pod Problem? ↓ kubectl describe pod Container Problem? ↓ kubectl logs Service Problem? ↓ kubectl get endpoints Storage Problem? ↓ kubectl describe pvc Network Problem? ↓ kubectl get networkpolicy -A Node Problem? ↓ kubectl describe node