Field Notes: GitOps in Production
Short notes from GitOps setups that went wrong, each with the habit that prevents it. The linked lessons have the mechanics.
One owner per object
The most common GitOps incident is two writers: CI still runs helm upgrade "just for this one service", an operator patches a field, a second Argo CD Application (or a Flux Kustomization) includes the same manifest. Each overwrites the other on every pass, and the object flaps. Rules: CI never deploys to clusters an agent manages; each manifest is in exactly one Application or Kustomization (Argo CD's FailOnSharedResource=true turns sharing into an error); fields owned by controllers (HPA replicas, Rollouts weights, injected sidecars) are left out of Git or ignored (Drift).
Break-glass, written down before you need it
When production is on fire and the Git path is slow, someone will change the cluster by hand. Make it a procedure, not an improvisation:
- Announce it in the incident channel.
- Pause the agent for that app only:
argocd app set APP --sync-policy noneorflux suspend kustomization KS. - Make the manual change; note the exact command.
- Open the PR that makes Git match the cluster (or reverts the release); merge it.
- Re-enable automation and confirm the app is Synced/Ready and still healthy.
- Alert on anything left suspended or with automation off for more than a day.
Check your guard rails in CI, not in review
Reviewers miss things like a release candidate promoted to production or a latest tag. A short script over the deploy repo catches them every time:
mkdir -p apps/linkly/staging apps/linkly/production apps/shortstats/production apps/qrcodes/production
printf 'image: {tag: 1.5.0-rc.2}\n' > apps/linkly/staging/values.yaml
printf 'image: {tag: 1.5.0-rc.2}\n' > apps/linkly/production/values.yaml # promoted too early
printf 'image: {tag: latest}\n' > apps/shortstats/production/values.yaml # a moving tag
printf 'image: {tag: 2.1.0}\n' > apps/qrcodes/production/values.yaml
cat > policy.sh <<'EOF'
#!/usr/bin/env bash
# Production must run immutable release versions: X.Y.Z or a digest.
status=0
for f in apps/*/production/values.yaml; do
tag=$(yq '.image.tag // ""' "$f")
if [[ "$tag" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ || "$tag" =~ ^sha256:[0-9a-f]{64}$ ]]; then
echo "ok $f: $tag"
else
echo "FAIL $f: '$tag' is not a release version"; status=1
fi
done
exit $status
EOF
bash policy.sh; echo "exit code: $?"FAIL apps/linkly/production/values.yaml: '1.5.0-rc.2' is not a release version
ok apps/qrcodes/production/values.yaml: 2.1.0
FAIL apps/shortstats/production/values.yaml: 'latest' is not a release version
exit code: 1
Grow this into real policy-as-code (Conftest or Kyverno CLI over the rendered manifests) when the rules multiply.
Caches lie, briefly
Argo CD's repo-server caches rendered manifests per commit, and Helm charts per version. If you re-push a chart under the same version, or a remote Kustomize base moves under a branch ref, Argo CD keeps the cached render. argocd app get APP --hard-refresh clears it, but the lesson is: never mutate a published version, and pin remote bases to tags or SHAs.
Big monorepos make every app slow
Every commit to a monorepo makes Argo CD re-render every Application that tracks it. Tell it which paths matter with the annotation argocd.argoproj.io/manifest-generate-paths: . on each Application (with Git webhooks configured), and split rarely-changing infrastructure from fast-moving apps. Flux's per-source ignore rules and separate GitRepository objects per area achieve the same.
CRDs need special care
- Helm installs CRDs from a chart's
crds/folder but never upgrades or deletes them. Under Argo CD the CRDs are applied like other objects; Flux's HelmRelease hasinstall.crds/upgrade.crds(Create,CreateReplace,Skip) to choose. - Large CRDs exceed the client-side
last-applied-configurationannotation limit: useServerSideApply=truein Argo CD (Flux always uses server-side apply). - Never let pruning delete a CRD: that deletes every custom resource of that kind, cluster-wide. Annotate CRDs with
Prune=false/kustomize.toolkit.fluxcd.io/prune: disabled.
Hub-and-spoke has a blast radius
One Argo CD managing fifty clusters is convenient until its credentials leak (fifty clusters) or an upgrade breaks it (no deploys anywhere). Either keep the hub small, locked down and highly available, or run an agent per cluster and centralise only visibility. Many teams split: an Argo CD per environment tier (non-prod, prod), never one for everything.
Bootstrap has a chicken-and-egg secret
Something has to exist before Git can be read: the deploy key, the SOPS age key, the External Secrets credentials. Keep that list short, create it with your cluster provisioning (Terraform, a sealed bootstrap script), store the originals in a password manager or KMS, and test a full cluster rebuild from Git at least once. "Can we recreate production from the repo?" is the real test of a GitOps setup.
Make the deployed revision visible
Put the Git revision on what you run: Argo CD and Flux both report it, but also pass it into the app (an env var or label set from the commit), expose it on /version and in metrics, and have the agent post commit statuses to the deploy repo. During an incident, "which commit is live?" should take seconds.
Test yourself
CI runs helm upgrade for a service that Argo CD also manages with self-heal on. What happens?
- CI wins
- Argo CD wins
- Each overwrites the other, so the object flaps between versions
- Kubernetes rejects the second writer
Why should pruning never be allowed to delete a CRD?
- CRDs can't be recreated
- Deleting a CRD deletes every custom resource of that kind in the whole cluster
- It breaks kubectl
- It's slow
What is the best end-to-end test that a GitOps setup is complete?
- A green CI pipeline
- Rebuilding a cluster from scratch using only Git plus the minimal bootstrap secrets
- Counting Applications
- Running argocd app list