Local yum

1.1Download packages(foo machine with internet)

This enable your prepare rpms for your dnf installation, the foo must has internet access, so download all rpm requires

1.1.1Config download repos

Before you can get all your rpm required, you need config the repo mirror on the foo which has internet access

1.1.1.1kubernetes repo

cat <<EOF > /etc/yum.repos.d/kubernetes.repo 
[kubernetes] 
name=Kubernetes 
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ 
enabled=1 
gpgcheck=0 
repo_gpgcheck=0 
EOF

1.1.2Download rpm

After repo configed on foo, we can now download rpm locally without installation, you should NOT install them before you download

mkdir /data
mkdir /data/yum-utils
mkdir /data/container-selinux
mkdir /data/createrepo
mkdir /data/repo
cd /data
dnf install --downloadonly --downloaddir=/data -y yum-utils
mv ./*.rpm ./yum-utils/

This is required by docker which is very special

dnf install --downloadonly --downloaddir=/data -y container-selinux
mv ./*.rpm ./container-selinux/
dnf install --downloadonly --downloaddir=/data -y createrepo
mv ./*.rpm ./createrepo/
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
dnf install --downloadonly --downloaddir=/data -y docker-ce-3:19.03.14-3.el8 docker-ce-cli-1:19.03.14-3.el8 containerd.io-1.3.9-3.1.el8 kubeadm
mv ./*.rpm ./repo/

1.1.3Package rpms

Tar your rpms for bar which has no internet access

tar -czvf yum.local.tar.gz ./
# download to local from terminal
sz yum.local.tar.gz

1.2Config local(bar machine without internet)

remove local mirrors

For some reason, you'd better remove repo exists, since they may slow down your dnf

rm -rf /etc/yum.repos.d/CentOS*
rm -rf /etc/yum.repos.d/docker-ce.repo
rm -rf /etc/yum.repos.d/kubernetes.repo

untar your gz

Upload tar to bar and untar

mkdir /data
cd /data
rz
tar -zxvf ./yum.local.tar.gz

install yum-utils

This is required for docker

dnf install ./yum-utils/*.rpm -y

install container-selinux

I don't know why, but we need it, or we got error when install docker/kubeadm

dnf install ./container-selinux/*.rpm -y

install createrepo

Use sha1 avoid dnf error in runtime

dnf install ./createrepo/*.rpm -y
createrepo -d -s sha1 /data/repo/

config createrepo

Local repo config, you can run dnf now

cat <<EOF > /etc/yum.repos.d/local.repo 
[local] 
name=Local 
baseurl=file:///data/repo/
enabled=1 
gpgcheck=0 
repo_gpgcheck=0 
EOF