Ubuntu24.04部署k8s集群 - 初始化
Pluto Lv2

主机准备

主机名IP 地址主机配置
k8s-master192.168.88.1364核,4GB内存,40GB硬盘
k8s-worker-01192.168.88.1372核,4GB内存,40GB硬盘
k8s-worker-02192.168.88.1382核,4GB内存,40GB硬盘

环境

  • Ubuntu 24.04
  • k8s 1.33.3

以下操作,在所有 4 台主机上均要进行,可以在 1 台主机上操作完后再进行克隆,但注意修改 IP 以及主机名。

禁用 Linux 的 swap 分区

1
2
sed -ri 's/.*swap.*/#&/' /etc/fstab  # 永久禁用 swap 分区
swapoff -a

添加DNS解析

我使用的是内网 DNS 服务器,若需要手动解析可编辑 /etc/hosts 文件,需要保证每台机器都能互相解析。

例如:

1
2
3
4
5
cat >> /etc/hosts << EOF
192.168.88.136 k8s-master
192.168.88.137 k8s-node-01
192.168.88.138 k8s-node-02
EOF

时间同步

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 查看和管理时间同步的命令
# 查看时间同步状态:

timedatectl status

# 启用或禁用 systemd-timesyncd

sudo systemctl enable systemd-timesyncd
sudo systemctl start systemd-timesyncd

# 使用ntpdate (可选)
apt install ntpdate -y

# 安装完成后使用阿里云的时间服务同步时间
ntpdate ntp1.aliyun.com

配置网络

为了让 K8s 能够转发网络流量,需要修改 iptables 的配置。

1
2
3
4
5
6
7
8
9
# 修改 Linux 内核参数,添加网桥过滤和地址转发功能
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

# 使配置生效
sudo sysctl --system

设置hostname

1
2
3
hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-node-01
hostnamectl set-hostname k8s-node-02

关闭 SELinux (Ubuntu跳过,因为没有SELinux)

1
2
setenforce 0
sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

关闭防火墙(一般默认状态是关闭的

1
2
ufw status
ufw disable

重启服务器

1
reboot
  • 本文标题:Ubuntu24.04部署k8s集群 - 初始化
  • 本文作者:Pluto
  • 创建时间:2025-08-12 17:19:00
  • 本文链接:https://blog.aoaostar.com/post/e2a36076/
  • 版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
 评论