Gitops argocd flux

From findscripter/everything-skills · View interactive version

Gitops argocd flux is an AI agent skill from the GitHub repository findscripter/everything-skills. 当用 ArgoCD 或 Flux 把 Git 仓库作为 Kubernetes 集群唯一可信源、需要声明式持续交付时使用;产出仓库布局、Application/Kustomization 清单、同步策略与渐进发布配置;不适用于一次性手动部署、非 K8s 目标或无集群/仓库权限的场景。触发词:GitOps、ArgoCD、Flux

How to use this skill

Skill file

何时使用

适用:

不该用(负边界):

遵循 OpenGitOps 四原则:声明式(Declarative)、版本化且不可变(Versioned & Immutable,状态存于 Git)、自动拉取(Pulled Automatically,由 Agent 拉取期望状态)、持续协调(Continuously Reconciled,对齐实际与期望状态)。

步骤

  1. 定义仓库布局与期望状态约定(按环境分目录或分仓库/分支)。
  2. 安装 ArgoCD 或 Flux 并接入集群。
  3. 配置同步策略、环境与晋升流程(生产加审批门禁)。
  4. 验证回滚与密钥处理,确认告警与健康检查到位。

推荐仓库布局:

gitops-repo/
├── apps/
│   ├── production/{app1,app2}/   # kustomization.yaml + deployment.yaml
│   └── staging/
├── infrastructure/{ingress-nginx,cert-manager,monitoring}/
└── argocd/{applications,projects}/

指令

ArgoCD 安装与取初始密码:

kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d

Flux 安装与 bootstrap:

brew install fluxcd/tap/flux
# 或下载官方安装脚本,先审阅再执行(不要直接管道到 bash)
tmpdir="$(mktemp -d)"; trap 'rm -rf "$tmpdir"' EXIT
curl -fsSLo "$tmpdir/flux-install.sh" https://fluxcd.io/install.sh
sed -n '1,160p' "$tmpdir/flux-install.sh"
sudo bash "$tmpdir/flux-install.sh"

flux bootstrap github \
  --owner=org --repository=gitops-repo \
  --branch=main --path=clusters/production --personal

排障:

argocd app get my-app          # 查看应用状态
argocd app diff my-app         # 查看与 Git 的差异(OutOfSync)
argocd app sync my-app --prune # 同步并清理 Git 中已删除的资源
argocd app sync my-app --force # 强制同步

示例

ArgoCD Application(含自动同步策略):

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-app
  namespace: argocd
spec:
  project: default
  source:
    repoURL: https://github.com/org/gitops-repo
    targetRevision: main
    path: apps/production/my-app
  destination:
    server: https://kubernetes.default.svc
    namespace: production
  syncPolicy:
    automated:
      prune: true      # 删除 Git 中已移除的资源
      selfHeal: true   # 自动纠正手工漂移
      allowEmpty: false
    syncOptions:
    - CreateNamespace=true
    retry:
      limit: 5
      backoff: {duration: 5s, factor: 2, maxDuration: 3m}

App of Apps 模式:用一个父 Application 指向 argocd/applications 目录,统一纳管所有子应用,syncPolicy.automated: {} 即可。

Flux GitRepository + Kustomization:

apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata: {name: my-app, namespace: flux-system}
spec:
  interval: 1m
  url: https://github.com/org/my-app
  ref: {branch: main}
---
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata: {name: my-app, namespace: flux-system}
spec:
  interval: 5m
  path: ./deploy
  prune: true
  wait: true
  timeout: 5m
  sourceRef: {kind: GitRepository, name: my-app}

渐进发布(Argo Rollouts,金丝雀):

apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata: {name: my-app}
spec:
  replicas: 5
  strategy:
    canary:
      steps:
      - setWeight: 20
      - pause: {duration: 1m}
      - setWeight: 50
      - pause: {duration: 2m}
      - setWeight: 100

蓝绿则用 strategy.blueGreen,设 autoPromotionEnabled: false 由人工晋升。

密钥管理(二选一):

# External Secrets Operator:从外部密钥库拉取,不入库
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata: {name: db-credentials}
spec:
  refreshInterval: 1h
  secretStoreRef: {name: aws-secrets-manager, kind: SecretStore}
  target: {name: db-credentials}
  data:
  - secretKey: password
    remoteRef: {key: prod/db/password}
# Sealed Secrets:加密后再提交,可安全入库
kubeseal --format yaml < secret.yaml > sealed-secret.yaml

注意事项

互见


采编自 sickn33/antigravity-awesome-skills(MIT),适配重写。

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.