1

前言

最近学习K8s需要安装kubeadm和依赖的镜像,记录下来分享给大家。

使用kubeadm.conf文件拉取镜像:

生成默认kubeadm.conf文件

kubeadm config print init-defaults > kubeadm.conf

默认为google的镜像仓库地址k8s.gcr.io,国内无法访问,需要把地址修改为国内的地址,这里使用阿里云的镜像仓库地址。

编辑kubeadm.conf,将imageRepository修改为registry.aliyuncs.com/google_containers,并确认Kubernetes版本是v1.19.4,和上面的镜像列表的版本保持一致

kubernetesVersion: v1.19.4

将imageRepository: k8s.gcr.io 修改为

imageRepository: registry.aliyuncs.com/google_containers

下载镜像:

kubeadm config images pull --config kubeadm.conf

或者docker pull指定版本直接拉取:

docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.19.4

docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.19.4

docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.19.4

docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.19.4

docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2

docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0

docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.7

修改tag:

docker tag registry.aliyuncs.com/google_containers/kube-apiserver:v1.19.4 k8s.gcr.io/kube-apiserver:v1.19.9

docker tag registry.aliyuncs.com/google_containers/kube-controller-manager:v1.19.4 k8s.gcr.io/kube-controller-manager:v1.19.4

docker tag registry.aliyuncs.com/google_containers/kube-scheduler:v1.19.4 k8s.gcr.io/kube-scheduler:v1.19.4

docker tag registry.aliyuncs.com/google_containers/kube-proxy:v1.19.4 k8s.gcr.io/kube-proxy:v1.19.4

docker tag registry.aliyuncs.com/google_containers/pause:3.2

docker tag registry.aliyuncs.com/google_containers/etcd:3.4.3-0

docker tag registry.aliyuncs.com/google_containers/coredns:1.6.7

手动拉取镜像

首先,我们看看需要安装哪些镜像,使用如下命令:

╭─root@kube-master ~
╰─# kubeadm config images list
W1122 01:44:17.606714   16720 configset.go:348] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
k8s.gcr.io/kube-apiserver:v1.19.4
k8s.gcr.io/kube-controller-manager:v1.19.4
k8s.gcr.io/kube-scheduler:v1.19.4
k8s.gcr.io/kube-proxy:v1.19.4
k8s.gcr.io/pause:3.2
k8s.gcr.io/etcd:3.4.13-0
k8s.gcr.io/coredns:1.7.0

从上面命令运行的结果可以看出来,我们需要kube-proxy、kube-apiserver、kube-controller-manager、kube-scheduler、etcd、coredns、pause镜像,因此我们就到docker hub上面去找,再这之前我们先来配置阿里镜像加速,如下所示:

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://xxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

注意:上面的xxx是我隐藏我的id写法,你们到阿里镜像上去,开通服务,复制成你们的就好!
image.png

加速设置好之后,接下来我们去docker hub去下载上面的依赖镜像,如图所示:
image.png
然后找到对应的1.19.4版本,如图所示:
image.png
点击复制右边的命令执行:

docker pull kubeimage/kube-apiserver-amd64:v1.19.4

下载完成之后,我们需要把标签改下`:

docker tag kubeimage/kube-apiserver-amd64:v1.19.4 k8s.gcr.io/kube-apiserver:v1.19.4
docker rmi kubeimage/kube-apiserver-amd64:v1.19.4

上面的两步操作的意思是先打个k8s.gcr.io/kube-apiserver:v1.19.4标签,然后再把kubeimage/kube-apiserver-amd64:v1.19.4删除。
依此类推,剩下的几个依赖包也是这样操作,我就不再赘述了,最后的如下所示:

╭─root@kube-master ~
╰─# docker images
REPOSITORY                           TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-proxy                v1.19.4             635b36f4d89f        10 days ago         118MB
k8s.gcr.io/kube-apiserver            v1.19.4             b15c6247777d        10 days ago         119MB
k8s.gcr.io/kube-controller-manager   v1.19.4             4830ab618586        10 days ago         111MB
k8s.gcr.io/kube-scheduler            v1.19.4             14cd22f7abe7        10 days ago         45.7MB
k8s.gcr.io/etcd                      3.4.13-0            0369cf4303ff        2 months ago        253MB
k8s.gcr.io/coredns                   1.7.0               bfe3a36ebd25        5 months ago        45.2MB
k8s.gcr.io/pause                     3.2                 80d28bedfe5d        9 months ago        683kB

总结

1、我这个是centos7上面安装的k8s,大家注意一下操作系统版本

引用

K8S安装过程笔记
Kubernetes/K8S 集群环境搭建
kubeadm k8s集群安装-kubeadm


Awbeci
3.1k 声望212 粉丝

Awbeci