在 pods 中获得 "ErrImageNeverPull"

Getting "ErrImageNeverPull" in pods

我正在使用 minikube 来测试部署并正在经历 this link

我的部署清单文件就像

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: webapp
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: webapp
    spec:
      containers:
      - name: webapp
        imagePullPolicy: Never # <-- here we go!
        image: sams
        ports:
        - containerPort: 80

然后当我尝试执行以下命令时得到输出

user@usesr:~/Downloads$ kubectl create -f mydeployment.yaml --validate=false

deployment "webapp" created

user@user:~/Downloads$ kubectl get deployments

NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
----     --------   -------   ----------   ---------   ----              
webapp    1         1         1            0           9s

user@user:~/Downloads$ kubectl get pods

NAME                     READY     STATUS              RESTARTS   AGE
----     --------   -------   ----------   ---------   ----              
webapp-5bf5bd94d-2xgs8   0/1       ErrImageNeverPull   0          21s

我试图通过从 deployment.yml 中删除行 imagePullPolicy: Never 来从 Docker-Hub 中提取图像,但得到了同样的错误。 谁能帮我确定哪里出了问题?

根据评论更新了问题

kubectl describe pod $POD_NAME
Name:           webapp-5bf5bd94d-2xgs8
Namespace:      default
Node:           minikube/10.0.2.15
Start Time:     Fri, 31 May 2019 14:25:41 +0530
Labels:         app=webapp
            pod-template-hash=5bf5bd94d
Annotations:    <none>
Status:         Pending
IP:             172.17.0.4
Controlled By:  ReplicaSet/webapp-5bf5bd94d
Containers:
  webapp:
    Container ID:   
    Image:          sams
    Image ID:       
    Port:           80/TCP
    State:          Waiting
      Reason:       ErrImageNeverPull
    Ready:          False
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-wf82w (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  default-token-wf82w:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-wf82w
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
             node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason             Age                From               Message
  ----     ------             ----               ----               -------
  Normal   Scheduled          18m                default-scheduler  Successfully assigned default/webapp-5bf5bd94d-2xgs8 to minikube
  Warning  ErrImageNeverPull  8m (x50 over 18m)  kubelet, minikube  Container image "sams" is not present with pull policy of Never
  Warning  Failed             3m (x73 over 18m)  kubelet, minikube  Error: ErrImageNeverPull    

docker images:

REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE
----------                             ---                 --------            -------             ----
<none>                                 <none>              723ce2b3d962        3 hours ago         1.91GB
bean_ben501/sams                       latest              c7c4a04713f4        4 hours ago         278MB
sams                                   latest              c7c4a04713f4        4 hours ago         278MB
sams                                   v1                  c7c4a04713f4        4 hours ago         278MB
<none>                                 <none>              b222da630bc3        4 hours ago         1.91GB
mcr.microsoft.com/dotnet/core/sdk      2.2-stretch         e4747ec2aaff        9 days ago          1.74GB
mcr.microsoft.com/dotnet/core/aspnet   2.2-stretch-slim    f6d51449c477        9 days ago          260MB

When using a single VM for Kubernetes, it’s useful to reuse Minikube’s built-in Docker daemon. Reusing the built-in daemon means you don’t have to build a Docker registry on your host machine and push the image into it. Instead, you can build inside the same Docker daemon as Minikube, which speeds up local experiments.

下面的命令很神奇 eval $(minikube docker-env) 然后你必须重新构建你的镜像。

对于 imagePullPolicy: Never,图像需要位于 minikube 节点上。

local-images-in minikube docker environment

您需要在当前终端 window 中使用 eval $(minikube docker-env)。这将为当前会话使用 minikube docker-env。

镜像需要在minikube虚拟机上。所以现在你需要重新构建你的形象。

但是要小心!构建镜像时不要使用sudo。它不会使用 minikube docker-env.

关闭终端后,一切都会像以前一样。

然后,在清单文件中使用 imagePullPolicy: Never 以使用本地映像注册表。

示例:

apiVersion: v1
kind: Pod
metadata:
  name: demo
spec:
  containers:
  - name: demo
    image: demo
    imagePullPolicy: Never # <-- here
    ports:
    - containerPort: 3000

检查你的

kubectl version 

确保客户端版本与守护程序(服务器)版本是最新的。阅读以下来自官方文档的引述

您使用的 kubectl 版本必须在集群的一个次要版本差异之内。例如,v1.2 客户端应该与 v1.1、v1.2 和 v1.3 master 一起工作。使用最新版本的 kubectl 有助于避免不可预见的问题。

如果您正在查看此问题,但使用的是 k3s,而不是给定的 minikube 解决方案,您可以使用 this solution, or from the rancher docs。在 k3s.

的设置中添加 --docker 标记

curl -sfL https://get.k3s.io | sh -s - --docker