Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Deploy and manage Kubernetes workloads: manifests, RBAC, Helm charts, service mesh, GitOps, and troubleshooting.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/gitops.md
1# GitOps23---45## GitOps Principles671. **Declarative** - Entire system described declaratively82. **Versioned and immutable** - Desired state stored in Git93. **Pulled automatically** - Agents pull state from Git104. **Continuously reconciled** - Agents ensure actual matches desired1112## ArgoCD Installation1314```bash15# Create namespace16kubectl create namespace argocd1718# Install ArgoCD19kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml2021# Wait for pods22kubectl wait --for=condition=Ready pods --all -n argocd --timeout=300s2324# Get initial admin password25kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d2627# Install CLI28brew install argocd2930# Login31argocd login localhost:8080 --username admin --password <password>3233# Access UI34kubectl port-forward svc/argocd-server -n argocd 8080:44335```3637## ArgoCD Application3839```yaml40apiVersion: argoproj.io/v1alpha141kind: Application42metadata:43name: myapp44namespace: argocd45finalizers:46- resources-finalizer.argocd.argoproj.io47spec:48project: default49source:50repoURL: https://github.com/myorg/myapp-manifests.git51targetRevision: main52path: overlays/production53destination:54server: https://kubernetes.default.svc55namespace: production56syncPolicy:57automated:58prune: true59selfHeal: true60allowEmpty: false61syncOptions:62- CreateNamespace=true63- PrunePropagationPolicy=foreground64- PruneLast=true65retry:66limit: 567backoff:68duration: 5s69factor: 270maxDuration: 3m71revisionHistoryLimit: 1072```7374## ArgoCD ApplicationSet7576```yaml77apiVersion: argoproj.io/v1alpha178kind: ApplicationSet79metadata:80name: myapp-environments81namespace: argocd82spec:83generators:84- list:85elements:86- cluster: dev87namespace: development88revision: develop89- cluster: staging90namespace: staging91revision: main92- cluster: prod93namespace: production94revision: main95template:96metadata:97name: 'myapp-{{cluster}}'98spec:99project: default100source:101repoURL: https://github.com/myorg/myapp-manifests.git102targetRevision: '{{revision}}'103path: 'overlays/{{cluster}}'104destination:105server: https://kubernetes.default.svc106namespace: '{{namespace}}'107syncPolicy:108automated:109prune: true110selfHeal: true111```112113## ArgoCD with Helm114115```yaml116apiVersion: argoproj.io/v1alpha1117kind: Application118metadata:119name: myapp-helm120namespace: argocd121spec:122project: default123source:124repoURL: https://charts.example.com125chart: myapp126targetRevision: 1.2.0127helm:128releaseName: myapp129valueFiles:130- values-production.yaml131values: |132replicaCount: 5133image:134tag: v2.0.0135parameters:136- name: service.type137value: LoadBalancer138destination:139server: https://kubernetes.default.svc140namespace: production141```142143## ArgoCD Project144145```yaml146apiVersion: argoproj.io/v1alpha1147kind: AppProject148metadata:149name: production150namespace: argocd151spec:152description: Production applications153sourceRepos:154- 'https://github.com/myorg/*'155- 'https://charts.example.com'156destinations:157- namespace: production158server: https://kubernetes.default.svc159- namespace: production-*160server: https://kubernetes.default.svc161clusterResourceWhitelist:162- group: ''163kind: Namespace164namespaceResourceBlacklist:165- group: ''166kind: ResourceQuota167- group: ''168kind: LimitRange169roles:170- name: developer171description: Developer access172policies:173- p, proj:production:developer, applications, get, production/*, allow174- p, proj:production:developer, applications, sync, production/*, allow175groups:176- developers177```178179## Flux Installation180181```bash182# Install Flux CLI183brew install fluxcd/tap/flux184185# Check prerequisites186flux check --pre187188# Bootstrap Flux (GitHub)189flux bootstrap github \190--owner=myorg \191--repository=fleet-infra \192--branch=main \193--path=clusters/production \194--personal195196# Bootstrap Flux (GitLab)197flux bootstrap gitlab \198--owner=myorg \199--repository=fleet-infra \200--branch=main \201--path=clusters/production202```203204## Flux GitRepository205206```yaml207apiVersion: source.toolkit.fluxcd.io/v1208kind: GitRepository209metadata:210name: myapp211namespace: flux-system212spec:213interval: 1m214url: https://github.com/myorg/myapp-manifests215ref:216branch: main217secretRef:218name: github-credentials219ignore: |220# Exclude files221.git/222*.md223```224225## Flux Kustomization226227```yaml228apiVersion: kustomize.toolkit.fluxcd.io/v1229kind: Kustomization230metadata:231name: myapp232namespace: flux-system233spec:234interval: 10m235targetNamespace: production236sourceRef:237kind: GitRepository238name: myapp239path: ./overlays/production240prune: true241timeout: 2m242healthChecks:243- apiVersion: apps/v1244kind: Deployment245name: myapp246namespace: production247postBuild:248substitute:249environment: production250replicas: "5"251substituteFrom:252- kind: ConfigMap253name: cluster-vars254```255256## Flux HelmRepository257258```yaml259apiVersion: source.toolkit.fluxcd.io/v1beta2260kind: HelmRepository261metadata:262name: bitnami263namespace: flux-system264spec:265interval: 1h266url: https://charts.bitnami.com/bitnami267---268apiVersion: helm.toolkit.fluxcd.io/v2beta1269kind: HelmRelease270metadata:271name: redis272namespace: production273spec:274interval: 5m275chart:276spec:277chart: redis278version: '17.x'279sourceRef:280kind: HelmRepository281name: bitnami282namespace: flux-system283values:284architecture: standalone285auth:286enabled: true287existingSecret: redis-credentials288master:289persistence:290size: 10Gi291```292293## Flux ImageUpdateAutomation294295```yaml296apiVersion: image.toolkit.fluxcd.io/v1beta1297kind: ImageRepository298metadata:299name: myapp300namespace: flux-system301spec:302image: myregistry.io/myapp303interval: 1m304secretRef:305name: registry-credentials306---307apiVersion: image.toolkit.fluxcd.io/v1beta1308kind: ImagePolicy309metadata:310name: myapp311namespace: flux-system312spec:313imageRepositoryRef:314name: myapp315policy:316semver:317range: '>=1.0.0'318---319apiVersion: image.toolkit.fluxcd.io/v1beta1320kind: ImageUpdateAutomation321metadata:322name: myapp323namespace: flux-system324spec:325interval: 1m326sourceRef:327kind: GitRepository328name: myapp329git:330checkout:331ref:332branch: main333commit:334author:335email: [email protected]336name: fluxcdbot337messageTemplate: 'Update image to {{.NewTag}}'338push:339branch: main340update:341path: ./overlays/production342strategy: Setters343```344345## Progressive Delivery with Flagger346347```yaml348# Install Flagger349kubectl apply -k github.com/fluxcd/flagger/kustomize/istio350351---352apiVersion: flagger.app/v1beta1353kind: Canary354metadata:355name: myapp356namespace: production357spec:358targetRef:359apiVersion: apps/v1360kind: Deployment361name: myapp362progressDeadlineSeconds: 600363service:364port: 80365targetPort: 8080366gateways:367- myapp-gateway368hosts:369- myapp.example.com370analysis:371interval: 1m372threshold: 5373maxWeight: 50374stepWeight: 10375metrics:376- name: request-success-rate377thresholdRange:378min: 99379interval: 1m380- name: request-duration381thresholdRange:382max: 500383interval: 1m384webhooks:385- name: load-test386url: http://flagger-loadtester.test/387timeout: 5s388metadata:389cmd: "hey -z 1m -q 10 -c 2 http://myapp-canary.production:80/"390```391392## Sealed Secrets393394```bash395# Install controller396kubectl apply -f https://github.com/bitnami-labs/sealed-secrets/releases/download/v0.24.0/controller.yaml397398# Install kubeseal CLI399brew install kubeseal400401# Create sealed secret402kubectl create secret generic db-credentials \403--from-literal=username=admin \404--from-literal=password=secret123 \405--dry-run=client -o yaml | \406kubeseal --format yaml > sealed-db-credentials.yaml407408# Apply sealed secret409kubectl apply -f sealed-db-credentials.yaml410```411412```yaml413apiVersion: bitnami.com/v1alpha1414kind: SealedSecret415metadata:416name: db-credentials417namespace: production418spec:419encryptedData:420username: AgBy8h...encrypted...421password: AgCtr2...encrypted...422template:423type: Opaque424metadata:425labels:426app: myapp427```428429## SOPS with Age430431```bash432# Install SOPS433brew install sops434435# Generate age key436age-keygen -o age.agekey437438# Create SOPS config439cat > .sops.yaml << EOF440creation_rules:441- path_regex: .*\.enc\.yaml$442encrypted_regex: ^(data|stringData)$443age: age1...publickey...444EOF445446# Encrypt secret447sops --encrypt --in-place secrets.enc.yaml448449# Configure Flux decryption450kubectl create secret generic sops-age \451--namespace=flux-system \452--from-file=age.agekey453```454455```yaml456# Flux Kustomization with SOPS457apiVersion: kustomize.toolkit.fluxcd.io/v1458kind: Kustomization459metadata:460name: myapp461namespace: flux-system462spec:463decryption:464provider: sops465secretRef:466name: sops-age467# ... rest of spec468```469470## Repository Strategies471472### Mono-repo473```474fleet-repo/475├── apps/476│ ├── myapp/477│ │ ├── base/478│ │ └── overlays/479│ └── another-app/480├── infrastructure/481│ ├── cert-manager/482│ └── ingress-nginx/483└── clusters/484├── dev/485├── staging/486└── production/487```488489### Multi-repo490```491# App repos (one per app)492myapp-manifests/493├── base/494└── overlays/495496# Infrastructure repo497infrastructure/498├── cert-manager/499└── ingress-nginx/500501# Fleet repo (references others)502fleet-infra/503├── apps.yaml # Points to app repos504└── infra.yaml # Points to infra repo505```506507## ArgoCD vs Flux Comparison508509| Feature | ArgoCD | Flux |510|---------|--------|------|511| UI | Built-in web UI | Third-party (Weave GitOps) |512| Multi-tenancy | AppProject | Namespaced resources |513| Helm | Native support | HelmController |514| Image automation | ArgoCD Image Updater | Native ImagePolicy |515| Notifications | ArgoCD Notifications | Alerts/Receivers |516| RBAC | Built-in | Kubernetes RBAC |517| Architecture | Centralized | Distributed |518519## Best Practices5205211. **Use separate repos** for app code and manifests5222. **Protect main branch** with required reviews5233. **Use sealed secrets or SOPS** for sensitive data5244. **Enable auto-sync with prune** for drift correction5255. **Set up notifications** for sync failures5266. **Use ApplicationSets/Kustomizations** for multi-environment5277. **Implement progressive delivery** for safe rollouts5288. **Version your Helm charts** semantically5299. **Keep manifests DRY** with Kustomize overlays53010. **Monitor reconciliation metrics** and alerts531