Error ImagePull failed to pull image k8s.gcr.io
环境
在国内主机(阿里云centos7)使用kubeadm init 初始化k8s集群失败
Error
[ERROR ImagePull]: failed to pull image k8s.gcr.io/kube-apiserver:v1.13.4: 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
原因
被墙,需外网
解决
两种方式,一种是FQ,一种是不从k8s.gcr.io
拉取镜像
FQ
这里不介绍
换源拉取镜像
查看所需要的镜像与版本
kubeadm config images list
[root@k8s-master ~]# kubeadm config images list
W0810 15:40:17.825258 8091 version.go:98] could not fetch a Kubernetes version from the internet: unable to get URL "https://dl.k8s.io/release/stable-1.txt": Get https://dl.k8s.io/release/stable-1.txt: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
W0810 15:40:17.825361 8091 version.go:99] falling back to the local client version: v1.15.2
k8s.gcr.io/kube-apiserver:v1.15.2
k8s.gcr.io/kube-controller-manager:v1.15.2
k8s.gcr.io/kube-scheduler:v1.15.2
k8s.gcr.io/kube-proxy:v1.15.2
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd:3.3.10
k8s.gcr.io/coredns:1.3.1
编写执行脚本
vim pull_k8s_images.sh
set -o errexit
set -o nounset
set -o pipefail
KUBE_VERSION=v1.15.2
KUBE_PAUSE_VERSION=3.1
ETCD_VERSION=3.3.10
DNS_VERSION=1.3.1
GCR_URL=k8s.gcr.io
# mirrorgooglecontainers/alleyj
DOCKERHUB_URL=mirrorgooglecontainers
images=(
kube-proxy:${KUBE_VERSION}
kube-scheduler:${KUBE_VERSION}
kube-controller-manager:${KUBE_VERSION}
kube-apiserver:${KUBE_VERSION}
pause:${KUBE_PAUSE_VERSION}
etcd:${ETCD_VERSION}
coredns:${DNS_VERSION}
)
for imageName in ${images[@]} ; do
docker pull $DOCKERHUB_URL/$imageName
docker tag $DOCKERHUB_URL/$imageName $GCR_URL/$imageName
docker rmi $DOCKERHUB_URL/$imageName
done
# 授予执行权限
chmod +x ./pull_k8s_images.sh
# 执行
./pull_k8s_images.sh
如果使用alliy仓库,可能会要求你登录,如果没有,去https://hub.docker.com注册账号
[root@k8s-master docker]# ./pull_k8s_images.sh
Error response from daemon: pull access denied for alleyj/kube-proxy, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
[root@k8s-master docker]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username:
要是还不行就试试另一个
mirrorgooglecontainers
如果使用
mirrorgooglecontainers
仓库可能会找不到部分镜像(没有更新)
[root@k8s-master docker]# ./pull_k8s_images.sh
v1.15.2: Pulling from mirrorgooglecontainers/kube-proxy
Digest: sha256:e580a74ffc64ec0a80b2917e6e877ea53fdc269d92f7513bdff05b1902124c5c
Status: Downloaded newer image for mirrorgooglecontainers/kube-proxy:v1.15.2
docker.io/mirrorgooglecontainers/kube-proxy:v1.15.2
Untagged: mirrorgooglecontainers/kube-proxy:v1.15.2
Untagged: mirrorgooglecontainers/kube-proxy@sha256:e580a74ffc64ec0a80b2917e6e877ea53fdc269d92f7513bdff05b1902124c5c
Error response from daemon: manifest for mirrorgooglecontainers/kube-scheduler:v1.15.2 not found: manifest unknown: manifest unknown
可以不拉取v1.15.2
的版本
kubeadm config images list --kubernetes-version 1.15.1
当然,在执行kubeadm init时,也要带上参数
kubeadm init --kubernetes-version 1.15.1
[root@localhost docker]# kubeadm config images list --kubernetes-version 1.15.1
k8s.gcr.io/kube-apiserver:v1.15.1
k8s.gcr.io/kube-controller-manager:v1.15.1
k8s.gcr.io/kube-scheduler:v1.15.1
k8s.gcr.io/kube-proxy:v1.15.1
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd:3.3.10
k8s.gcr.io/coredns:1.3.1
[root@localhost docker]#
# 修改版本号
vim pull_k8s_images.sh
./pull_k8s_images.sh
最后可以通
docker images
查看
还有一种方法是手动去docker hub上找,例如mirrorgooglecontainers
上没有v1.15.2
,但是我们可以找到v1.15.2-beta.0
要是mirrorgooglecontainers
实在没有,换个仓库找找