因为公司部署k8s的时候需要在现场的内网环境安装,所以需要在无网环境进行安装k8s集群,所以在现场规划设备和系统时,会优先确定操作系统版本,保证安装版本和操作系统的一致性
我们目前安装k8s版本,采用的操作系统为CentOS7.9,所以本地使用虚拟机(vmware或virtualBox)创建一个精简版的虚拟机。进行离线下载安装包
1.获取k8s和docer的版本
k8s&docker&Centos: [ftp://ftp.rhce.cc/k8s/*](ftp://ftp.rhce.cc/k8s/*)
2.获取yum源依赖包
前提:Centos虚拟机必须可以联网!!!要不后面都玩不下去的。
[root@master01 yum.repos.d]# rm -rf /etc/yum.repos.d/* ; wget -P /etc/yum.repos.d/ ftp://ftp.rhce.cc/k8s/*
--2022-05-05 21:15:13-- ftp://ftp.rhce.cc/k8s/*
=> ‘/etc/yum.repos.d/.listing’
Resolving ftp.rhce.cc (ftp.rhce.cc)... 101.37.152.41
Connecting to ftp.rhce.cc (ftp.rhce.cc)|101.37.152.41|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD (1) /k8s ... done.
==> PASV ... done. ==> LIST ... done.
3.# 创建本地仓库包
[root@master01 ~]# yum install --downloadonly --downloaddir=/root/k8sOfflineSetup/packages \
> createrepo
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
docker-ce-stable | 3.5 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
kubernetes | 1.4 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/8): epel/x86_64/group_gz | 96 kB 00:00:00
(2/8): docker-ce-stable/x86_64/primary_db | 76 kB 00:00:00
(3/8): docker-ce-stable/x86_64/updateinfo | 55 B 00:00:00
(4/8): kubernetes/primary | 108 kB 00:00:00
(5/8): extras/7/x86_64/primary_db | 246 kB 00:00:00
…………………………….
Total 938 kB/s | 1.1 MB 00:00:01
exiting because "Download Only" specified
实用工具
[root@master01 ~]# yum install --downloadonly --downloaddir=/root/k8sOfflineSetup/packages \
> yum-utils \
> nfs-utils \
> wget
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package wget-1.14-18.el7_6.1.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package nfs-utils.x86_64 1:1.3.0-0.68.el7.2 will be installed
--> Processing Dependency: libtirpc >= 0.2.4-0.7 for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: gssproxy >= 0.7.0-3 for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: rpcbind for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: quota for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: libnfsidmap for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: libevent for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: keyutils for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: libtirpc.so.1()(64bit) for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: libnfsidmap.so.0()(64bit) for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: libevent-2.0.so.5()(64bit) for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
………………..
Total 789 kB/s | 2.1 MB 00:00:02
exiting because "Download Only" specified
docker 依赖包
[root@master01 ~]# yum install --downloadonly --downloaddir=/root/k8sOfflineSetup/packages \
> device-mapper-persistent-data \
> lvm2
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
………………………
Total 983 kB/s | 3.8 MB 00:00:03
exiting because "Download Only" specified
docker
[root@master01 ~]# yum install --downloadonly --downloaddir=/root/k8sOfflineSetup/packages \
> docker-ce-19.03.5 \
> docker-ce-cli-19.03.5 \
> containerd.io
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
…………….
------------------------------------------------------------------------------------------------------------------------
Total 731 kB/s | 99 MB 00:02:18
exiting because "Download Only" specified
kubelet
[root@master01 ~]# yum install --downloadonly --downloaddir=/root/k8sOfflineSetup/packages \
> kubelet-1.21.0 \
> kubeadm-1.21.0 \
> kubectl-1.21.0
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package kubeadm.x86_64 0:1.21.0-0 will be installed
--> Processing Dependency: kubernetes-cni >= 0.8.6 for package: kubeadm-1.21.0-0.x86_64
--> Processing Dependency: cri-tools >= 1.13.0 for package: kubeadm-1.21.0-0.x86_64
---> Package kubectl.x86_64 0:1.21.0-0 will be installed
---> Package kubelet.x86_64 0:1.21.0-0 will be installed
--> Processing Dependency: socat for package: kubelet-1.21.0-0.x86_64
--> Processing Dependency: conntrack for package: kubelet-1.21.0-0.x86_64
--> Running transaction check
---> Package cri-tools.x86_64 0:1.23.0-0 will be installed
---> Package kubelet.x86_64 0:1.21.0-0 will be installed
--> Processing Dependency: conntrack for package: kubelet-1.21.0-0.x86_64
---> Package kubernetes-cni.x86_64 0:0.8.7-0 will be installed
---> Package socat.x86_64 0:1.7.3.2-2.el7 will be installed
--> Finished Dependency Resolution
Error: Package: kubelet-1.21.0-0.x86_64 (kubernetes)
Requires: conntrack
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
—————————————————
报错解决:
执行yum clean all
重新下载即可,如下:
[root@master01 ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base docker-ce-stable epel extras kubernetes updates
Cleaning up list of fastest mirrors
[root@master01 ~]# yum install --downloadonly --downloaddir=/root/k8sOfflineSetup/packages kubelet-1.21.0 kubeadm-1.21.0 kubectl-1.21.0
Loaded plugins: fastestmirror
Determining fastest mirrors
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
kubernetes | 1.4 kB 00:00:00
updates | 2.9 kB 00:00:00
—————————
------------------------------------------------------------------------------------------------------------------------
Total 863 kB/s | 65 MB 00:01:16
exiting because "Download Only" specified
获取kubeadm依赖镜像
获取kubeadm用到的镜像列表,这步操作要在一台安装了docker的环境上操作。拉取完成后打包复制到资源包/root/k8sOfflineSetup/images目录中。
从阿里云拉取镜像
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.21.0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.21.0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.21.0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.21.0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
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.5
[root@master01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver v1.21.0 4d217480042e 13 months ago 126MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy v1.21.0 38ddd85fe90e 13 months ago 122MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler v1.21.0 62ad3129eca8 13 months ago 50.6MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager v1.21.0 09708983cc37 13 months ago 120MB
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns 1.6.5 70f311871ae1 2 years ago 41.6MB
registry.cn-hangzhou.aliyuncs.com/google_containers/etcd 3.4.3-0 303ce5db0e90 2 years ago 288MB
registry.cn-hangzhou.aliyuncs.com/google_containers/pause 3.1 da86e6ba6ca1 4 years ago 742kB
重新tag镜像 —kubeadm调用的时候必须要是google的
docker images | grep registry.cn-hangzhou.aliyuncs.com/google_containers|sed 's/registry.cn-hangzhou.aliyuncs.com\/google_containers/k8s.gcr.io/'|awk '{print "docker tag " $3 " "$1":"$2}'|sh
删除旧镜像
docker images | grep registry.cn-hangzhou.aliyuncs.com/google_containers|awk '{print "docker rmi " $1":"$2}'|sh
在当前目录导出镜像为压缩包
docker save -o kube-controller-manager-v1.21.0.tar k8s.gcr.io/kube-controller-manager:v1.21.0
docker save -o kube-apiserver-v1.21.0.tar k8s.gcr.io/kube-apiserver:v1.21.0
docker save -o kube-scheduler-v1.21.0.tar k8s.gcr.io/kube-scheduler:v1.21.0
docker save -o kube-proxy-v1.21.0.tar k8s.gcr.io/kube-proxy:v1.21.0
docker save -o coredns-1.6.5.tar k8s.gcr.io/coredns:1.6.5
docker save -o etcd-3.4.3-0.tar k8s.gcr.io/etcd:3.4.3-0
docker save -o pause-3.1.tar [k8s.gcr.io/pause:3.1](http://k8s.gcr.io/pause:3.1)
**calico网络插件依赖镜像 **
从Quickstart for Calico on Kubernetes找到calico.yaml文件,命名为calico-v3.10.3.yaml保存到资源包/root/k8sOfflineSetup/plugins目录中。
注意:当前calico的版本3.10.3 已经很老的,可以选择新一点的版本,作者这边拉取的是3.22.2,操作如下:
[root@master01 ~]# curl https://projectcalico.docs.tigera.io/manifests/calico.yaml -O
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 217k 100 217k 0 0 10633 0 0:00:20 0:00:20 --:--:-- 11727
[root@master01 ~]#
[root@master01 ~]# ls
1.sh anaconda-ks.cfg coredns-1.6.5.tar k8sOfflineSetup kube-controller-manager-v1.21.0.tar kube-scheduler-v1.21.0.tar
2.sh calico.yaml etcd-3.4.3-0.tar kube-apiserver-v1.21.0.tar kube-proxy-v1.21.0.tar pause-3.1.tar
[root@master01 ~]# cat calico.yaml | grep -i "Image:"
image: docker.io/calico/cni:v3.22.2
image: docker.io/calico/cni:v3.22.2
image: docker.io/calico/pod2daemon-flexvol:v3.22.2
image: docker.io/calico/node:v3.22.2
image: docker.io/calico/kube-controllers:v3.22.2
[root@master01 ~]# cat calico.yaml | grep -i "Image:"|awk '{print "docker pull "$2}'|sh
在当前目录导出镜像为压缩包
docker save -o calico-cni-v3.22.2.tar calico/cni:v3.22.2
docker save -o calico-pod2daemon-flexvol-v3.22.2.tar calico/pod2daemon-flexvol:v3.22.2
docker save -o calico-node-v3.22.2.tar calico/node:v3.22.2
docker save -o calico-kube-controllers-v3.22.2.tar calico/kube-controllers:v3.22.2
同样拉取完成后打包复制到资源包/root/k8sOfflineSetup/images目录中。
[root@master01 ~]# mkdir -p /root/k8sOfflineSetup/images
[root@master01 ~]# mv *.tar /root/k8sOfflineSetup/images/
自此相应的安装包已下载并保存完毕