linux 环境下用rancher安装k8s集群
准备环境:
3台机器
一、环境初始化
1)修改 /etc/sysctl.conf
将桥接的IPv4流量传递到iptables的链
cat > /etc/sysctl.conf << EFO net.ipv4.ip_forward = 1 net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EFO
生效
sysctl -p /etc/sysctl.conf
2)关闭防火墙 关闭selinux 关闭swap
systemctl stop firewalld && systemctl disable firewalld sed -i 's/enforcing/disabled/' /etc/selinux/config && setenforce 0 swapoff -a && sed -ri 's/.*swap.*/#&/' /etc/fstab
3) 时间同步
yum install ntpdate -y ntpdate ntp1.aliyun.com date -R #查看新时间是否已同步
4)重启
reboot #注意确定好环境哈
二、先为所有机器安装好docker
1、移除以前docker相关包
sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine
2、配置yum源
sudo yum install -y yum-utils sudo yum-config-manager \ --add-repo \ http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3、安装docker
sudo yum install -y docker-ce docker-ce-cli containerd.io #以下是在安装k8s的时候使用 yum install -y docker-ce-20.10.8 docker-ce-cli-20.10.8 containerd.io-1.4.10
4、启动并配置加速
systemctl enable docker --now sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://82m9ar63.mirror.aliyuncs.com"], "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "storage-driver": "overlay2" } EOF sudo systemctl daemon-reload sudo systemctl restart docker
三、部署rancher
docker run -d --name=rancher --restart=unless-stopped \ -p 80:80 -p 443:443 \ --privileged \ -v /home/rancher:/var/lib/rancher \ rancher/rancher:latest
参考链接:
https://zhuanlan.zhihu.com/p/403539342
https://blog.csdn.net/l2931050/article/details/124110605
https://blog.csdn.net/weixin_60092693/article/details/121665901
https://blog.csdn.net/weixin_41636021/article/details/127976712