1. 搭建方案
搭建方案有四种:
- minikube
- kubeadm
- 二进制安装
- 命令行工具
演示使用kubeadm的方式进行
1.1 服务器要求:
三台虚拟机;
最低配置2C 2Gi 20g硬盘
最好能联网,不能联网的话需要提供对应镜像的私有仓库
1.2 软件环境:
操作系统:centos7
Docker: 20+
k8s: 1.23.6
1.3 安装步骤:
1.3.1 初始操作
#关闭防火塘
systemctl stop firewalld
systemctl disable firewalld
#关闭selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config #永久
setenforce 0 #临时
或者:
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
#检查selinux是否关闭,重启后如何显示Disabled则表示生效
getenforce
#关闭swap
swapoff -a #临时
sed -ri 's/.*swap.*/#&/' /etc/fstab #永久
或者:
swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
#检查swap是否生效,如果Swap 全部显示 0B则表示生效
free -h
#关闭完swap后,一定要重启一下虚拟机!!!
#关闭完swap后,一定要重启一下虚拟机!!!
#关闭完swap后,一定要重启一下虚拟机!!!
#根据规划设置主机名
hostnamectl set-hostname <hostname>
#在master添加hosts
cat >> /etc/hosts << EOF
192.168.113.120 k8s-master
192.168.113.121 k8s-node1
192.168.113.122 k8s-n0de2
EOF
# 将桥接的IPV4流量传送到iptables的链
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system #生效
#时间同步
yum install ntpdate -y
ntpdate time.windows.com
升级系统内核;(强烈建议升级)
CentOs 7.x系