免费公开题库原题 #118 · Troubleshooting

ErrImagePull 与 ImagePullBackOff 怎么排查?

Pod 状态: ErrImagePull → 重试 → ImagePullBackOff

诊断:

# 从这里开始 — 查看 Events 部分
kubectl describe pod <pod-name>

错误信息及对应原因:

Event 信息根本原因
repository does not exist or may require 'docker login'镜像名称拼写错误或仓库地址不对
no basic auth credentials私有仓库 — imagePullSecrets 未配置或配置错误
manifest unknown指定的 Tag 在仓库中不存在
connection timeout / network unreachable节点无法访问仓库(防火墙、DNS)
unauthorized: access denied拉取凭证错误

修复 1 — 镜像名称错误:

# 本地验证镜像是否存在
docker pull nginx:wrongtag

# 更新 Deployment 镜像
kubectl set image deployment/<name> <container>=nginx:correct-tag

修复 2 — 私有仓库凭证:

# 创建拉取凭证
kubectl create secret docker-registry regcred   --docker-server=registry.example.com   --docker-username=myuser   --docker-password=mypassword

# 在 Pod spec 中引用
spec:
  imagePullSecrets:
  - name: regcred

修复 3 — 网络问题:

# 从节点上测试仓库可达性
kubectl run -it --rm debug --image=busybox -- wget -O- https://registry.example.com/v2/

📖 官方文档:https://kubernetes.io/docs/concepts/containers/images/