环境准备
1
服务器要求
搭建K8s集群的最低硬件配置要求
| 节点类型 | CPU | 内存 | 磁盘 |
|---|---|---|---|
| Master节点 | 2核+ | 2GB+ | 20GB+ |
| Worker节点 | 1核+ | 1GB+ | 20GB+ |
2
系统初始化(所有节点)
所有节点
配置主机名、关闭防火墙、禁用Swap等基础设置
# 设置主机名(每个节点不同) hostnamectl set-hostname k8s-master hostnamectl set-hostname k8s-worker1 hostnamectl set-hostname k8s-worker2 # 配置hosts(所有节点) cat >> /etc/hosts << EOF 192.168.1.10 k8s-master 192.168.1.11 k8s-worker1 192.168.1.12 k8s-worker2 EOF # 关闭防火墙 systemctl stop firewalld systemctl disable firewalld # 关闭SELinux setenforce 0 sed -i 's/enforcing/disabled/' /etc/selinux/config # 关闭Swap swapoff -a sed -ri 's/.*swap.*/#&/' /etc/fstab # 配置内核参数 cat > /etc/sysctl.d/k8s.conf << EOF net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward = 1 EOF sysctl --system
3
安装Docker(所有节点)
所有节点
K8s使用Docker作为容器运行时
# 安装Docker
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum -y install docker-ce-20.10.17-3.el7
systemctl enable docker && systemctl start docker
# 配置Docker使用systemd作为cgroup驱动
cat > /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors": ["https://hub-mirror.c.163.com"]
}
EOF
systemctl restart docker