Moving the cluster onto GitOps
Where it started
The cluster’s applications were first installed by hand with helm install, one command at a time, with the settings kept in files in a Git repository. Git had the intended state, but nothing made the cluster actually match it. Anything changed by hand drifted silently, and rebuilding the cluster would mean a manual rebuild.
The goal
I wanted Git to be the single source of truth for what runs in the cluster. A change should only take editing a file and pushing it, undoing it should be a revert, and rebuilding from scratch should just mean pointing a fresh cluster at the repository.
How it works now
I used Argo CD with the app of apps pattern. One root application watches a folder in the repository; every file in that folder defines another application, such as Immich, Gitea, the monitoring stack or Loki. Adding an application to the cluster = new file
Each application syncs automatically, removes resources that were deleted from Git, and corrects anything changed by hand. The homelab page shows which components are deployed this way, and the live count of applications in sync with Git.
What went wrong
The migration itself caused an outage, because I moved seven applications to Argo CD at once. Argo CD rendered each Helm chart, found small differences from what was already running (labels, annotations, ordering) and redeployed all seven at the same moment. On a cluster with little spare memory, that redeploy storm exhausted every node: load averages above 50, with less than 200 MB of memory free. I had to restart k3s on the server node to stop it.
Three more problems surfaced while the cluster recovered:
- Argo CD couldn’t read the private repository. It had the address but no credentials. I gave it a read-only deploy key scoped to that one repository, so it didn’t need a personal access token.
- Pods with single-node volumes got stuck. The storm killed pods while they still held their storage, and their replacements were scheduled onto other nodes, where the volumes couldn’t attach until the old mounts were released.
- Some applications showed as out of sync forever. Helm charts that generate a random password create a new one each time they’re rendered, so Argo CD always saw a difference. Helm also labels everything it creates as Helm-managed, which Argo CD doesn’t. The fix was to tell Argo CD to ignore the generated secrets, use pre-created secrets for new installs, and drop the stale Helm labels.
Takeaways for a prod environment
- Migrate one application at a time, and watch the cluster’s resources while each one syncs.
- Decide how secrets reach the cluster before moving anything that has them.
- Adopting existing resources is different from deploying new ones. Expect Argo CD to see differences you didn’t know existed, and review the first diff before turning on automatic sync.