【问题标题】:run `minikube start`, cannot pull k8s.gcr images, but `docker pull` can do运行 `minikube start`,无法拉取 k8s.gcr 图像,但 `docker pull` 可以
【发布时间】:2019-07-15 03:35:12
【问题描述】:

我正在尝试通过minikube运行k8s,我按照offical article,当我尝试minikube start的命令时,错误说我无法拉取docker镜像(k8s.gcr):

tianyu@ubuntu:~$ minikube start
????  minikube v0.34.1 on linux (amd64)
????  Creating virtualbox VM (CPUs=2, Memory=2048MB, Disk=20000MB) ...
????  "minikube" IP address is 192.168.99.100
????  Found network options:
    ▪ HTTP_PROXY=http://127.0.0.1:35033
    ▪ HTTPS_PROXY=http://127.0.0.1:35033/
    ▪ NO_PROXY=localhost,127.0.0.0/8,::1
????  Configuring Docker as the container runtime ...
✨  Preparing Kubernetes environment ...
????  Pulling images required by Kubernetes v1.13.3 ...
❌  Unable to pull images, which may be OK: running cmd: sudo kubeadm config images pull --config /var/lib/kubeadm.yaml: command failed: sudo kubeadm config images pull --config /var/lib/kubeadm.yaml
stdout: 
stderr: failed to pull image "k8s.gcr.io/kube-apiserver:v1.13.3": output: Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
, error: exit status 1
: Process exited with status 1
????  Launching Kubernetes v1.13.3 using kubeadm ... 
????  Error starting cluster: kubeadm init: 
sudo /usr/bin/kubeadm init --config /var/lib/kubeadm.yaml --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests --ignore-preflight-errors=DirAvailable--data-minikube --ignore-preflight-errors=Port-10250 --ignore-preflight-errors=FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml --ignore-preflight-errors=FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml --ignore-preflight-errors=FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml --ignore-preflight-errors=FileAvailable--etc-kubernetes-manifests-etcd.yaml --ignore-preflight-errors=Swap --ignore-preflight-errors=CRI 

[init] Using Kubernetes version: v1.13.3
[preflight] Running pre-flight checks
    [WARNING Service-Docker]: docker service is not enabled, please run 'systemctl enable docker.service'
    [WARNING Swap]: running with swap on is not supported. Please disable swap
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
error execution phase preflight: [preflight] Some fatal errors occurred:
    [ERROR ImagePull]: failed to pull image k8s.gcr.io/kube-apiserver:v1.13.3: output: Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
, error: exit status 1
    [ERROR ImagePull]: failed to pull image k8s.gcr.io/kube-controller-manager:v1.13.3: output: Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
, error: exit status 1
    [ERROR ImagePull]: failed to pull image k8s.gcr.io/kube-scheduler:v1.13.3: output: Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
....
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`

: Process exited with status 1

我在中国,所以我通过 vpn 访问 gcr docker hub。 我关注了这个链接(https://docs.docker.com/config/daemon/systemd/#httphttps-proxy),所以我可以通过 docker 拉取图像(k8s.gcr)。信息如下:

tianyu@ubuntu:~$ sudo docker pull k8s.gcr.io/kube-apiserver:v1.13.3
v1.13.3: Pulling from kube-apiserver
73e3e9d78c61: Pull complete 
d261e2f8ca5b: Pull complete 
Digest: sha256:cdb80dc78f3c25267229012a33800b8b203e8e8b9fa59f9fe93e156cc859f89c
Status: Downloaded newer image for k8s.gcr.io/kube-apiserver:v1.13.3
tianyu@ubuntu:~$ sudo docker pull k8s.gcr.io/kube-controller-manager:v1.13.3
v1.13.3: Pulling from kube-controller-manager
73e3e9d78c61: Already exists 
846fc1deb4d7: Pull complete 
Digest: sha256:408350880946f037be82d6ad2ed7dc3746b221932f0eeb375aef935d62392031
Status: Downloaded newer image for k8s.gcr.io/kube-controller-manager:v1.13.3

为什么我不能通过 minikube 拉取图像?

感谢您的宝贵时间。

【问题讨论】:

标签: docker kubernetes minikube


【解决方案1】:

我也在中国。请使用参数启动 minikube

--docker-env HTTP_PROXY=http://10.0.2.2:35033 --docker-env HTTPS_PROXY=http://10.0.2.2:35033

【讨论】:

【解决方案2】:

如果您使用的是 mac,以下将起作用。 minikube start --vm-driver=virtualbox 为此,您必须先下载并安装 VirtualBox。

【讨论】:

    【解决方案3】:

    Minikube 1.0 releases in March 2019现在正式包括:

    添加--image-repository 标志,以便用户可以选择备用存储库镜像

    关注PR 3714

    此 PR 旨在为一些访问 gcr.io 有困难的用户支持新的命令行参数 --image-repository。

    通过 withregistry.cn-hangzhou.aliyuncs.com/google_containers 测试。

    这是阿里云人维护的gcr.io的著名镜像之一。
    我使用此镜像进行了验证,因此它应该可以按预期工作(v1.13.3)。

    如果在用户环境中无法访问所提供的镜像,我们可能会使用--image-repository 作为最终解决方法。
    我同意像 APT / pacman 世界一样维护镜像列表也有帮助, 甚至在设置过程中尝试通过 IP 地址猜测可靠的镜像。

    --registry-mirror 只影响那些没有存储库前缀的镜像 - 来自 Docker 官方注册表的镜像。
    它不适用于来自私有注册表的图像,例如 gcr.io/kube-proxy。对于私有镜像,docker 仍然会去私有注册中心获取它们。

    如果您使用--registry-mirror 设置 minikube,它可能适用于使用 ubuntu/18.04 的 pod/deployment,但不适用于 gcr.io/ - 您需要从引用中清除“gcr.io/”使其看起来像官方注册表中的图像。
    对于后一种情况,可以使用--registry-mirror https://private_server --image-registry [private_server/]google_containers

    【讨论】:

      【解决方案4】:

      --register-mirror=registry.cn-hangzhou.aliyuncs.com/google_containers 对我不起作用。还有--image-mirror-country=cn

      但是--docker-env HTTP_PROXY=http://10.0.2.2:35033 --docker-env HTTPS_PROXY=http://10.0.2.2:35033 对我有用。

      我配置了代理真的很奇怪。我可以通过 google.com ping 通。 但是不能直接拉图。

      【讨论】:

        猜你喜欢
        • 2023-04-03
        • 2020-06-29
        • 2022-08-05
        • 2019-12-08
        • 1970-01-01
        • 1970-01-01
        • 2019-11-24
        • 2019-09-30
        • 2020-01-08
        相关资源
        最近更新 更多