Minikube无法从本地仓库拉取镜像。

8
我运行了eval $(minikube docker-env),然后构建了一个Docker容器。当我在主机上运行docker images时,我可以看到这个镜像。当我运行minikube ssh然后运行docker images时,我也能看到它。
但是,当我尝试运行它时,Pod无法启动。kubectl describe pod显示:
14m     3m      7   kubelet, minikube   spec.containers{quoting-crab-customer-refresh-cache-cron}   Normal      Pulling         pulling image "personalisation-customer:latest"
14m     3m      7   kubelet, minikube   spec.containers{quoting-crab-customer-refresh-cache-cron}   Warning     Failed          Failed to pull image "personalisation-customer:latest": rpc error: code = 2 desc = Error: image library/personalisation-customer:latest not found
14m     2s      66  kubelet, minikube                                   Warning     FailedSync      Error syncing pod
14m     2s      59  kubelet, minikube   spec.containers{quoting-crab-customer-refresh-cache-cron}   Normal      BackOff         Back-off pulling image "personalisation-customer:latest"

我的imagePullPolicyAlways

这可能是什么原因?其他pod在本地工作正常。

5个回答

10

你并非从本地注册表中获取镜像,而是使用之前下载或本地构建的镜像,因为你指定了 imagePullPolicy: Always,它将始终尝试从注册表中拉取镜像。

你的镜像中不包含特定的Docker注册表personalisation-customer:latest,Docker会将其理解为index.docker.io/personalisation-customer:latest,但这是一个不存在于公共Docker注册表中的镜像。

因此,你有两个选择:imagePullPolicy: IfNotPresent 或将镜像上传到某个注册表。


1
您应该喝一杯啤酒了。我没有正确理解文档,而您拯救了我。谢谢您。 - The Dembinski

2
本地 Docker 缓存不是一个注册表。由于您将 iMagePullPolicy 设置为 Always,因此 Kubernetes 尝试从 Dockerhub(默认注册表)下载镜像。将其设置为 Never,这样 Kubernetes 就可以使用本地镜像。

2

我有同样的问题。问题是没有提到图像版本。我使用了

kubectl run testapp1 --image=<image> --image-pull-policy=IfNotPresent

替代,

kubectl run testapp1 --image=<image>:<version> --image-pull-policy=IfNotPresent

1
对于minikube,请按以下方式进行更改:
  1. Eval the docker env using: eval $(minikube docker-env)

  2. Build the docker image: docket build -t my-image

  3. Set the image name as only "my-image" in pod specification in your yaml file.

  4. Set the imagePullPolicy to Never in you yaml file. Here is the example:

    apiVersion:
    kind:
    metadata:
    spec:
      template:
         metadata:
            labels:
               app: my-image
      spec:
         containers:
           - name: my-image
           image: "my-image"
           imagePullPolicy: Never
    

0

您可以使用ssh连接到minikube

minikube ssh -p <profilename>

然后拉取图像

docker pull <image>

请确保 imagePullPolicy: IfNotPresent

然后运行您的部署


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接