AgentSkillsCN

gitops-patterns

基于 ArgoCD 和 Flux 的 GitOps 实践模式

SKILL.md
--- frontmatter
name: gitops-patterns
description: GitOps patterns with ArgoCD and Flux

GitOps Patterns

Git as the source of truth for infrastructure.


GitOps Flow

code
Code Change → PR → Merge → CI Build → Image Push → Git Sync → Deploy
StepTool
CI BuildAzure DevOps
Image PushAzure Container Registry
Git SyncArgoCD / Flux
DeployAKS

Repository Structure

code
gitops-repo/
├── base/                 # Base manifests
│   ├── deployment.yaml
│   ├── service.yaml
│   └── kustomization.yaml
├── overlays/
│   ├── dev/
│   │   └── kustomization.yaml
│   ├── staging/
│   │   └── kustomization.yaml
│   └── prod/
│       └── kustomization.yaml

ArgoCD Application

yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: myapp
  namespace: argocd
spec:
  project: default
  source:
    repoURL: https://github.com/org/gitops-repo
    targetRevision: HEAD
    path: overlays/prod
  destination:
    server: https://kubernetes.default.svc
    namespace: production
  syncPolicy:
    automated:
      prune: true
      selfHeal: true

Flux Configuration

yaml
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
  name: myapp
spec:
  interval: 1m
  url: https://github.com/org/gitops-repo
  ref:
    branch: main
---
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: myapp
spec:
  interval: 10m
  path: ./overlays/prod
  sourceRef:
    kind: GitRepository
    name: myapp

DO / DON'T

✅ Do❌ Don't
Git for all changeskubectl apply manually
Automated syncManual deployments
Environment overlaysDuplicate manifests
PR reviewsDirect pushes