Before GitOps: what does your CI pipeline actually change?
Before moving to Argo CD, find the manual fixes made in the cluster, bring the live manifests into git, and turn on self-heal step by step.
While planning the move to Argo CD, one question kept coming up: there are manual fixes in the cluster. Replica counts were raised, probe timings were stretched, resource limits were changed. Will the next deploy overwrite them? And if not, where are they written down?
Symptoms
- The answer to "why does this deployment have 4 replicas?" isn't in git.
- The same application runs with different probes and limits in two clusters, and nobody knows why.
- The values in the Helm chart or manifest repo don't match the values in the cluster.
Why does it happen?
In environments like this, most of the CI pipeline comes down to a single line:
kubectl set image deployment/x c=registry.example.com/x:${CI_COMMIT_SHA}
That command changes only the image. Replicas, probes, resources, environment variables: CI never touches any of them. The result splits in two:
- The good news: manual fixes aren't overwritten on deploy; they survive.
- The bad news: those fixes aren't written down anywhere. The only source of truth is the cluster itself. This is called drift.
This is exactly where a GitOps tool gets dangerous. It treats the old manifest in git as "correct" and, with self-heal on, reverts every manual fix in the cluster within minutes.
Diagnosis and migration steps
- Export the live manifests. Open a separate repo or folder per cluster. Strip the fields the cluster fills in itself, like
status,managedFields,resourceVersionanduid.
ns=app
for kind in deployment statefulset service configmap ingress cronjob; do
for name in $(kubectl -n "$ns" get "$kind" -o name); do
mkdir -p "clusters/$CLUSTER/$ns"
kubectl -n "$ns" get "$name" -o yaml \
| yq 'del(.status,
.metadata.managedFields,
.metadata.resourceVersion,
.metadata.uid,
.metadata.creationTimestamp,
.metadata.generation,
.metadata.annotations."kubectl.kubernetes.io/last-applied-configuration",
.metadata.annotations."deployment.kubernetes.io/revision",
.spec.clusterIP, .spec.clusterIPs)' \
> "clusters/$CLUSTER/$ns/${name//\//_}.yaml" # deployment.apps/x -> deployment.apps_x.yaml
done
done
Secrets are deliberately left out of this loop. They must not go into git as plain text.
- Diff the clusters against each other. If the same application differs between two clusters, that is either a deliberate decision or a forgotten fix. Ask the owner which one it is.
diff -ru clusters/a/app clusters/b/app
-
Create the Argo CD applications with auto-sync and self-heal off. At this stage Argo CD only watches. The "OutOfSync" diff in the UI shows you the real difference between git and the cluster. Fix git until that diff is zero.
-
Once the diff is zero, turn on self-heal. From now on, git is the source of truth.
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: app-x
namespace: argocd
spec:
project: apps
source:
repoURL: https://git.example.com/platform/manifests.git
targetRevision: main
path: clusters/a/app
destination:
server: https://kubernetes.default.svc
namespace: app
syncPolicy:
# in step 3 this automated block doesn't exist at all; Argo CD only shows the diff
automated:
prune: false # turn deletion on last
selfHeal: true
syncOptions:
- CreateNamespace=false
- Clarify the role of CI. There are two options. CI keeps doing image bumps only, and the image field is ignored in Argo CD. Or, the cleaner one: CI writes to git instead of the cluster, updating the image tag in the manifest.
yq -i '.spec.template.spec.containers[0].image = "registry.example.com/x:" + strenv(CI_COMMIT_SHA)' \
clusters/a/app/deployment.apps_x.yaml
git commit -am "x: image ${CI_COMMIT_SHA}" && git push
Watch out
- AppProject restrictions. Argo CD AppProjects are often set up to block cluster-scoped resources (CRDs, ClusterRoles and the like). Some applications won't sync because of that. Either apply those resources manually, or widen the restriction deliberately and write down why.
rollout restart. A manual restart adds an annotation to the pod template. Self-heal reverts it. That's harmless, but surprising the first time you see it.- Secrets. No plain-text secrets go into git. Pick a separate approach, such as Sealed Secrets or External Secrets, and decide on it before the GitOps migration.
prune. Turn on deletion of resources that aren't in git last. A resource missed during export disappears silently with prune.
Lesson
Moving to GitOps isn't installing a tool; it's moving the source of truth from the cluster to git. First write down what the cluster is today, then give git the final say.
Checklist
- [ ] Is it clear, item by item, what the CI pipeline changes in the cluster?
- [ ] Have the live manifests been cleaned up and committed to git per cluster?
- [ ] Have the owners been asked about the differences between clusters?
- [ ] Were the Argo CD applications created with auto-sync and self-heal off first?
- [ ] Was self-heal kept off until the "OutOfSync" diff reached zero?
- [ ] Has a separate method been chosen for secrets?
- [ ] Is CI's new role (image bumps or writing to git) settled?