Sub topic 15
When to choose GitOps (Argo CD, Flux) instead
This chapter assumes you have followed the earlier chapters. You know how a GitHub Actions workflow builds an image, authenticates to a cluster, runs kubectl set image, and checks the rollout. Here you compare that push-based approach with pull-based GitOps and decide which one fits your situation.
Push versus pull
In the pipeline you built, the workflow pushes changes into the cluster. The runner holds credentials (a kubeconfig secret or an OIDC-issued identity) and calls the Kubernetes API from outside.
GitOps reverses the direction. A controller runs inside the cluster, watches a Git repository, and pulls the desired state from it. Argo CD and Flux are the two common tools. The controller compares what Git says with what the cluster runs, and it fixes any difference. This is called reconciliation.
With GitOps, CI still builds and pushes the image. The last CI step changes from kubectl set image to a commit that updates the image tag in a config repository. The controller does the rest.
What GitOps gives you
- No cluster credentials in CI. The runner needs write access to a Git repository, not to the Kubernetes API. This removes the kubeconfig secret and shrinks the blast radius of a leaked CI token.
- Drift correction. If someone edits a Deployment with
kubectl edit, the controller detects the difference and can revert it. A push pipeline only changes the cluster when it runs. - Git as the audit trail. Every change to the cluster is a commit with an author, a review, and a revert option. Rollback becomes
git revert. - Many clusters. One repository can drive dozens of clusters, each running its own controller. A push pipeline needs credentials for every cluster.
What it costs
- More moving parts. You install and upgrade a controller, and you learn its resources, such as an Argo CD
Applicationor a FluxKustomization. - A second repository or path. Image tags must be written back to Git, usually through a bot commit or an image-update component. This adds a step and a possible failure.
- Slower, less direct feedback. The workflow no longer waits on
kubectl rollout status. Success is visible in the controller's status, so you need notifications or a status check to see failures. - Secrets still need a plan. Git should not hold plain secrets. You need a tool such as Sealed Secrets or the External Secrets Operator.
Choosing
| Situation | Better fit |
|---|---|
| One or two clusters, small team, simple Deployments | Push with GitHub Actions |
| You want the pipeline result to include rollout success | Push |
| Many clusters or many teams | GitOps |
| Security policy forbids CI access to the API server | GitOps |
| You need automatic drift correction and a full audit trail | GitOps |
The two are not exclusive. Many teams keep GitHub Actions for build and test, then hand deployment to Argo CD or Flux. A reasonable path is to start with the push pipeline from this tutorial and move to GitOps when credential management or cluster count becomes the main pain.
Exercise
Your team runs 12 clusters and a security review rejects giving CI a credential for each of them. Which approach fits better, and what does the final CI step become?
Show answer
GitOps. CI still builds and pushes the image, but the last step commits the new image tag to the config repository instead of running kubectl. The controller in each cluster pulls the change and applies it, so CI holds no cluster credentials.
Exercise
Name two things you lose or must add when moving from a push pipeline to GitOps.
Show answer
You lose the in-workflow kubectl rollout status check, so you need controller notifications or status checks to see failed rollouts. You must also add a controller to operate and a way to write image tags back to Git, plus a secrets approach that keeps plain secrets out of the repository.