🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
**1. 安装要求** * 一台或多台运行兼容 deb/rpm 的 Linux 操作系统的计算机;例如:Ubuntu 或 CentOS。 * 每台机器至少:内存 2GB+,2个 CPU+,硬盘 30GB+。 * Master 节点的处理器数量必须至少是 2 核。 ![](https://img.kancloud.cn/ab/72/ab7217adb0eb7e926ea5d88f1601440f_1393x472.webp) * 集群中所有机器之间网络互通。 * 可以访问外网。因为需要拉取镜像,如果服务器不能上网,需要提前下载镜像并导入节点。 **2. 先准备 3 台机器** ![](https://img.kancloud.cn/d2/53/d2533358b92262b5d692681ced3ff62f_1964x264.png) <br/> **3. 分别设置各个机器的主机名** ```shell (1)k8s-master1 节点上设置 # hostnamectl set-hostname k8s-master1 (2)k8s-node1 节点上设置 # hostnamectl set-hostname k8s-node1 (3)k8s-node2 节点上设置 # hostnamectl set-hostname k8s-node2 (4)重启所有节点 # reboot ``` <br/> **4. 时间同步【所有节点】** ```shell # yum install ntpdate -y # ntpdate edu.ntp.org.cn ``` <br/> **5. 关闭防火墙【所有节点】** ```shell (1)关闭防火墙 # systemctl stop firewalld.service (2)禁止防火墙开机自启 # systemctl disable firewalld.service (3)查看防火墙是否已被关闭 # firewall-cmd --state not running ``` <br/> **6. 关闭 selinux【所有节点】** ```shell # sed -i 's/enforcing/disabled/' /etc/selinux/config # cat /etc/selinux/config SELINUX=disabled 【disabled表示已经关闭】 ``` <br/> **7. 关闭 swap【所有节点】** ```shell (1)关闭swap # swapoff -a # sed -i 's/.*swap.*/#&/' /etc/fstab (2)查看是否已经关闭 # free -h total used free shared buff/cache available Mem: 1.8G 204M 505M 8.6M 1.1G 1.4G Swap: 0B 0B 0B 【这一行都为 0 则已关闭】 ``` <br/> **8. 配置hosts【所有节点】** ```shell # cat >> /etc/hosts << EOF 192.168.1.16 k8s-master1 192.168.1.17 k8s-node1 192.168.1.18 k8s-node2 EOF ``` <br/> **9. 配置 ssh 互信【所有节点(可选)】** ```shell (1)一路回车即可 # ssh-keygen (2) # ssh-copy-id -i ~/.ssh/id_rsa.pub root@k8s-master1 # ssh-copy-id -i ~/.ssh/id_rsa.pub root@k8s-node1 # ssh-copy-id -i ~/.ssh/id_rsa.pub root@k8s-node2 ``` <br/> **10. 允许 iptables 检查桥接流量【所有节点】** ```shell # cat > /etc/sysctl.d/k8s.conf << EOF net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF # sysctl --system ```