一、说明
公司当前有一个用TKE搭建的K8s集群,目前遇到的问题:
- 目前TKE已经基本不更新了
- 公司内K8s集群所承载了所有项目的测试环境,目前资源已经无法满足一台节点坏
- 跟现网集群环境不一致,现网是每个项目一个集群
针对上面的问题,经过内部沟通,决定在公司内重新搭建一套多集群K8s环境,为了便于管理,最终选择用Rancher来管理这个多集群的环境,为了解及测试Rancher,前期先用6台虚拟机搭建模拟环境,本文主要讲的就是搭建Rancher测试集群的事情
三、安装系统
- 安装略
- 虚拟机IP地址:192.168.17.51
yoda@yoda01:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.3 LTS
Release: 22.04
Codename: jammy
四、系统环境配置
- 修改主机名称
yoda@yoda:~$ sudo hostnamectl set-hostname yoda01
[sudo] password for yoda:
yoda@yoda03:~$ hostname
yoda01
- 关闭防火墙
yoda@yoda01:~$ sudo systemctl stop ufw.service
yoda@yoda01:~$ sudo systemctl disable ufw.service
Synchronizing state of ufw.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable ufw
Removed /etc/systemd/system/multi-user.target.wants/ufw.service.
yoda@yoda01:~$ sudo ufw status
Status: inactive #这个状态说明防火墙关闭了
- 开启系统路由转发功能
yoda@yoda01:~$ sudo vim /etc/sysctl.conf
net.ipv4.ip_forward = 1 #将这一行添加到最后一行,然后保存
yoda@yoda01:~$ sudo sysctl -p
net.ipv4.ip_forward = 1
yoda@yoda01:~$ sudo sysctl -a | grep "net.ipv4.ip_forward = 1"
net.ipv4.ip_forward = 1
- 配置源
yoda@yoda01:~$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
yoda@yoda01:~$ sudo vim /etc/apt/sources.list
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
# deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
五、安装docker
yoda@yoda01:~$ curl https://releases.rancher.com/install-docker/20.10.sh | sh
yoda@yoda01:/var/log$ docker --version
Docker version 20.10.24, build 297e128
……
配置镜像加速
yoda@yoda01:~$ sudo mkdir -p /etc/docker
yoda@yoda01:~$ sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://sx15mtuf.mirror.aliyuncs.com"]
}
EOF
yoda@yoda01:~$ sudo systemctl daemon-reload
yoda@yoda01:~$ sudo systemctl restart docker
六、安装Rancher2.6.9
sudo docker run -d --restart=unless-stopped --name=rancher -p 80:80 -p 443:443 --privileged rancher/rancher:v2.6.9
yoda@yoda01:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6cc63abc0241 rancher/rancher:v2.6.9 "entrypoint.sh" 12 seconds ago Up 10 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp rancher
七、访问Rancher
- 在浏览器访问 https://192.168.17.51/
- 查看初始密码
yoda@yoda01:~$ sudo docker logs 6cc63abc0241 2>&1 | grep "Bootstrap Password:"
- 登陆后直接使用即可