5 min read

Advanced GitOps - Deploy Automation, Rollback and Best Practices for Production

1. Recap: From Manual Sync to Confidence in Production

So far, this series has covered enough to operate Kubernetes with GitOps day to day: core concepts of Pods, Deployments and Services, kubectl, namespaces, ConfigMaps and Secrets, and an introduction to ArgoCD with an Application syncing a repository to the cluster. This last article closes the gap between “ArgoCD is installed” and “I trust this pipeline to put changes into production without constant supervision”: full deploy automation, automatic rollback, more refined sync policies and the best practices that separate a demo setup from a production-ready one.

2. Automating the Deploy End to End

A complete GitOps pipeline usually combines CI (which builds and tests the application) with CD via ArgoCD (which applies the result to the cluster). CI doesn’t apply anything directly to the cluster — its only responsibility is to update the manifests repository with the new version, letting ArgoCD detect and apply the change:

# .github/workflows/deploy.yml
name: build-and-release
on:
  push:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Build and push the image
        run: |
          docker build -t registry.example.com/my-app:${{ github.sha }} .
          docker push registry.example.com/my-app:${{ github.sha }}

      - name: Update the image tag in the manifests repository
        run: |
          git clone https://github.com/my-org/my-app-manifests.git
          cd my-app-manifests
          kustomize edit set image my-app=registry.example.com/my-app:${{ github.sha }}
          git commit -am "deploy: my-app@${{ github.sha }}"
          git push

That last step — an automated commit to the manifests repository, swapping the image tag — is the trigger that makes ArgoCD (with syncPolicy.automated configured, as seen in the previous article) detect the difference and apply the rollout automatically, without the CI pipeline needing any credentials to access the cluster. This separation — CI only writes to Git, only ArgoCD writes to the cluster — is the core of what makes GitOps safer than a traditional CI pipeline running kubectl apply directly.

3. Automatic Rollback

One of the most concrete gains of GitOps shows up when a deploy goes wrong. Since every change is a commit, reverting a problematic deploy is, in principle, as simple as reverting the commit:

# Revert the last commit that changed the image tag
git revert HEAD
git push

ArgoCD detects this revert like any other change to the repository and applies it automatically, taking the cluster back to the previous state. This can (and should) be combined with automatic health checks, so the rollback happens without waiting for someone to notice manually that something broke:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-app
  namespace: argocd
spec:
  # ...
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    retry:
      limit: 3
      backoff:
        duration: 30s
        factor: 2
        maxDuration: 5m

The retry block makes ArgoCD retry a failed sync, with exponential backoff — useful for transient failures (a readiness probe that takes a bit longer than usual, for example) without requiring manual intervention. For automatic rollback based on the application’s actual health (not just on sync success), complementary tools like Argo Rollouts add progressive delivery strategies — canary or blue-green — that automatically promote or revert a new version based on metrics (error rate, latency) collected during the rollout.

4. More Refined Sync Policies

Not every change should be synced automatically and without review. ArgoCD lets you refine this per Application:

spec:
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - CreateNamespace=true
      - ApplyOutOfSyncOnly=true
  ignoreDifferences:
    - group: apps
      kind: Deployment
      jsonPointers:
        - /spec/replicas
  • CreateNamespace=true creates the destination namespace automatically if it doesn’t exist yet — avoiding a manual setup step before a new application’s first deploy.
  • ApplyOutOfSyncOnly=true applies only the resources that actually diverge from Git, reducing the “noise” of reapplying everything on every sync.
  • ignoreDifferences tells ArgoCD to ignore divergences in a specific field — in the example, spec/replicas of Deployments, useful when a Horizontal Pod Autoscaler (HPA) adjusts the number of replicas dynamically and you don’t want ArgoCD reverting that adjustment to the fixed value declared in Git.

In environments with multiple teams, it’s also common to restrict permissions through ArgoCD’s AppProject — limiting which repositories, clusters and namespaces each Application can use as source or destination, instead of giving any Application that gets created unrestricted access to the whole cluster.

5. Best Practices for Production

A few practices that separate a demo GitOps cluster from a production-ready one:

  • Never commit Secrets in plain text — revisiting the point raised in Article 2 of this series: use Sealed Secrets, SOPS or integration with an external vault (Vault, AWS Secrets Manager) to version secrets safely within the GitOps flow.
  • Separate application and manifests repositories — the repository with the application’s source code and the one with the Kubernetes manifests are usually different, each with its own access control; this also prevents a push to the code from accidentally triggering an ArgoCD sync before the image is ready.
  • Mandatory review for production — even with automatic sync turned on, protect the branch/folder that points to production by requiring a reviewed pull request, so no change reaches the cluster without at least a second pair of eyes.
  • Monitor ArgoCD itself — a GitOps controller that’s down (or with sync stuck) means urgent changes, including rollbacks, don’t reach the cluster; alerts on ArgoCD’s health are as important as alerts on the application itself.
  • Start with manual sync, move to automatic gradually — for critical applications, it’s reasonable to start without syncPolicy.automated, validate the process with reviewed manual syncs, and only turn on automation once the team trusts the CI pipeline and the tests that precede it.

6. Series Conclusion

Over these four articles, this series went from “what is a Pod” to a complete GitOps pipeline: Kubernetes core concepts (Pods, Deployments, Services), kubectl and organizing resources with namespaces, ConfigMaps and Secrets, an introduction to GitOps and ArgoCD, and finally end-to-end deploy automation, automatic rollback through Git and the best practices that make this flow safe enough for production. From here, the groundwork is laid to explore more specific topics — progressive delivery with Argo Rollouts, secret management with Sealed Secrets or Vault, cluster observability — but the Kubernetes + GitOps pair, well implemented, already solves most of the challenge of operating applications in production with confidence and traceability.


References:

  1. ArgoCD Documentation — Sync Policies
  2. Argo Rollouts Documentation
  3. Bitnami Sealed Secrets
  4. OpenGitOps — GitOps Principles