一台是阿里云,一台是腾讯云,一台是华为云,一台是百度云等多种公有云混合安装K8S集群

2023-12-15 04:52:14

1. 修改主机名称和添加hosts

#永久修改主机名
hostnamectl set-hostname  master  && bash     #在master01上操作,阿里云服务器
hostnamectl set-hostname  worker1   && bash   #在node01上操作,阿里腾讯云服务器
hostnamectl set-hostname  worker2   && bash   #在node02上操作,华为云服务器
cat >> /etc/hosts << EOF
202.168.216.25    master
198.201.73.25    worker1
49.58.173.125    worker2
EOF

2.系统优化

#时间同步:
yum install epel-release  -y
yum install ntpdate -y
ntpdate time.windows.com
#修改内核参数
cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF

cat >>  /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

modprobe br_netfilter #加载br_netfilter模块
lsmod |grep br_netfilter #验证模块是否加载成功
sysctl -p /etc/sysctl.d/k8s.conf  #使刚才修改的内核参数生效
systemctl stop firewalld # 关闭
systemctl disable firewalld # 禁止开机启动防火墙
sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
setenforce 0 # 临时
yum install -y yum-utils device-mapper-persistent-data lvm2 wget curl

wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo

yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
    

#yum list docker-ce --showduplicates | sort -r #查看yum仓库中可以安装的docker版本
#yum -y install docker-ce-18.06.1.ce-3.el7 #安装指定的版本
yum -y install docker-ce docker-ce-cli containerd.io #安装最新docker
systemctl enable docker
systemctl start docker
docker --version

cat > /etc/docker/daemon.json << EOF
{
  "registry-mirrors": ["https://qj799ren.mirror.aliyuncs.com","https://4c99aa72f1a643edb02b13b93fec6a17.mirror.swr.myhuaweicloud.com"],
  "insecure-registries": ["0.0.0.0/0"],
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
EOF
systemctl restart docker
systemctl status docker

3.rancher安装

#在master01上操作,阿里云服务器上安装rancher
docker run -d --name rancher_server --restart=unless-stopped --privileged   -p 8080:80 -p 8443:443 -v /rancher/rancher:/var/lib/rancher    rancher/rancher:v2.4.17 

浏览器访问 https://202.168.216.25:8443

4. 参考博客第5步以后继续操作

点击阅读

文章来源:https://blog.csdn.net/qq_14910065/article/details/134914519
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。