准备

我们先装备三台机器,一台master,两台worker,在安装之前,对三台机器先准备好基础环境。

先打开机器的转发功能

vi /etc/sysctl.conf 加入如下内容
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
# 导入配置,引入桥接包过滤模块

modprobe br_netfilter
sysctl -p /etc/sysctl.conf

关闭防火墙

#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld

关闭selinux

#永久关闭,一定要重启操作系统后生效。
sed -ri 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
#临时关闭,不重启操作系统,即刻生效。
setenforce 0 

三台机器分别修改hostname

hostnamectl set-hostname master
hostnamectl set-hostname worker1
hostnamectl set-hostname worker2

#在host增加这三个hostname的IP访问,分别把如下内容的/etc/hosts文件拷贝到三台机器上
vi /etc/hosts
192.168.100.41 master
192.168.100.42 worker1
192.168.100.43 worker2


## k3s error
vi /etc/default/grub
#添加
GRUB_CMDLINE_LINUX="cgroup_memory=1 cgroup_enable=memory swapaccount=1 systemd.unified_cgroup_hierarchy=0"

update-grub

reboot

安装docker

http://www.liguoli.cn/view/my/81.html

安装Rancher

在master上,安装Rancher

docker run -d -p 8055:80 -p 8443:443 --restart=unless-stopped -v /data/rancherhome/rancher:/var/lib/rancher -v /data/rancherhome/auditlog:/var/log/auditlog --name rancher --privileged=true rancher/rancher


## 方式2
docker run -d -p 3001:80 -p 3000:443 --restart=unless-stopped -v /home/app/rancher:/var/lib/rancher -v /home/app/rancher/auditlog:/var/log/auditlog --name rancher --cgroupns host --privileged=true rancher/rancher


#网络设置
yum install -y iptables-services
modprobe ip_tables
modprobe iptable_filter
docker restart rancher
reboot

docker logs -f rancher

访问管理

https://192.168.100.41:8443/

#切换到中文模式

#重置密码
docker exec -ti rancher reset-password

#使用密码登录
#同意协议

创建K8s 集群

#创建集群
#选择 自定义 v1.27.7+k3s2 版本

kubectl的客户端工具

集群配置成功后,我们可以在master上,部署一个kubectl的客户端工具,来进行命令是的访问集群。

yum -y install kubernetes-client
mkdir ~/.kube
cd ~/.kube
vi config

上面编辑config的内容从集群仪表盘上面获取

error

# 去除污点
kubectl taint node master node-role.kubernetes.io/control-plane:NoSchedule-
©2019 Somore 豫ICP备19009951号 sqlixiaoli@163.com