为什么在我使用Kubernetes时,docker再次下载相同的图像

时间:2018-04-11 01:39:51

标签: docker kubernetes

我使用kbuernetes& docker在没有Internet的隔离环境中,我总是将图像保存到其他机器的.tar文件并加载到隔离环境,但有时kubernetes的Pod无法启动成功并说Pod是拉图像但网络不正常。 但我检查了泊坞窗的图像,图像已加载,为什么我还需要再次拉同一张图片?

这是docker的图片,MYSQL的图片已加载:

[root@localhost kubecfg]# docker images
REPOSITORY                                                       TAG                 IMAGE ID            CREATED             SIZE
quay.io/kubernetes-ingress-controller/nginx-ingress-controller   0.12.0              4a9cd8a2008a        3 weeks ago         230.5 MB
docker.io/mysql                                                  latest              5195076672a7        3 weeks ago         371.4 MB
gcr.io/google_containers/kube-apiserver-amd64                    v1.9.2              7109112be2c7        11 weeks ago        210.4 MB

这是kubernetes的错误日志

[root@localhost kubecfg]# kubectl describe pod mysql-vmwdw
Name:           mysql-vmwdw
Namespace:      default
Node:           localhost.localdomain/192.168.88.129
Start Time:     Mon, 02 Apr 2018 14:14:07 +0800
Labels:         app=mysql
Annotations:    <none>
Status:         Running
IP:             192.168.0.61
Controlled By:  ReplicationController/mysql
Containers:
  mysql:
    Container ID:   docker://9aa3128eaa1f330dfd0d6ebf732dca5a99ad49d7d6d4002a2384bdb03e056d7d
    Image:          docker.io/mysql
    Image ID:       docker-pullable://docker.io/mysql@sha256:691c55aabb3c4e3b89b953dd2f022f7ea845e5443954767d321d5f5fa394e28c
    Port:           3306/TCP
    State:          Waiting
      Reason:       ImagePullBackOff
    Last State:     Terminated
      Reason:       Error
      Exit Code:    1
      Started:      Tue, 10 Apr 2018 14:56:04 +0800
      Finished:     Wed, 11 Apr 2018 08:56:04 +0800
    Ready:          False
    Restart Count:  3
    Environment:
      MYSQL_ROOT_PASSWORD:  123456
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-s7kq2 (ro)
Conditions:
  Type           Status
  Initialized    True 
  Ready          False 
  PodScheduled   True 
Volumes:
  default-token-s7kq2:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-s7kq2
    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   SuccessfulMountVolume   19m                 kubelet, localhost.localdomain  MountVolume.SetUp succeeded for volume "default-token-s7kq2"
  Normal   SandboxChanged          19m (x12 over 19m)  kubelet, localhost.localdomain  Pod sandbox changed, it will be killed and re-created.
  Warning  FailedCreatePodSandBox  19m (x12 over 19m)  kubelet, localhost.localdomain  Failed create pod sandbox.
  Warning  Failed                  9m (x6 over 18m)    kubelet, localhost.localdomain  Failed to pull image "docker.io/mysql": rpc error: code = Unknown desc = Network timed out while trying to connect to https://index.docker.io/v1/repositories/library/mysql/images. You may want to check your internet connection or if you are behind a proxy.
  Warning  Failed                  4m (x41 over 18m)   kubelet, localhost.localdomain  Error: ImagePullBackOff

它说:“无法提取图片”docker.io/mysql“:rpc错误:code = Unknown desc =网络在尝试连接https://index.docker.io/v1/repositories/library/mysql/images时超时。您可能需要检查一下互联网连接或如果您在代理服务器后面。“

我加载了图像,为什么docker会再次拉出相同的图像?我该怎么做才能解决问题?

3 个答案:

答案 0 :(得分:1)

目前尚不清楚指定的imagePullPolicy是什么。在您的情况下,它应该是Never

https://kubernetes.io/docs/concepts/containers/images/#pre-pulling-images

答案 1 :(得分:1)

您正在为图片使用:latest标记。当图片代码为latest时,kubernetes会将imagePullPolicy设置为Always。有关详细信息,请see the official doc

您可以将标记更改为其他标记(例如docker.io/mysql:8.0),或者只需将imagePullPolicy自己指定为Never

答案 2 :(得分:1)

在您通过

创建部署的情况下
 kubectl run mysql --image=docker.io/mysql --imagePullPolicy=Never

应该解决问题。或者,您可以在部署的imagePullPolicy规范中将Never设置为IfNotPresentyaml以修复此错误。