使用kubeadm安装kubernetes(国内镜像下载)

原创
2021/11/25 16:16
阅读数 23

主机环境 Ubuntu Linux

安装 kubeadm

https://kubernetes.io/zh/docs/setup/production-environment/tools/kubeadm/install-kubeadm/

sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

创建集群

https://kubernetes.io/zh/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/

kubeadm init

国内环境,可能会拉取不到镜像的解决方法

添加阿里云镜像源(Debian 或 Ubuntu)

$ apt-get update && apt-get install -y apt-transport-https
$ curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - 
$ cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF  
$ apt-get update
$ apt-get install -y kubelet kubeadm kubectl

查询k8s相关镜像

$ kubeadm config images list
k8s.gcr.io/kube-apiserver:v1.22.4
k8s.gcr.io/kube-controller-manager:v1.22.4
k8s.gcr.io/kube-scheduler:v1.22.4
k8s.gcr.io/kube-proxy:v1.22.4
k8s.gcr.io/pause:3.5
k8s.gcr.io/etcd:3.5.0-0
k8s.gcr.io/coredns/coredns:v1.8.4

阿里云仓库的镜像名称是:

kube-apiserver:v1.22.4
kube-controller-manager:v1.22.4
kube-scheduler:v1.22.4
kube-proxy:v1.22.4
pause:3.5
etcd:3.5.0-0
coredns:v1.8.4

所以对镜像名称进行截取后,重新拼接阿里云镜像仓库地址

$ for i in `kubeadm config images list`; do docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/${i:11}; done

重新命名镜像名称,给 kubeadm 使用

registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.22.4
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.22.4
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.22.4
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.22.4
registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.0-0
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:v1.8.4
registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.5
$ for i in `docker images | grep google_containers |awk '{print $1":"$2}'`; do echo k8s.gcr.io/${i:52} && docker tag $i k8s.gcr.io/${i:52} && docker rmi $i; done


k8s.gcr.io/kube-apiserver            v1.22.4   8a5cc299272d   6 days ago     128MB
k8s.gcr.io/kube-controller-manager   v1.22.4   0ce02f92d3e4   6 days ago     122MB
k8s.gcr.io/kube-scheduler            v1.22.4   721ba97f54a6   6 days ago     52.7MB
k8s.gcr.io/kube-proxy                v1.22.4   edeff87e4802   6 days ago     104MB
hello-world                          latest    feb5d9fea6a5   2 months ago   13.3kB
k8s.gcr.io/etcd                      3.5.0-0   004811815584   5 months ago   295MB
k8s.gcr.io/coredns                   v1.8.4    8d147537fb7d   5 months ago   47.6MB
k8s.gcr.io/pause                     3.5       ed210e3e4a5b   8 months ago   683kB

重新命名 coredns 镜像,因为 kubeadm 需要的名称为 k8s.gcr.io/coredns/coredns

$ docker tag k8s.gcr.io/coredns:v1.8.4 k8s.gcr.io/coredns/coredns:v1.8.4
$ docker rmi k8s.gcr.io/coredns:v1.8.4

查看 kubeadm 所需要的镜像

$ docker images
k8s.gcr.io/kube-apiserver            v1.22.4   8a5cc299272d   6 days ago     128MB
k8s.gcr.io/kube-controller-manager   v1.22.4   0ce02f92d3e4   6 days ago     122MB
k8s.gcr.io/kube-scheduler            v1.22.4   721ba97f54a6   6 days ago     52.7MB
k8s.gcr.io/kube-proxy                v1.22.4   edeff87e4802   6 days ago     104MB
hello-world                          latest    feb5d9fea6a5   2 months ago   13.3kB
k8s.gcr.io/etcd                      3.5.0-0   004811815584   5 months ago   295MB
k8s.gcr.io/coredns/coredns           v1.8.4    8d147537fb7d   5 months ago   47.6MB
k8s.gcr.io/pause                     3.5       ed210e3e4a5b   8 months ago   683kB

最后初始化集群

$ kubeadm init
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部