deployment
尽管使用相同映像注册表的其他部署按预期工作,但我在minikube
使用本地注册表时收到“无法拉取映像”错误。
我的工作流程是从下面名为 Dockerfile 的文件中构建图像docker.collection
。
$ minikube start --insecure-registry localhost:5000 --memory 4096
$ docker build . -f docker.collection -t localhost:5000/collection:latest -t localhost:5000/collection:dev
$ docker push localhost:5000/collection
$ cat deployment.yaml | kubectl apply -f -
部署已按预期创建,但 pod 未启动,并且 minikube 仪表板显示:
无法拉取图像“localhost:5000 / collection:dev”:rpc 错误:代码 = 未知 desc = 守护进程的错误响应:未找到 localhost:5000 / collection:dev 的清单
我没有理由相信在构建或推送图像时存在任何问题,并且在主机上,我可以成功拉取......
$ docker pull localhost:5000/collection:dev
dev: Pulling from collection
Digest: sha256:8becfdd412f0b86ece8335aa5ee1aede75992d17f88739a28da5939eab28fde5
Status: Image is up to date for localhost:5000/collection:dev
我还应该检查什么?如何获取有关故障的更多详细信息?
进一步调试
我还检查过:
- minikube 节点可以访问
localhost:5000
:
$ minikube ssh
$ ping localhost:5000
PING localhost:5000 (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: seq=0 ttl=64 time=0.126 ms
64 bytes from 127.0.0.1: seq=1 ttl=64 time=0.041 ms
64 bytes from 127.0.0.1: seq=2 ttl=64 time=0.058 ms
^C
--- localhost:5000 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.041/0.075/0.126 ms
$
run
图像的最小部分以相同的方式失败:kubectl run coll-test --image=localhost:5000/collection:dev
产生相同的事件:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 24s default-scheduler Successfully assigned dev/coll-test-cf4467b8d-8vpdk to minikube
Normal BackOff 23s kubelet, minikube Back-off pulling image "localhost:5000/collection:dev"
Warning Failed 23s kubelet, minikube Error: ImagePullBackOff
Normal Pulling 7s (x2 over 23s) kubelet, minikube Pulling image "localhost:5000/collection:dev"
Warning Failed 7s (x2 over 23s) kubelet, minikube Failed to pull image "localhost:5000/collection:dev": rpc error: code = Unknown desc = Error response from daemon: manifest for localhost:5000/collection:dev not found
Warning Failed 7s (x2 over 23s) kubelet, minikube Error: ErrImagePull
- 图像的条目存在于 repo 中:
$ curl http://localhost:5000/v2/_catalog
{"repositories":["collection","foo","bar"]}
部署和 Dockerfile
# deployment.yaml
apiVersion: apps/v1beta2
kind: Deployment
metadata:
namespace: dev
name: collection
labels:
app: collection
spec:
replicas: 1
selector:
matchLabels:
app: collection
template:
metadata:
labels:
app: collection
spec:
containers:
- name: collection
image: "localhost:5000/collection:dev"
command: ["bash", "./collection_entry.sh"]
imagePullPolicy: Always
# docker.collection
FROM python:3
WORKDIR /code
COPY . /code/
RUN adduser --system --group --no-create-home celery
RUN mkdir /var/run/celery
RUN mkdir /var/log/celery
RUN chown celery:celery /var/run/celery
RUN chown celery:celery /var/log/celery
RUN chmod 755 /var/run/celery
RUN chmod 755 /var/log/celery
RUN pip3 -q install -r requirements.txt
USER celery
ENTRYPOINT ./collection_entry.sh
答案1
1)你必须跑eval $(minikube docker-env)
2)使用Minikube的Docker守护进程构建镜像
docker build -t collection .
3)在 pod 规范中设置镜像,就像 build 标签一样 -collection
4)将 imagePullPolicy 设置为 Never,否则 Kubernetes 将尝试下载镜像。
apiVersion: apps/v1beta2
kind: Deployment
metadata:
namespace: dev
name: collection
labels:
app: collection
spec:
replicas: 1
selector:
matchLabels:
app: collection
template:
metadata:
labels:
app: collection
spec:
containers:
- name: collection
image: "collection"
command: ["bash", "./collection_entry.sh"]
imagePullPolicy: Never