mcpField
A
ArgoCDReview

ArgoCDReview

github.com/julianobarbosa云与 DevOps1462 次安装2 天前更新
代码仓库

关于 ArgoCDReview

ArgoCDReview 是面向 ArgoCD 运维人员的命令行审查与排障技能,覆盖应用状态、清单差异、部署历史和同步故障诊断。还提供同步与回滚操作的流程参考。

主要功能

  1. 01查看应用健康与同步状态
  2. 02比较线上与 Git 清单
  3. 03检查部署历史和资源树
  4. 04诊断同步故障与资源异常
  5. 05参考同步及回滚流程

适用场景

  1. 01检查应用为何处于不健康状态
  2. 02发现线上配置与 Git 的差异
  3. 03排查同步失败或资源降级
  4. 04回滚到指定部署历史版本

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/julianobarbosa/claude-code-skills --skill argocdreview

安装后在 Claude Code 中输入/argocdreview确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

Tools/
.gitkeep
Workflows/
DiffManifests.md
ReviewApplication.md
ReviewResources.md
RollbackApp.md
TroubleshootSync.md

详细介绍

ArgoCDReview - ArgoCD CLI 审查与故障排查

用于审查应用、诊断问题和管理部署的全面 ArgoCD CLI 命令。

此技能提供一系列结构化命令,用于检查 ArgoCD 应用状态、比较实时清单与 Git 中的清单、查看部署历史,以及排查同步失败问题。


前提条件

  • 已安装 ArgoCD CLI(argocd)
  • 已登录 ArgoCD 服务器:argocd login <server>
  • 如果使用多个集群,请设置上下文
# Verify connection
argocd version
argocd account get-user-info

快速参考命令

应用状态概览
# List all applications with status
argocd app list

# Get detailed app status (health, sync, resources)
argocd app get <app-name>

# Get app status as JSON (for scripting)
argocd app get <app-name> -o json

# Wide output with more columns
argocd app list -o wide
健康与同步状态
# Check sync status only
argocd app get <app-name> --show-operation

# List all OutOfSync applications
argocd app list --sync-status OutOfSync

# List all Degraded applications
argocd app list --health-status Degraded

# List applications by project
argocd app list --project <project-name>

工作流路由

工作流触发词文件
ReviewApplication“review app”、“check app status”、“app health”Workflows/ReviewApplication.md
DiffManifests“diff app”、“compare live vs desired”、“what changed”Workflows/DiffManifests.md
TroubleshootSync“sync failed”、“why not syncing”、“sync errors”Workflows/TroubleshootSync.md
RollbackApp“rollback”、“revert deployment”、“previous version”Workflows/RollbackApp.md
ReviewResources“list resources”、“app resources”、“managed resources”Workflows/ReviewResources.md

核心审查操作

1. 应用差异(实时状态与期望状态)

比较当前部署的内容与 Git 中声明的期望部署内容:

# Show diff between live state and Git
argocd app diff <app-name>

# Show diff with local manifests
argocd app diff <app-name> --local <repo-path>

# Server-side manifest generation (recommended for Helm/Kustomize)
argocd app diff <app-name> --local <repo-root> --server-side-generate
2. 查看应用清单
# Show desired manifests (from Git)
argocd app manifests <app-name>

# Show live manifests (from cluster)
argocd app manifests <app-name> --source live

# Get specific resource manifest
argocd app get-resource <app-name> \
  --kind Deployment \
  --name <deployment-name> \
  --namespace <namespace>
3. 部署历史
# View deployment history
argocd app history <app-name>

# Output example:
# ID  DATE                           REVISION
# 0   2025-01-10 10:00:00 +0000 UTC  abc1234 (HEAD)
# 1   2025-01-09 15:30:00 +0000 UTC  def5678 (v1.2.0)
# 2   2025-01-08 09:00:00 +0000 UTC  789abcd (v1.1.0)
4. 资源树与详情
# Show resource tree
argocd app resources <app-name>

# Show resource tree with health status
argocd app resources <app-name> --tree

# Get specific resource details
argocd app get-resource <app-name> \
  --resource-name <resource> \
  --kind <kind>

同步操作

安全同步(先预览)
# Preview what would sync (dry-run)
argocd app sync <app-name> --dry-run

# Sync single application
argocd app sync <app-name>

# Sync and wait for completion
argocd app sync <app-name> --wait

# Sync specific resources only
argocd app sync <app-name> --resource :Service:my-service
argocd app sync <app-name> --resource apps:Deployment:my-deployment
选择性同步
# Sync by label selector
argocd app sync -l app.kubernetes.io/instance=my-app

# Sync multiple apps
argocd app sync app1 app2 app3

# Sync excluding specific resources
argocd app sync <app-name> --resource '!apps:Deployment:skip-this'
强制同步(谨慎使用)
# Force sync (replaces resources)
argocd app sync <app-name> --force

# Force sync with prune (deletes removed resources)
argocd app sync <app-name> --prune --force

# Sync with replace strategy
argocd app sync <app-name> --replace

回滚操作

# View history first
argocd app history <app-name>

# Rollback to specific history ID
argocd app rollback <app-name> <history-id>

# Rollback without confirmation
argocd app rollback <app-name> <history-id> --yes

# Rollback and wait for completion
argocd app rollback <app-name> <history-id> --timeout 300

故障排查命令

同步失败诊断
# Get detailed sync operation status
argocd app get <app-name> --show-operation

# View sync operation result
argocd app get <app-name> -o json | jq '.status.operationState'

# Check for resource errors
argocd app resources <app-name> --tree | grep -E "(Degraded|Progressing|Missing)"
应用日志
# View logs for app's pods
argocd app logs <app-name>

# Follow logs
argocd app logs <app-name> -f

# Logs for specific container
argocd app logs <app-name> \
  --container <container-name>

# Logs for specific group/kind
argocd app logs <app-name> \
  --kind Deployment \
  --name <deployment-name>
资源事件
# Get Kubernetes events for app resources
kubectl get events -n <namespace> --sort-by='.lastTimestamp' | grep <app-name>

常见诊断场景

场景 1:应用卡在“Progressing”状态
# 1. Check what's progressing
argocd app resources <app-name> --tree

# 2. Find stuck resources (usually Deployments)
argocd app get <app-name> -o json | jq '.status.resources[] | select(.health.status == "Progressing")'

# 3. Check pod events
kubectl describe deployment <deployment-name> -n <namespace>
kubectl get pods -n <namespace> | grep <app-name>
场景 2:应用显示“OutOfSync”,但无法同步
# 1. Check diff
argocd app diff <app-name>

# 2. Check for ignored differences
argocd app get <app-name> -o json | jq '.spec.ignoreDifferences'

# 3. Check sync policy
argocd app get <app-name> -o json | jq '.spec.syncPolicy'

# 4. Force refresh from Git
argocd app get <app-name> --refresh
场景 3:健康状态为“Degraded”
# 1. Find unhealthy resources
argocd app resources <app-name> --tree

# 2. Get resource details
argocd app get-resource <app-name> \
  --kind <kind> \
  --name <name>

# 3. Check pod status
kubectl get pods -n <namespace> -l app.kubernetes.io/instance=<app-name>
kubectl describe pod <pod-name> -n <namespace>

多源应用

对于具有多个源的应用:

# Sync with specific source revisions
argocd app sync <app-name> \
  --revisions v1.0.0 --source-positions 1 \
  --revisions v2.0.0 --source-positions 2

# Sync by source name
argocd app sync <app-name> \
  --revisions v1.0.0 --source-names helm-chart \
  --revisions main --source-names values-repo

最佳实践检查清单

  • 同步前务必运行 argocd app diff
  • 在生产环境中执行同步操作时使用 --dry-run
  • 回滚前检查部署历史
  • 排查健康状况时查看资源树
  • 使用 JSON 输出进行脚本处理:-o json
  • 为同步操作设置适当的超时时间

示例

示例 1:审查故障应用

User: "Why is my-app not healthy?"
→ Run argocd app get my-app --show-operation
→ Check argocd app resources my-app --tree
→ Identify Degraded resources
→ Investigate with kubectl describe

示例 2:比较实时状态与期望状态

User: "What changed in production?"
→ Run argocd app diff my-app
→ Shows line-by-line diff
→ Identify configuration drift

示例 3:部署不当后回滚

User: "Rollback my-app to previous version"
→ Run argocd app history my-app
→ Identify target history ID
→ Run argocd app rollback my-app <id>
→ Verify with argocd app get my-app

相关工具

  • kubectl:直接检查集群
  • k9s:交互式 Kubernetes 仪表板
  • stern:多 Pod 日志跟踪
  • kubectx/kubens:切换上下文和命名空间

评论

支持 Markdown