解决minikube的ImagePullBackOff问题
首先使用阿里云镜像来创建minikube的群集:
$ minikube start --image-mirror-country=cn --memory='4gb'
一般情况下应该没有网络问题,如果无法正常安装可以尝试配置一下底层docker的代理:
然后尝试安装registry addon
:
➤ minikube addons enable registry
再我的环境下,其中一个image会无法正常下载(虽然使用了镜像):
➤ watch kubectl get po -A
执行上面的命令可以看到其中一个registry-proxy
的image一直无法拉取. 使用下面的命令找到这个pod具体使用的image名称:
➤ kubectl get po registry-proxy-5nr99 -n kube-system -o yaml | grep image
image: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-registry-proxy:0.4@sha256:1040f25a5273de0d72c54865a8efd47e3292de9fb8e5353e3fa76736b854f2da
imagePullPolicy: IfNotPresent
image: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-registry-proxy:0.4
imageID: docker-pullable://registry.cn-hangzhou.aliyuncs.com/google_containers/kube-registry-proxy@sha256:1040f25a5273de0d72c54865a8efd47e3292de9fb8e5353e3fa76736b854f2da
于是使用minikube
的手工拉取image命令:
$ minikube image load registry.cn-hangzhou.aliyuncs.com/google_containers/kube-registry-proxy:0.4
这样这个image就可以被拉取下来,用下面的命令查看image:
➤ minikube image ls
可以看到image已经拉取下来了:
此时使用kubectl
替换拉取失败的pod:
➤ kubectl get po registry-proxy-lkfz5 -n kube-system -o yaml | kubectl replace --force -f -
等待一会儿就可以看到相关pod被替换了:
此时再重新enable addon即可:
这样image拉取失败的问题就解决了.
补充内容:
有的时候直接两个images全都不能正常下载:
kube-system registry-proxy-kxfc6 0/1 ImagePullBackOff 0 91s
kube-system registry-szxb9 0/1 ImagePullBackOff 0 91s
此时我们可以一个一个收工拉取,先看registry-proxy-kxfc6
:
➤ kubectl get po registry-proxy-kxfc6 -n kube-system -o yaml | grep image
image: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-registry-proxy:0.4@sha256:1040f25a5273de0d72c54865a8efd47e3292de9fb8e5353e3fa76736b854f2da
imagePullPolicy: IfNotPresent
- image: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-registry-proxy:0.4@sha256:1040f25a5273de0d72c54865a8efd47e3292de9fb8e5353e3fa76736b854f2da
imageID: ""
message: Back-off pulling image "registry.cn-hangzhou.aliyuncs.com/google_containers/kube-registry-proxy:0.4@sha256:1040f25a5273de0d72c54865a8efd47e3292de9fb8e5353e3fa76736b854f2da"
手工拉取这个image:
➤ minikube image load registry.cn-hangzhou.aliyuncs.com/google_containers/kube-registry-proxy:0.4
然后拉取第二个image:
➤ kubectl get po registry-szxb9 -n kube-system -o yaml | grep image
image: docker.io/registry:2.8.1@sha256:83bb78d7b28f1ac99c68133af32c93e9a1c149bcd3cb6e683a3ee56e312f1c96
imagePullPolicy: IfNotPresent
image: registry@sha256:83bb78d7b28f1ac99c68133af32c93e9a1c149bcd3cb6e683a3ee56e312f1c96
imageID: docker-pullable://registry@sha256:83bb78d7b28f1ac99c68133af32c93e9a1c149bcd3cb6e683a3ee56e312f1c96
➤ minikube image load docker.io/registry:2.8.1
检查一下相关images都已经拉取了:
➤ minikube image ls | grep proxy
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-registry-proxy:0.4
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.26.3
weli@192:~/w/w/common|main⚡?
➤ minikube image ls | grep registry
registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner:v5
registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.9
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.26.3
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-registry-proxy:0.4
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.26.3
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.26.3
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.26.3
registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.6-0
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:v1.9.3
docker.io/library/registry:<none>
docker.io/library/registry:2.8.1
接下来替换两个pods:
➤ kubectl get po registry-szxb9 -n kube-system -o yaml | kubectl replace --force -f -
➤ kubectl get po registry-proxy-kxfc6 -n kube-system -o yaml | kubectl replace --force -f -
pod "registry-proxy-kxfc6" deleted
pod/registry-proxy-kxfc6 replaced
此时重新启动addon:
➤ minikube addons disable registry
🌑 'registry' 插件已被禁用
weli@192:~/w/liweinan.github.io|master⚡*
➤ minikube addons enable registry
💡 registry is an addon maintained by Google. For any concerns contact minikube on GitHub.
You can view the list of minikube maintainers at: https://github.com/kubernetes/minikube/blob/master/OWNERS
╭──────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Registry addon with docker driver uses port 62258 please use that instead of default port 5000 │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯
📘 For more information see: https://minikube.sigs.k8s.io/docs/drivers/docker
▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/kube-registry-proxy:0.4
▪ Using image docker.io/registry:2.8.1
🔎 Verifying registry addon...
🌟 启动 'registry' 插件
查看插件运行情况:
➤ minikube addons list | grep registry
| registry | minikube | enabled ✅ | Google |
| registry-aliases | minikube | disabled | 3rd party (unknown) |
| registry-creds | minikube | disabled | 3rd party (UPMC Enterpr
可以看到已经正常运行了。