非常感谢这篇文章解决了我的问题

k8s.gcr.io 镜像国内拉不下来解决思路

学习公开外部 IP 地址以访问集群中应用程序时,在这个最简单的“为一个在五个 pod 中运行的应用程序创建服务” 就遇到下载镜像失败,不是 ImagePullBackOff 就是 ErrImagePull

按照以上文章第一种方法解决了我的问题
记录一下

docker search后替换

  1. 原文中 image: gcr.io/google-samples/node-hello:1.0

  2. 尝试将 gcr.io 替换为 registry.aliyuncs.com ,或者registry.aliyuncs.com/google_containers 等,找不到!

  3. docker search node-hello:1.0

     NAME                                   DESCRIPTION                               STARS     OFFICIAL   AUTOMATED
     empiregeneral/node-hello               gcr.io/google_containers/node-hello:1.0   1                    [OK]
     tomtsang/dockerlibraryk8s-node-hello   gcr.io/google-samples/node-hello:1.0      0                    [OK]
     yumingc/node-hello                     node-hello:1.0                            0                    [OK]
     gongcqq/node-hello                     gcr.io/google-samples/node-hello:1.0      0  
    

    可以看到其中 tomtsang/dockerlibraryk8s-node-hello 和 gongcqq/node-hello 都是缓存了 gcr.io/google-samples/node-hello:1.0

  4. 替换load-balancer-example.yaml 中iamge

     image: tomtsang/dockerlibraryk8s-node-hello 
    

    然后
    kubectl delete -f load-balancer-example.yaml

    kubectl apply -f load-balancer-example.yaml

    耐心等待之后
    kubectl get pods

     NAME                           READY   STATUS    RESTARTS      AGE
     hello-world-76f58bd7bf-4fxr4   1/1     Running   0             5m38s
     hello-world-76f58bd7bf-7b4xd   1/1     Running   0             5m38s
     hello-world-76f58bd7bf-hxgrp   1/1     Running   0             5m38s
     hello-world-76f58bd7bf-sx44g   1/1     Running   0             5m38s
     hello-world-76f58bd7bf-t667v   1/1     Running   0             5m38s
    

    虽然很慢,但是,总算 ok 了!

换成 pull 之后 tag 的方法

  1. docker pull tomtsang/dockerlibraryk8s-node-hello

     Using default tag: latest
     latest: Pulling from tomtsang/dockerlibraryk8s-node-hello
     ...
     Digest: sha256:1768734b2a86b4101fb49abe284e1f2b295e620cf7a051d6be850c4a44adf733
     Status: Downloaded newer image for tomtsang/dockerlibraryk8s-node-hello:latest
     docker.io/tomtsang/dockerlibraryk8s-node-hello:latest
    
  2. 打 tag
    docker tag tomtsang/dockerlibraryk8s-node-hello gcr.io/google-samples/node-hello:1.0

  3. 确认一下
    docker images |grep node-hello

     tomtsang/dockerlibraryk8s-node-hello                                     latest    1e2404f3042c   4 years ago    644MB
     gcr.io/google-samples/node-hello                                         1.0       1e2404f3042c   4 years ago    644MB
    
  4. 原文中恢复为 image: gcr.io/google-samples/node-hello:1.0

    再来 apply 为什么会失败?那就先用前面替换的方法,后续再处理这个问题

       containers:
       - image: gcr.io/google-samples/node-hello
         imagePullPolicy: IfNotPresent
    

加上 imagePullPolicy: IfNotPresent ,也不对!?

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐