为什么在此Kubernetes部署中出现ErrImagePull错误? [英] Why am I getting an ErrImagePull error in this Kubernetes deployment?
问题描述
我正在尝试使用Minikube,Docker Registry和演示节点项目创建本地Kubernetes部署.
I'm trying to create a local Kubernetes deployment using Minikube, Docker Registry, and a demo node project.
我做的第一件事是安装Docker v 1.12.3,然后是Minikube v0.12.2.
The first thing I did was install Docker v 1.12.3, then Minikube v0.12.2.
然后,我通过运行此命令(通过本教程)创建了Docker Registry容器,仅运行了下面的第一个命令)
Then I created a Docker Registry container by running this command (via this tutorial, only running the first command below)
docker run -d -p 5000:5000 --name registry registry:2
接下来,我运行此minikube命令以创建本地kubernetes集群:
Next I ran this minikube command to create a local kubernetes cluster:
minikube start --vm-driver="virtualbox" --insecure-registry="0.0.0.0:5000"
我的项目结构如下:
.
├── Dockerfile
└── server.js
我的Dockerfile看起来像这样:
and my Dockerfile looks like this:
FROM node:7.1.0
EXPOSE 8080
COPY server.js .
CMD node server.js
然后,我构建了自己的docker映像并将其推送到我的私有存储库:
Then I built my own docker image and pushed it to my private repository:
docker build -t hello-node .
docker tag hello-node localhost:5000/hello-node
docker push localhost:5000/hello-node
然后我尝试使用此命令运行部署:
Then I tried to run a deployment with this command:
kubectl run hello-node --image=localhost:5000/hello-node --port=8888
但是我得到了:
sudo kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default hello-node-3745105022-gzs5a 0/1 ErrImagePull 0 11m
kube-system kube-addon-manager-minikube 1/1 Running 4 10d
kube-system kube-dns-v20-2x64k 3/3 Running 12 10d
kube-system kubernetes-dashboard-mjpjv 1/1 Running 4 10d
我认为我可能会缺少某种Docker注册表身份验证,但是在进行谷歌搜索时,找不到我能理解的东西.有人可以指出正确的方向吗?
I think I might be missing some kind of docker registry authentication, but as I'm googling I can't find something that I understand. Could someone please point me in the right direction?
修改
在使用ssh访问kubernetes VM上的bash
并使用以下命令从我的私有注册表中提取hello-node
映像后:
After using ssh to access bash
on the kubernetes VM and pull the hello-node
image from my private registry by using this command:
minikube ssh
Boot2Docker version 1.11.1, build master : 901340f - Fri Jul 1
22:52:19 UTC 2016
Docker version 1.11.1, build 5604cbe
docker@minikube:~$ sudo docker pull localhost:5000/hello-node
Using default tag: latest
Pulling repository localhost:5000/hello-node
Error while pulling image: Get http://localhost:5000/v1/repositories/hello-node/images: dial tcp 127.0.0.1:5000: getsockopt: connection refused
localhost:5000
是在kubernetes主机VM中使用的正确地址吗?
Is localhost:5000
the correct address to use within the kubernetes host VM?
推荐答案
看起来您正在主机上运行注册表.实际上,您需要在VM内运行注册表.您可以通过先运行以下命令将docker客户端指向minikube VM中的docker守护进程
eval $(minikube docker-env)
在您的外壳中.
It looks like you're running the registry on the host. In fact, you need to run the registry inside the VM. You can point your docker client to the docker daemon inside the minikube VM by running this command first
eval $(minikube docker-env)
in your shell.
然后,您可以在主机上运行docker build命令,但它将在VM内部构建.
Then, you can run the docker build command on your host, but it will build inside the VM.
实际上,如果您的目标是仅运行映像的本地版本,则应运行eval $(minikube docker-env)
以指向VM中的docker守护程序,并在pod YAML中设置imagePullPolicy: IfNotPresent
.然后,kubernetes将使用本地构建的映像(如果可用).
In fact, if your goal is to simply run the local version of your images, you should run the eval $(minikube docker-env)
to point towards the docker daemon in your VM, and set the imagePullPolicy: IfNotPresent
in your pod YAML. Then, kubernetes will use a locally built image if available.
这篇关于为什么在此Kubernetes部署中出现ErrImagePull错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!