refactor(cluster): 通用化第四个 Worker 节点接入
将原宁波专用接入脚本改为由环境变量控制节点名称、站点和 WireGuard 端口,支持香港双物理节点 Worker 池。增加候选节点启用开关和服务商网络许可门禁,未明确批准时禁止任何 WireGuard 或 K3s 写操作。同步调整生产验收、巡检、拓扑校验和运行手册。\n\n验证:\n- scripts/cluster 全部 Shell 脚本 bash -n\n- scripts/cluster 全部 ShellCheck\n- git diff --check\n- 本地凭据值扫描\n- 当前三节点 WireGuard/K3s/PostgreSQL 只读基线检查
This commit is contained in:
@@ -15,10 +15,10 @@ load_cluster_env
|
||||
hosts=("$CLUSTER_NINGBO_HOST" "$CLUSTER_HONGKONG_HOST" "$CLUSTER_LOS_ANGELES_HOST")
|
||||
wireguard_ips=(10.77.0.1 10.77.0.2 10.77.0.3)
|
||||
site_labels=(ningbo hongkong losangeles)
|
||||
if [[ -n $CLUSTER_NINGBO_WORKER_HOST ]]; then
|
||||
hosts+=("$CLUSTER_NINGBO_WORKER_HOST")
|
||||
if [[ $CLUSTER_WORKER_NODE_4_ENABLED == true ]]; then
|
||||
hosts+=("$CLUSTER_WORKER_NODE_4_HOST")
|
||||
wireguard_ips+=(10.77.0.4)
|
||||
site_labels+=(ningbo-worker-2)
|
||||
site_labels+=("$CLUSTER_WORKER_NODE_4_NAME")
|
||||
fi
|
||||
peer_count=$((${#hosts[@]} - 1))
|
||||
for source_index in "${!hosts[@]}"; do
|
||||
@@ -55,7 +55,7 @@ done
|
||||
echo "wireguard_acceptance=PASS peers=${#hosts[@]} handshakes=$((${#hosts[@]} * peer_count)) packet_loss_lt_1=true"
|
||||
|
||||
expected_nodes=3
|
||||
[[ -z $CLUSTER_NINGBO_WORKER_HOST ]] || expected_nodes=4
|
||||
[[ $CLUSTER_WORKER_NODE_4_ENABLED != true ]] || expected_nodes=4
|
||||
cluster_state=$(cluster_ssh "$CLUSTER_NINGBO_HOST" bash -s -- "$expected_nodes" <<'REMOTE'
|
||||
set -euo pipefail
|
||||
expected_nodes=$1
|
||||
@@ -72,22 +72,24 @@ printf 'nodes=%s\n' "$($kubectl get nodes --no-headers | wc -l)"
|
||||
REMOTE
|
||||
)
|
||||
[[ $cluster_state == nodes="$expected_nodes" ]]
|
||||
if [[ -n $CLUSTER_NINGBO_WORKER_HOST ]]; then
|
||||
worker_state=$(cluster_ssh "$CLUSTER_NINGBO_HOST" 'bash -s' <<'REMOTE'
|
||||
if [[ $CLUSTER_WORKER_NODE_4_ENABLED == true ]]; then
|
||||
worker_state=$(cluster_ssh "$CLUSTER_NINGBO_HOST" bash -s -- \
|
||||
"$CLUSTER_WORKER_NODE_4_NAME" "$CLUSTER_WORKER_NODE_4_SITE" <<'REMOTE'
|
||||
set -euo pipefail
|
||||
kubectl='k3s kubectl'
|
||||
node=easyai-ningbo-worker-2
|
||||
node=$1
|
||||
site=$2
|
||||
[[ $($kubectl get node "$node" -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}') == True ]]
|
||||
[[ $($kubectl get node "$node" -o jsonpath='{.metadata.labels.easyai\.io/site}') == ningbo ]]
|
||||
[[ $($kubectl get node "$node" -o jsonpath='{.metadata.labels.easyai\.io/site}') == "$site" ]]
|
||||
[[ $($kubectl get node "$node" -o jsonpath='{.metadata.labels.easyai\.io/worker}') == true ]]
|
||||
[[ $($kubectl get node "$node" -o jsonpath='{.metadata.labels.easyai\.io/database}') == false ]]
|
||||
[[ $($kubectl get node "$node" -o json | jq '[.spec.taints[]? | select(.key=="easyai.io/worker-only" and .effect=="NoSchedule")] | length') -eq 1 ]]
|
||||
[[ $($kubectl get pods -A --field-selector "spec.nodeName=$node" -o json |
|
||||
jq '[.items[] | select(.metadata.namespace!="kube-system" and .metadata.labels["app.kubernetes.io/name"]!="easyai-worker")] | length') -eq 0 ]]
|
||||
printf 'worker_node=ready\n'
|
||||
printf 'worker_node=ready node=%s site=%s\n' "$node" "$site"
|
||||
REMOTE
|
||||
)
|
||||
[[ $worker_state == worker_node=ready ]]
|
||||
[[ $worker_state == "worker_node=ready node=$CLUSTER_WORKER_NODE_4_NAME site=$CLUSTER_WORKER_NODE_4_SITE" ]]
|
||||
fi
|
||||
echo "k3s_control_plane=PASS servers=3 worker_nodes=$((expected_nodes - 3)) witness_business_pods=0"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user