Kubernetes 一主多从集群从 0 到 1 部署

前言

本篇使用 kubeadm 工具来安装和部署Kubernetes 1.24.9版本的一主多从集群环境。首先声明下没有选择最新版本的 K8S 原因是 Kubesphere 的版本兼容 ,好在不同版本安装的过程大同小异。

前置准备

安装虚拟机

K8S 一主两从的3 台 Linux 系统服务器配置如下:

主机名K8S角色IP配置操作系统
k8s-masterMaster节点192.168.179.214核CPU 8G内存 20G硬盘CentOS 7.9
k8s-node1Worker节点192.168.179.224核CPU 8G内存 20G硬盘CentOS 7.9
k8s-node2Worker节点192.168.179.234核CPU 8G内存 20G硬盘CentOS 7.9

❗️ 如果你没有安装虚拟机,你可以按照这篇文章 VMware 基于CentOS 7.9 镜像搭建 K8S 一主多从本地虚拟服务器 的步骤来完成搭建。

关闭防火墙

💥 所有节点均要执行

# 关闭防火墙
systemctl stop firewalld
# 重启禁用防火墙    
systemctl disable firewalld
# 查看防火墙状态
systemctl status firewalld

禁用 SELinux

💥 所有节点均要执行

sed -i 's/enforcing/disabled/' /etc/selinux/config

关闭 Swap 分区

💥 所有节点均要执行

swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

时区设置和时间同步

# 时区设置
sed -i '$a\export TZ=Asia/Shanghai' /etc/profile && source /etc/profile && date

# 时间校准(阿里云 ntp 时间服务器)
yum -y install ntpdate
ntpdate time1.aliyun.com

主机名和域名解析配置

192.168.179.21 主机执行

# 192.168.179.21 设置主机名 k8s-master
hostnamectl set-hostname k8s-master

# 立即生效设置
exec bash

192.168.179.22 主机执行

# 192.168.179.22 设置主机名 k8s-node1
hostnamectl set-hostname k8s-node1

# 立即生效设置
exec bash

192.168.179.23 主机执行

# 192.168.179.23 设置主机名 k8s-node2
hostnamectl set-hostname k8s-node2

# 立即生效设置
exec bash

配置域名解析 (💥 所有节点机器均要执行💥 )

cat >> /etc/hosts