Ubuntu部署K8S集群
本例以三臺Ubuntu24.04為例,1master節點2worker節點
環境準備
- 修改hostname,三臺服務器分別執行
hostnamectl set-hostname k8s-master01hostnamectl set-hostname k8s-worker01hostnamectl set-hostname k8s-worker02
-
配置靜態ip(不同系統修改方法略微差異)
vim /etc/netplan/50-cloud-init.yaml # 確保ens網卡dhcp已關閉并配置address為固定ip
執行
netplan apply
應用配置
執行dig -t a www.baidu.com
查看nameserver如果是127.0.0.53(ubuntu默認使用這個本地ip代理dns)不是在50-cloud-init.yaml中配置的nameserver,則需要如下操作: -
主機名與ip解析
-
時區和時間同步
timedatectl set-timezone Asia/Shanghai
定時任務定時同步
crontab -e
59 23 * * * ntpdate ntp.aliyun.com
- 配置內核轉發及網橋過濾
# 創建加載內核模塊文件
cat << EOF | tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
# 本次執行手動加載
modprobe overlay
modprobe br_netfilter
# 驗證查看
lsmod | egrep "overlay"
lsmod | egrep "br_netfilter"
# 添加網橋過濾及內核轉發配置文件
cat << EOF | tee