[*] 更新 init-k8s 脚本
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 10s
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 10s
This commit is contained in:
@@ -11,6 +11,10 @@ export k8s_version=1.32.1
|
||||
# 网段配置
|
||||
export pod_subnet=10.101.0.0/16
|
||||
export service_subnet=10.100.0.0/16
|
||||
# 配置 高可用 VIP
|
||||
export vip_ip=10.1.3.100
|
||||
export vip=$vip_ip/16
|
||||
export masters=10.1.3.101,10.1.3.102,10.1.3.103
|
||||
curl -sSL https://git.martin98.com/MartinFarm/init/raw/branch/main/init-k8s.sh | bash
|
||||
```
|
||||
### 初始化 单 master 节点
|
||||
@@ -89,24 +93,21 @@ kubectl wait --for=condition=Ready pods --all -n calico-apiserver --timeout=300s
|
||||
### 初始化高可用集群
|
||||
#### 所有 master
|
||||
```bash
|
||||
# 配置 高可用 VIP
|
||||
apt install -y keepalived haproxy
|
||||
export vip_ip=10.1.3.100
|
||||
export vip=$vip_ip/16
|
||||
export masters=10.1.3.101,10.1.3.102,10.1.3.103
|
||||
current_ip=$(hostname -I | awk '{print $1}')
|
||||
first_master=$(echo $masters | cut -d',' -f1)
|
||||
if [ "$current_ip" == "$first_master" ]; then
|
||||
state=MASTER
|
||||
priority=200
|
||||
else
|
||||
state=BACKUP
|
||||
priority=100
|
||||
fi
|
||||
cat <<EOF | sudo tee /etc/keepalived/keepalived.conf
|
||||
vrrp_instance VI_1 {
|
||||
state $state
|
||||
interface eth0
|
||||
virtual_router_id 51
|
||||
priority 100
|
||||
priority $priority
|
||||
advert_int 1
|
||||
virtual_ipaddress {
|
||||
$vip
|
||||
@@ -116,8 +117,9 @@ EOF
|
||||
IFS=',' read -r -a master_ips <<< "$masters"
|
||||
backend_config=""
|
||||
for ((i=0; i<${#master_ips[@]}; i++)); do
|
||||
backend_config+=" server master-$((i+1)) ${master_ips[$i]}:6443 check"$'\n'
|
||||
backend_config+=" server master-$((i+1)) ${master_ips[$i]}:6444 check"$'\n'
|
||||
done
|
||||
mkdir -p /usr/local/haproxy
|
||||
cat <<EOF | sudo tee /etc/haproxy/haproxy.cfg
|
||||
global
|
||||
log 127.0.0.1 local0 notice
|
||||
@@ -147,7 +149,6 @@ frontend k8s-api
|
||||
|
||||
backend k8s-api-backend
|
||||
mode tcp
|
||||
option tcplog
|
||||
option tcp-check
|
||||
balance roundrobin
|
||||
default-server inter 10s downinter 5s rise 2 fall 2 slowstart 60s maxconn 250 maxqueue 256 weight 100
|
||||
@@ -156,6 +157,8 @@ EOF
|
||||
groupadd -r haproxy || echo "用户组已存在"
|
||||
useradd -r -g haproxy -s /sbin/nologin haproxy || echo "用户已存在"
|
||||
sudo systemctl restart keepalived && sudo systemctl restart haproxy
|
||||
systemctl status keepalived
|
||||
systemctl status haproxy
|
||||
```
|
||||
### Master-01
|
||||
```bash
|
||||
@@ -173,7 +176,7 @@ bootstrapTokens:
|
||||
kind: InitConfiguration
|
||||
localAPIEndpoint:
|
||||
advertiseAddress: $(hostname -I | awk '{print $1}')
|
||||
bindPort: 6443
|
||||
bindPort: 6444
|
||||
nodeRegistration:
|
||||
criSocket: unix:///var/run/containerd/containerd.sock
|
||||
imagePullPolicy: IfNotPresent
|
||||
|
||||
Reference in New Issue
Block a user