Why docker download the same image again while I using Kubernetes

4/11/2018

I using kbuernetes & docker in a isolate environment without Internet, and I always pull image and save to .tar file in other machine and load to the isolate environment, but sometimes kubernetes's Pod cann't launch successful and says the Pod is pull image but network is not ok. But I check docker's image, the image has loaded, why I also need to pull the same image again?

this is docker's image, MYSQL's image has loaded:

[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

this is kubernetes's error log

[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

It says: " 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."

I had load the image, why docker would pull the same image again? And what should I do to resolve the problem?

-- macroxmu
docker
kubernetes

3 Answers

4/11/2018

You are using :latest tag for the image. When the image tag is latest, kubernetes will set imagePullPolicy to Always. For details, see the official doc.

You can either change the tag to something else (eg, docker.io/mysql:8.0) or, simply you can specify imagePullPolicy yourself to Never.

-- Abdullah Al Maruf - Tuhin
Source: StackOverflow

4/11/2018

It is not clear what is the imagePullPolicy specified. In your case it should be Never.

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

-- Mohit Mutha
Source: StackOverflow

4/11/2018

In your case creating the deployment by

 kubectl run mysql --image=docker.io/mysql --imagePullPolicy=Never

should solve the problem. Alternatively you could set imagePullPolicy to Never or IfNotPresent in the yaml spec of your deployment to fix this error.

-- rmb
Source: StackOverflow