SuperAPI AI 工具集

k8s-gitops

部署与运维

查看项目

更新于 10-16 10:52

技能介绍

Kubernetes GitOps 是一套基于 kubectl-mcp-server 工具、使用 Flux 与 ArgoCD 的 GitOps 工作流技能。

适用时机

当用户提及 Flux、ArgoCD、GitOps、sync、reconcile,或涉及检查同步状态、触发对账、配置漂移检测,以及 out of sync、从 Git 部署、持续交付等关键词时,可使用本技能。

优先级规则

技能给出四条优先级规则:先检查 source 是否就绪再排查问题(关键,使用 flux_sources_list_tool);部署前先确认同步状态(高,使用 argocd_app_get_tool);Git 变更后进行对账(中,使用 flux_reconcile_tool);手动变更前先挂起(低,使用 flux_suspend_tool)。

Flux CD

检查 Flux 状态可使用 flux_kustomizations_list_tool(namespace="flux-system")、flux_helmreleases_list_tool(namespace) 和 flux_sources_list_tool(namespace="flux-system")。对账资源使用 flux_reconcile_tool(kind, name, namespace),例如对 kustomization 或 helmrelease 进行对账。暂停与恢复使用 flux_suspend_tool 和 flux_resume_tool,需传入 kind、name、namespace。

ArgoCD

列出应用使用 argocd_apps_list_tool(namespace="argocd");获取应用状态使用 argocd_app_get_tool(name, namespace);同步应用使用 argocd_sync_tool(name, namespace);刷新应用使用 argocd_refresh_tool(name, namespace)。

GitOps 故障排查

Flux 不同步时:source 未就绪可检查 flux_sources_list_tool() 并检查 Git 凭据;Kustomization 失败可检查 flux_kustomizations_list_tool() 并检查清单错误;HelmRelease 失败可检查 flux_helmreleases_list_tool() 并检查 values 与 chart 版本。ArgoCD OutOfSync 时可使用 argocd_app_get_tool(),手动同步或检查自动同步;Degraded 时检查健康状态并修复不健康资源;Unknown 时使用 argocd_refresh_tool() 刷新应用。

环境晋级

使用 Flux Kustomization 时,可分别对 staging 与 production 的 kustomization 执行 flux_reconcile_tool。使用 ArgoCD 时,可先同步 app-staging,再通过 argocd_app_get_tool 查看状态,然后同步 app-production。

多集群 GitOps

可在工具调用中传入 context 参数来管理跨集群 GitOps,例如分别列出 cluster-1 与 cluster-2 的 kustomization,或在对账时指定 production-cluster。

漂移检测

通过 argocd_app_get_tool 与 flux_kustomizations_list_tool 比较实际状态与期望状态。

前置条件

Flux 工具需要先安装 Flux,可使用 flux install。ArgoCD 工具需要先安装 ArgoCD,可使用 kubectl create namespace argocd 和 kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml。

相关技能

k8s-deploy 用于标准部署,k8s-helm 用于 Helm chart 管理。