在 pod 中获取“ErrImageNeverPull”

问题:

我正在使用minikube测试部署并正在通过此链接

我的部署清单文件就像

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

即使我尝试通过从但得到相同的错误中Docker-Hub删除行来尝试从中提取图像。任何人都可以在这里帮助我确定哪里和哪里出了问题imagePullPolicy: Neverdeployment.yml

根据评论更新了问题

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

回答1:

在为 Kubernetes 使用单个 VM 时,重用 Minikube 的内置 Docker 守护程序很有用。重用内置守护程序意味着您不必在主机上构建 Docker 注册表并将映像推送到其中。相反,您可以在与 Minikube 相同的 Docker 守护程序中构建,从而加快本地实验。

以下命令具有魔力 eval $(minikube docker-env)

因为imagePullPolicy: Never图像需要在 minikube 节点上。

此答案提供详细信息

local-images-in minikube docker 环境

回答2:

您需要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
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论