4 min readDevang Pandya
GitOps with Argo CD, without letting main delete production
How I put Argo CD in front of a cluster. Promotion is a git change, secrets stay out of the repo, and automated prune is a decision you make later.
- Kubernetes
- GitOps
- Argo CD
GitOps, in the form I will actually run, means the cluster is a copy of a git path, and the only supported way to change production is to change that path. Argo CD is the reconciler. It is not your CI system. CI builds the image, runs the tests, and bumps a tag in git. Argo applies git. Mixing those two jobs is how a green test suite becomes a production deploy you did not mean to make.
Start without automated sync
The first Application I write does not sync itself. Someone looks at the diff and clicks Sync, in non-production, until the path has been boring for a while. Automated prune is powerful: if you delete a manifest, Argo deletes the object, including a namespace you removed from git. That is the feature. It is a poor default on the first afternoon.
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: billing-api
namespace: argocd
spec:
project: billing
source:
repoURL: https://github.com/example/gitops
path: apps/billing-api/prod
targetRevision: main
destination:
server: https://kubernetes.default.svc
namespace: billing
syncPolicy:
syncOptions:
- CreateNamespace=false
example/gitops is a placeholder, not a repository of mine. CreateNamespace=false is deliberate. Namespaces are created by a platform change, not as a side effect of the first sync of an application.
When you later turn automation on, this is the block, and I want the reason written next to it:
syncPolicy:
automated:
prune: true
selfHeal: true
Self-heal means a hotfix applied with kubectl is reverted. Agree that with the person who gets paged. If the on-call path is still "edit the deployment live", you are not ready for self-heal, and pretending otherwise just makes the next incident worse.
Pointing production at the same branch your application CI pushes to, with prune on, means every merge is a production deploy. Some teams want that. Most teams who say they want it have not decided what a rollback is. A separate path per environment, and a pull request to change the production tag, is the promotion model I start with. The image tag in git is the release. Argo does not build it.
Projects, not the default project
The default AppProject can sync any repository into any namespace. That is too open the moment a second team has access to the Argo UI. Create a project that allows one repo and one destination namespace group. A mistake then fails the sync instead of installing a chart into kube-system.
Argo's own credential for the git repository is a GitHub App or a read-only deploy key. It is not a personal access token from whoever set the cluster up. When that person leaves, the cluster should not lose the ability to read git, and their token should not still be able to write to it.
Secrets do not go in git
A Kubernetes Secret committed next to the Deployment will end up in the repo history. I use External Secrets, pointed at AWS Secrets Manager or SSM, or SOPS if the team already operates the keys. Sealed Secrets is fine when you already run it well. A new platform does not need a third secrets invention.
The Application manifest may name the secret. The value stays in AWS, encrypted, with a role the External Secrets controller assumes via IRSA. The application role and the Argo role are not the same role.
The UI and the health of things Argo does not understand
Put SSO in front of the Argo UI. Do not hang it on a public load balancer with the default admin password because "we will lock it down after the migration". The UI can sync production. Treat it that way.
Argo marks a custom resource Healthy when the resource exists, unless you teach it otherwise. A CRD that creates a Deployment can be Healthy while the pods are not. Add a health check, or watch the workload the CRD owns, before you trust the green icon in prod.
Argo itself is a deployment you have to upgrade. Put that upgrade on the same calendar as the cluster. A GitOps tool nobody patches is just another control plane you are afraid of.
One application, then the pattern
I start with a single non-production service. The repo layout, the project, the secret path, and the person who is allowed to sync all get invented there. An ApplicationSet or an app-of-apps is how you stop copying YAML once the first one is dull. It is a poor way to discover that your Helm chart does not template the namespace correctly, forty times.
If the cluster is EKS, the deploy path is part of the Kubernetes work, not a plugin you bolt on after the migration weekend. The migration is done when a second person can ship without asking the person who built the cluster.
Want this looked at in your account?
Devang Pandya works through these problems with teams who already have something in production. Tell us what is in the way.