基于三台运行CentOS 8的服务器(IP地址为192.168.10.x)来搭建Kubernetes v1.28.2集群的详细步骤。我们将使用kubeadm工具来简化这一过程,并选择Calico作为CNI插件。
声明:本文是实战案例,经过实测检验,提供完整的解决方案。 包括国内网络问题的解决,提供完整的配置文件, 以及各种常见问题的解答等。
1 安装环境
服务器:
192.168.10.90 cm90 kubernetes master
192.168.10.91 cm91 kubernetes node
192.168.10.92 cm92 kubernetes node
OS version: CentOS stream 8
Linux version: v4.18.0-553.5.1.el8.x86_64
2 基础环境设置
2.1 关闭防火墙和SELinux
# 关闭防火墙
systemctl stop firewalld
# 禁止开启自启动
systemctl disable firewalld
# 禁用SELINUX
sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
#临时禁用
setenforce 0
2.2 禁用swap分区
# 关闭swap
swapoff -a
sed -i '/ swap / s/^(.*)$/#\1/' /etc/fstab
查看swapon是否关闭
swapon -s
2.3 修改内核参数
#编辑文件
vi /etc/sysctl.conf
#修改内容
vm.swappiness=0
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables=1
#执行生效
sysctl -p
3 安装Docker引擎
3.1 安装必要的包
yum install -y yum-utils device-mapper-persistent-data lvm2
3.2 添加Docker仓库
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
下载后存放目录:/etc/yum.repos.d/docker-ce.repo
官方仓库的的地址,一般情况下不能下载,所以我这边手工改成了阿里云的仓库。
# 编辑docker-ce.repo
vi /etc/yum.repos.d/docker-ce.repo
#修改的内容如下:
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://mir