feat(k8s): 事件页简化、可视化编辑 P0、Deployment 五 Tab 修复
- 事件中心:去彩虹图表,改专业排名列表 + 主题变量 - 网络/配置/存储:ResourceVisualEditor 双向 YAML 同步、导入 YAML、新建 - vite manualChunks 减小 embed 主包体积 - run.sh:多副本强制 MODE=release + MySQL/Redis - Deployment 编辑:共享 manifest、统一 saveDeploymentManifest - 修复存储挂载 initContainers 混入 bug、补 Tolerations UI - 服务 Tab:applyYAML 创建 + ResourceVisualEditor 编辑 - 基本信息:Pod 模板标签 + Selector 同步
This commit is contained in:
1 parent
339b24a579
commit
d0cf71b05a
17 files changed
+814
-497
No files matched your search
@@ -924,6 +924,51 @@ cmd_kubernetes_build() {
|
||||
KUBERNETES_BUILT_IMAGE="$image_tag"
|
||||
}
|
||||
|
||||
# 读取 deployment.yaml 中的 replicas(默认 1)// Logan.Li
|
||||
kubernetes_manifest_replicas() {
|
||||
local replicas
|
||||
replicas=$(awk '/^ replicas:/{print $2; exit}' "$KUBERNETES_MANIFEST_DIR/deployment.yaml" 2>/dev/null)
|
||||
echo "${replicas:-1}"
|
||||
}
|
||||
|
||||
# 读取集群中 aiops Deployment 当前副本数 // Logan.Li
|
||||
kubernetes_live_replicas() {
|
||||
kubectl -n "$KUBERNETES_NAMESPACE" get deployment aiops -o jsonpath='{.spec.replicas}' 2>/dev/null
|
||||
}
|
||||
|
||||
# 多副本时 SQLite 不共享,强制切换 MODE=release + 集群内 MySQL/Redis // Logan.Li
|
||||
ensure_cluster_mode_for_replicas() {
|
||||
local replicas=${1:-1}
|
||||
if [ "$replicas" -le 1 ]; then
|
||||
return 0
|
||||
fi
|
||||
if ! kubectl -n "$KUBERNETES_NAMESPACE" get deployment aiops &>/dev/null; then
|
||||
warning "Deployment 尚未创建,跳过多副本模式切换(apply 后会自动处理)"
|
||||
return 0
|
||||
fi
|
||||
local current_mode
|
||||
current_mode=$(kubectl -n "$KUBERNETES_NAMESPACE" get deployment aiops \
|
||||
-o jsonpath='{.spec.template.spec.containers[0].env[?(@.name=="MODE")].value}' 2>/dev/null)
|
||||
if [ "$current_mode" = "release" ]; then
|
||||
info "副本 $replicas,已为 release 模式"
|
||||
return 0
|
||||
fi
|
||||
warning "副本 $replicas > 1,SQLite 数据不共享,自动切换 MODE=release (mysql + redis)"
|
||||
kubectl -n "$KUBERNETES_NAMESPACE" set env deployment/aiops \
|
||||
MODE=release \
|
||||
DATABASE_DRIVER=mysql \
|
||||
DATABASE_HOST=mysql \
|
||||
DATABASE_PORT=3306 \
|
||||
DATABASE_USER=aiops \
|
||||
DATABASE_PASSWORD=aiops_pass_2026 \
|
||||
DATABASE_DBNAME=aiops \
|
||||
REDIS_DRIVER=redis \
|
||||
REDIS_HOST=redis \
|
||||
REDIS_PORT=6379 \
|
||||
--overwrite
|
||||
success "已切换 release 模式,使用集群 MySQL/Redis"
|
||||
}
|
||||
|
||||
# Kubernetes 部署
|
||||
cmd_kubernetes() {
|
||||
local action=${1:-help}
|
||||
@@ -959,7 +1004,13 @@ cmd_kubernetes() {
|
||||
|
||||
# 4. 部署应用
|
||||
info "部署 AIOps 应用..."
|
||||
local target_replicas
|
||||
target_replicas=$(kubernetes_manifest_replicas)
|
||||
if [ "$target_replicas" -gt 1 ]; then
|
||||
warning "manifest replicas=$target_replicas,将自动切换 MODE=release"
|
||||
fi
|
||||
kubectl apply -f "$KUBERNETES_MANIFEST_DIR/deployment.yaml"
|
||||
ensure_cluster_mode_for_replicas "$target_replicas"
|
||||
kubectl -n "$KUBERNETES_NAMESPACE" rollout status deployment/aiops --timeout=180s 2>/dev/null || {
|
||||
warning "应用正在启动,查看日志: ./run.sh kubernetes logs"
|
||||
}
|
||||
@@ -983,6 +1034,10 @@ cmd_kubernetes() {
|
||||
upgrade|update)
|
||||
check_kubernetes_deps
|
||||
banner "========== Kubernetes 滚动更新 =========="
|
||||
local live_replicas
|
||||
live_replicas=$(kubernetes_live_replicas)
|
||||
live_replicas=${live_replicas:-1}
|
||||
ensure_cluster_mode_for_replicas "$live_replicas"
|
||||
cmd_kubernetes_build 1
|
||||
info "更新 Deployment 镜像: $KUBERNETES_BUILT_IMAGE"
|
||||
kubectl -n "$KUBERNETES_NAMESPACE" set image deployment/aiops aiops="$KUBERNETES_BUILT_IMAGE" --record
|
||||
@@ -1061,7 +1116,7 @@ cmd_kubernetes() {
|
||||
check_kubernetes_deps
|
||||
local replicas=${2:-1}
|
||||
if [ "$replicas" -gt 1 ]; then
|
||||
warning "MODE=local 时 SQLite 数据不共享,多副本会导致数据分裂,建议 replicas=1 或切换 MODE=release"
|
||||
ensure_cluster_mode_for_replicas "$replicas"
|
||||
fi
|
||||
info "扩缩容到 $replicas 副本..."
|
||||
kubectl -n "$KUBERNETES_NAMESPACE" scale deployment/aiops --replicas="$replicas"
|
||||
|
||||
Reference in new issue
Block a user