Ubuntu20.04 搭建Kubernetes 1.28版本集群

发布于:2025-05-13 ⋅ 阅读:(11) ⋅ 点赞:(0)

环境依赖

以下操作,无特殊说明,所有节点都需要执行

  • 安装 ssh 服务
  1. 安装 openssh-server

复制代码

sudo apt-get install openssh-server
  1. 修改配置文件

复制代码

vim /etc/ssh/sshd_config

找到配置项

复制代码

LoginGraceTime 120
PermitRootLogin prohibit-password
StrictModes yes

把 prohibit-password 改为 yes,如下:

复制代码

LoginGraceTime 120
PermitRootLogin yes
StrictModes yes
  • 设置节点,ssh 到其他节点免密

复制代码

ssh-keygen -t rsa

这将生成一个 RSA 密钥对。默认情况下,这些文件会存储在~/.ssh/目录下,分别是id_rsa(私钥)和id_rsa.pub(公钥)。按提示操作,或者直接按回车键接受默认设置。如果已经存在密钥对,可以跳过此步。

复制公钥到远程主机:使用 ssh-copy-id 命令来将你的公钥添加到远程主机的~/.ssh/authorized_keys文件中。

复制代码

ssh-copy-id user@remote_host
  • 设置主机名,保证每个节点名称都不相同

复制代码

hostnamectl set-hostname xxx
  • 同步节点时间
  1. 安装 ntpdate

复制代码

sudo apt-get -y install ntpdate
  1. 配置 crontab,添加定时任务

复制代码

crontab -e

0 */1 * * * ntpdate time1.aliyun.com

关闭防火墙

复制代码

systemctl stop firewalld && systemctl disable firewalld

or

ufw disable

iptables 配置

为了让 Kubernetes 能够检查、转发网络流量,需要修改 iptables 的配置,并启用 br_netfilter模块。

复制代码

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward=1 # better than modify /etc/sysctl.conf
EOF

sudo sysctl --system # 手动加载所有的配置文件

关闭 swap 分区

关闭 Linux 的 swap 分区,提升 Kubernetes 的性能。

复制代码

复制代码

# 临时关闭
sudo swapoff -a
# 永久关闭:注释 swap 挂载,给 swap 这行开头加一下 "#" 注释
sudo sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab 

为什么要关闭 swap 交换分区?
Swap 交换分区,如果机器内存不够,会使用 swap 分区,但是 swa


网站公告

今日签到

点亮在社区的每一天
去签到