هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
The quick answer
kubectl get pods -n shop
NAME READY STATUS RESTARTS AGE
api-6d8f9c7b5d-x2kq9 0/1 CrashLoopBackOff 5 (40s ago) 4m
kubectl describe pod api-6d8f9c7b5d-x2kq9 -n shop
kubectl logs api-6d8f9c7b5d-x2kq9 -n shop --previous
kubectl get events -n shop --sort-by=.lastTimestamp | tail -20describe → read the Events at the bottom and the State / Last State of the container. logs --previous shows why the last run crashed.
Step by step
- Read the STATUS column and look it up:
| Status | Meaning | Usual fix |
|---|---|---|
Pending | No node was chosen yet. | Events say why: not enough CPU/memory, taint, nodeSelector/affinity, PVC not bound. |
ContainerCreating (long) | Node chosen, the container can not start yet. | Volume mount, Secret/ConfigMap missing, CNI (network) problem — see events. |
ImagePullBackOff / ErrImagePull | The image can not be pulled. | Name or tag wrong, registry needs imagePullSecrets, registry not reachable. |
CreateContainerConfigError | A referenced Secret, ConfigMap or key does not exist. | Create it, or fix the name in the Pod spec. |
CrashLoopBackOff | The container starts and dies again and again. | kubectl logs --previous; app error, wrong command, missing env, failing probe. |
OOMKilled (in Last State) | It used more memory than its limit. | Raise resources.limits.memory or fix the leak. |
Init:0/1, Init:CrashLoopBackOff | An init container did not finish. | kubectl logs POD -c INIT-NAME. |
Running but 0/1 ready | The readiness probe fails. | Probe path/port wrong, or the app is slow — check describe. |
- Describe the Pod — the bottom part is the story:
kubectl describe pod api-6d8f9c7b5d-x2kq9 -n shop | sed -n '/Last State/,/Ready/p;/Events/,$p'
Last State: Terminated
Reason: Error
Exit Code: 1
Events:
Warning BackOff 12s (x20 over 4m) kubelet Back-off restarting failed container api- Get the exact reason in one line (good for scripts and tickets):
kubectl get pod api-6d8f9c7b5d-x2kq9 -n shop -o jsonpath='{.status.containerStatuses[0].state}{"\n"}{.status.containerStatuses[0].lastState.terminated.reason}{"\n"}'- Pending? Check the nodes. Are there free resources, and does the Pod tolerate the taints?
kubectl describe node worker1 | grep -A8 'Allocated resources'
kubectl get nodes -o custom-columns=NAME:.metadata.name,TAINTS:.spec.taints
kubectl get pvc -n shopThe scheduler event 0/3 nodes are available: 3 Insufficient memory means the Pod requests more than any node has free — lower the request or add nodes.
- Look at the owner — a broken Deployment change often shows in the ReplicaSet:
Check that it worked
Common problems
| Problem | Cause | Fix |
|---|---|---|
Failed to pull image … not found | Typo in the image name or the tag does not exist. | Check the tag in the registry; use the full name registry/project/app:tag. |
pull access denied / unauthorized | Private registry, no pull secret. | Create a docker-registry Secret and add imagePullSecrets. |
secret "db-cred" not found | The Secret is missing in this namespace. | Secrets are per namespace — create it in shop. |
0/3 nodes are available: … untolerated taint | All nodes have taints the Pod does not tolerate. | Add a toleration, or schedule on other nodes. |
pod has unbound immediate PersistentVolumeClaims | No StorageClass / no free volume. | kubectl get pvc,sc; set a StorageClass or create the PV. |
CrashLoopBackOff, no logs at all | The process exits before it writes (wrong command or entrypoint). | Check command/args; kubectl debug with a copy and sh. |
Liveness probe failed and restarts | The probe kills a slow-starting app. | Add a startupProbe or a longer initialDelaySeconds. |
Go further
- Command pages: kubectl, crictl.
- Next how-tos: Get the logs of a crashed Pod, Open a shell in a running Pod, Roll back a deployment, Create a Kubernetes Secret safely, Add liveness and readiness probes.
- Learn it: CKA — Troubleshoot Pods, CKA — Probes, CKA — Resources, The debug flow in daily DevOps.
- Full guides: kubectl, Kubernetes with kubeadm, k9s.
- Practise: Lab: troubleshooting drill — fix five broken things.
1A Pod is Pending. Where do you find the reason?
In the events: kubectl describe pod (bottom) or kubectl get events — usually resources, taints, affinity or an unbound PVC.
2A container is in CrashLoopBackOff. Which log do you need?
The log of the previous run: kubectl logs POD --previous.