用Rancher2.x版本部署k8s
一、用Rancher2.x版本部署k8s
1、Rancher简介
Rancher官网
Rancher是业界唯一完全开源的企业级容器管理平台,为企业用户提供在生产环境中落地使用容器所需的一切功能与组件。
Rancher2.x基于Kubernetes构建,使用Rancher,DevOps团队可以轻松测试、部署和管理应用程序,运维团队可以部署、管理和维护一切Kubernetes集群,无论集群运行在何基础设施之上。
2、环境准备
#系统版本
操作系统: ubuntu-18.04-server-amd64.iso #系统版本 nulige@node3:~$ uname -a Linux node3.com 4.15.0-20-generic #21-Ubuntu SMP Tue Apr 24 06:16:15 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
#IP规划
192.168.56.11 node1.com 192.168.56.12 node2.com 192.168.56.13 node3.com
#修改主机名 (备注:三台机都要操作)
nulige@node1:~$ sudo hostname node1.com nulige@node1:~$ sudo vi /etc/hostname node1.com
#配置网络
nulige@ubuntu:/etc/netplan$ sudo apt install ifupdown nulige@ubuntu:/etc/netplan$ cd /etc/netplan nulige@ubuntu:/etc/netplan$ sudo nano /etc/netplan/01-netcfg.yaml # This file describes the network interfaces available on your system # For more information, see netplan(5). network: version: 2 renderer: networkd ethernets: ens33: addresses: [192.168.56.11/24] gateway4: 192.168.56.2 nameservers: addresses: [192.168.56.2, 8.8.8.8] dhcp4: no optional: no nulige@ubuntu:/etc/netplan$ sudo netplan apply nulige@ubuntu:/etc/netplan$ ip a 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:50:56:2b:1a:b2 brd ff:ff:ff:ff:ff:ff inet 192.168.56.11/24 brd 192.168.56.255 scope global ens33 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe2b:1ab2/64 scope link valid_lft forever preferred_lft forever
#配置域名解析(备注:三台机都要操作)
nulige@node1:~$ sudo vi /etc/hosts 192.168.56.11 node1.com 192.168.56.12 node2.com 192.168.56.13 node3.com
#关闭防火墙 (备注:三台机都要操作)
#关闭ubuntu的防火墙 sudo ufw disable
3、安装Rancher
#安装Docker
sudo curl -sSL https://get.docker.com/ | sh #docker命令 docker version docker images docker ps -a #给当前用户赋权 sudo usermod -a -G docker $USER #使他生效,刷新缓存 注销再登陆
#sudo免密
sudo vi /etc/sudoers # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL nulige ALL=(ALL) NOPASSWD:ALL #添加此句,nulige替换为你的用户名
sudo nano /etc/apt/sources.list
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
#更新源
sudo apt-get update
#登录管理控制台
https://dev.aliyun.com/
#配置镜像加速
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"] } EOF
#重启服务
sudo systemctl daemon-reload sudo systemctl restart docker
#安装Rancher
sudo docker run -d --restart=always --name rancher -p 80:80 -p 443:443 -v /opt/rancher:/var/lib/rancher rancher/rancher:latest
#登录网站
https://192.168.56.11
设置密码,再登录
#配置页面选项
#master节点配置
#添加第一个从节点
sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.2.2 --server
https://192.168.56.11 --token n7c95shl9dwknzglv759vjtnwgsgg2qqhpdsbwgltlrstq5nbsw9nm --ca-checksum 5aac2921fad23ca3e96fa10db845daad9851913a12830b34bcadaf5476ae47cf
--etcd --controlplane --worker
#添加第二个从节点(配置有区别)
sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.2.2 --server
https://192.168.56.11 --token n7c95shl9dwknzglv759vjtnwgsgg2qqhpdsbwgltlrstq5nbsw9nm --ca-checksum 5aac2921fad23ca3e96fa10db845daad9851913a12830b34bcadaf5476ae47cf
--worker
#添加节点成功
clusters
Nodes
#开启监控功能
tools--->monitoring --->enabled
#添加持久卷
#项目及命名空间
Projects/Namespaces--->add Project--->sock-shop
添加项目:
上传sock-shop.yaml文件
参考:https://blog.csdn.net/miss1181248983/article/details/87970338