KyLin Server 11 X64部署k8s v1.34.0
一、环境准备
- 服务器要求
• 操作系统:KyLin Server 11 X64 银河麒麟
• kubernetes版本: V1.34.0
• 配置要求:
• Master节点:2 核 CPU/4GB 内存/20GB 磁盘
• node节点:4 核 CPU/8GB 内存/40GB 磁盘
• 网络要求:所有节点互通,配置静态 IP,关闭防火墙或开放必要端口(6443、10250、10251 等)
- 节点规划(示例)
• master 节点:192.168.2.201(主机名:k8s-01)
• node 节点:192.168.2.202/203/204/205(主机名:k8s-02,03,04,05)
二、系统初始化(所有节点执行)
-
关闭防火墙systemctl stop firewalld
systemctl disable firewalld -
关闭 SELinuxsetenforce 0
sed -i ‘s/^SELINUX=enforcing$/SELINUX=permissive/’ /etc/selinux/config -
关闭 Swapswapoff -a
sed -i ‘/swap/s/^/#/’ /etc/fstab4. 配置 IPVS 依赖# 安装ipset及ipvsadm
dnf -y install ipset ipvsadm
配置ipvsadm模块加载方式
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
modprobe – ip_vs
modprobe – ip_vs_rr
modprobe – ip_vs_wrr
modprobe – ip_vs_sh
modprobe – nf_conntrack
EOF
授权、运行脚本并检查模块是否加载
chmod 755 /etc/sysconfig/modules/ipvs.modules &&
bash /etc/sysconfig/modules/ipvs.modules &&
lsmod | grep -e ip_vs -e nf_conntrack5. 配置内核参数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
vm.swappiness = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
EOF
modprobe br_netfilter
查看是否加载
lsmod | grep br_netfilter
生效
sysctl -p /etc/sysctl.d/k8s.conf6. 配置时间同步dnf install -y chrony
systemctl start chronyd
systemctl enable chronyd
chronyc sources7. 配置主机名与 hosts# master节点
hostnamectl set-hostname k8s-master
node节点
hostnamectl set-hostname k8s-node1
bash
所有节点配置hosts
cat >> /etc/hosts << EOF
192.168.2.201 k8s-01
192.168.2.202 k8s-02
192.168.2.203 k8s-03
192.168.2.204 k8s-04
192.168.2.205 k8s-05
EOF
三、安装 Docker 及 cri-dockerd(所有节点)
3.1. 安装 Docker
步骤1:卸载系统默认的 Docker 相关组件dnf -y remove docker-cli container* moby
步骤2:配置 Docker CE 的 Yum 仓库(使用清华镜像源)
cat > /etc/yum.repos.d/docker-ce.repo << EOF
[docker-ce-stable]
name=Docker CE Stable
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/x86_64/stable
enabled=1
gpgcheck=0
EOF
步骤 3:刷新 Yum 缓存dnf clean all
dnf makecache
步骤 4:安装 Docker CEdnf install -y docker-ce docker-ce-cli containerd.io
步骤 5:配置 Docker 守护进程mkdir -p /etc/docker/
cat > /etc/docker/daemon.json << EOF
{
“exec-opts”: [“native.cgroupdriver=sys