离线部署的两种方法:

  • 方法一:直接将相关安装依赖包上传到各个节点
  • 方法二:搭建自主可控的软件仓库和镜像仓库(repo节点)

此篇主要记录方法二的实现步骤,参考思路如下:

离线部署方案二:搭建自主可控的软件仓库和镜像仓库(repo节点)

一、整体思路

即:在局域网内(k8s集群之外),搭建一台仓库节点repo,作为软件/镜像仓库,其他节点从它这里获取资源。
部分参考:https://blog.csdn.net/Harry_z666/article/details/128564336(中间有小坑,已修改)

二、安装环境说明

虚拟机:VMware Pro 16
操作系统:CentOS7.x-86_x64
repo:192.168.253.172
master:192.168.253.173
node1:192.168.253.174
node2:192.168.253.175

三、建立自主可控的软件仓库

最开始全部节点,都要关闭防火墙:

systemctl stop firewalld
systemctl disable firewalld
sed -i 's/enforcing/disabled/' /etc/selinux/config
sed -ri 's/.*swap.*/#&/' /etc/fstab

1. 整体思路

整体思路:在一台内网机器(repo)上构建一个yum仓库,并在所有节点上配置yum访问该yum仓库。存在两个方案:

  • 方案一:在repo节点中下载k8s所需的软件包及其所有依赖,并复制到内网上述yum仓库中;
  • 方案二:repo节点下载一个Centos完整镜像包(包含了常用的rpm包),将其挂载出来,再利用nginx去访问即可。

本篇文章使用方案一进行。

2. repo节点

补充:使用yum下载命令 yum install ${软件} --downloadonly --downloaddir=${指定目录}
eg:
yum -y install httpd --downloadonly --downloaddir=/data/repo
yum -y install autossh --downloadonly --downloaddir=/data/repo

下载所需工具依赖包

yum install --downloadonly --downloaddir=/opt/repo ntpdate wget httpd createrepo vim telnet netstat lrzsz

配置国内yum源

yum clean all
yum makecache
yum install -y wget
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum install --downloadonly --downloaddir=/opt/repo docker-ce

配置国内kubernetes源

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

下载好kubelet-1.23.0 kubeadm-1.23.0 kubectl-1.23.0所需要的依赖包

yum install --downloadonly --downloaddir=/opt/repo  kubelet-1.23.0 kubeadm-1.23.0 kubectl-1.23.0
wget --no-check-certificate https://docs.projectcalico.org/v3.25/manifests/calico.yaml
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml

将下载软件包的目录制作为yum源

createrepo /opt/repo/
createrepo --update /opt/repo
cd /opt/repo
yum install -y httpd
systemctl start httpd && systemctl enable httpd
ln -s /opt/repo /var/www/html/
cd ~

3. k8s集群节点

在每个节点创建离线环境repo源

cat > /etc/yum.repos.d/local.repo << EOF
[local]
name=local
baseurl=http://192.168.253.172/repo/
enabled=1
gpgcheck=0
EOF
yum clean all && yum makecache

测试

yum -y install docker-ce

其余安装步骤,见之前普通安装k8s集群教程:【k8s】VMware16搭建k8s集群(亲试无坑)

四、建立自主可控的镜像仓库

1. 整体思路

同样在repo节点上构建一个镜像仓库,并在所有节点上配置docker访问该镜像仓库。在能连接公网的repo节点上 ,将所需的各镜像复制到内网,并部署到上述镜像仓库。有两种方案:

  • 方案一:使用docker官方提供的Registry镜像建立镜像仓库
  • 方案二:harbor镜像仓库

2. 方案一:Registry镜像建立镜像仓库

安装docker(仓库和节点)

yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io -y

启动docker(仓库和节点)

systemctl start docker
systemctl status docker

使用registry制作镜像仓库(仓库)

docker pull registry
docker save -o registry.tar registry
docker load -i registry.tar
docker run -d -p 5000:5000 --restart=always --name registry registry

修改配置文件(仓库和节点)

vim /etc/docker/daemon.json
{
"registry-mirrors":["https://registry.docker-cn.com"],
"insecure-registries":["192.168.253.172:5000"]
}

重启docker(仓库和节点)

systemctl restart docker

拉取镜像(仓库)

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

下载镜像(仓库)

docker save -o kube-apiserver.tar registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver
docker load -i kube-apiserver.tar

重新打tag(仓库)

docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.21.0 192.168.253.172:5000/kube-apiserver:hd

上传镜像(仓库)

docker push 192.168.253.172:5000/kube-apiserver:hd

拉取镜像(节点)

docker pull 192.168.253.172:5000/kube-apiserver:hd

2. 方案二:Harbor镜像仓库

在repo节点上,首先下载harbor的压缩包:https://github.com/goharbor/harbor(2.3.2)
然后,解压harbor压缩包到/usr/local目录下面(其他目录也行)

tar -zvxf harbor-offline-installer-v2.3.2.tgz
cd /harbor

修改harbor配置文件harbor.yml(先复制harbor.yml.tmplharbor.yml

cp harbor.yml.tmpl harbor.yml
vim harbor.yml
hostname: 192.168.253.172(本机ip)

data_volume: /data/harbor/data

# https related config
# https:
  # https port for harbor, default is 443
  # port: 443
  # The path of cert and key files for nginx
  # certificate: /your/certificate/path
  # private_key: /your/private/key/path

先安装docker和docker-compose

yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce
systemctl start docker
systemctl enable docker
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version

安装harbor服务

sh /install.sh(可能需要执行几遍)
docker-compose ps(验证启动情况)

浏览器登录:
输入IP访问:http://192.168.253.172
输入用户名admin和密码Harbor12345即可登录

docker登录:
需要先修改配置文件:vim /usr/lib/systemd/system/docker.service

# ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd -H fd:// --insecure-registry 192.168.253.172 --containerd=/run/containerd/containerd.sock
systemctl daemon-reload
systemctl restart docker
docker-compose up -d(需要在harbor目录(/usr/local/harbor,即docker-compose.yml所在的目录)下执行,启动harbor)
docker login -u admin -p Harbor12345 http://192.168.253.172(可能需要执行几遍)

harbor仓库的使用:

# harbor如何停止与启动
cd harbor       //切换到harbor安装包目录
docker-compose stop   //停止Harbor
docker-compose start  //启动Harbor
# 上传下载镜像
docker tag nginx 192.168.253.172/test/nginx:test(repo节点)
docker push 192.168.253.172/test/nginx:test(repo节点)

docker pull 192.168.253.172/test/nginx:test(k8s集群节点)
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐