Managing Kubernetes deployments with kubectl apply works until you stop knowing what is actually running in the cluster. The change history lives in the head of whoever ran the command, rollbacks are manual, and the state declared in the manifests starts drifting from the real one. GitOps solves that by inverting the model: Git is the source of truth, and the cluster continuously reconciles toward it.
This is the architecture we run in production on GKE Autopilot, with ArgoCD as the sync engine.
The base infrastructure: two clusters, one fleet
The setup runs on two GKE Autopilot clusters connected through GKE Fleet — GCP's unified control plane for managing multiple clusters as a single unit. ArgoCD is installed only on the primary cluster and manages both from there. The secondary cluster has no ArgoCD of its own: it receives its deployments from the primary through the Fleet.
Choosing Autopilot over Standard removes node pool management and simplifies operations — no sizing nodes or managing infrastructure scaling by hand. The trade-off is less control over node configuration, but for this kind of workload it's worth it.
ArgoCD manages itself
ArgoCD is installed from the official manifests in the project's GitHub repository, not via Helm. The manifests live in GitLab, in a platform apps repository, and ArgoCD uses them to deploy itself on the primary cluster.
This is no minor detail: it means every ArgoCD upgrade follows the same GitOps flow as every other application. Nobody runs kubectl apply by hand to upgrade the controller. You commit to the repo, ArgoCD detects the change and updates itself. The controller's own version history lives in Git, audited and reversible like any other component.
The manifest that makes this loop possible is an Application pointing at the platform apps repository itself:
# platform-apps/argocd/application.yaml
# ArgoCD Application that manages ArgoCD itself
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: argocd
namespace: argocd
spec:
project: default
source:
repoURL: git@gitlab.com:platform/platform-apps.git
targetRevision: main
path: argocd/manifests
destination:
server: https://kubernetes.default.svc
namespace: argocd
syncPolicy:
automated:
prune: true
syncOptions:
- ServerSideApply=true Platform apps: one repo, every operator
Besides ArgoCD, the platform apps repo holds the manifests for the cluster operators:
- External Secrets Operator (ESO) — secret injection from GCP Secret Manager.
- KEDA — event-driven autoscaling.
- External DNS — automatic DNS record management.
- Cert Manager — TLS certificate issuance and renewal.
Each one has its own ApplicationSet configured to deploy to every cluster in the Fleet. The logic is simple: these operators are cross-cutting infrastructure. It makes no sense to manage them app by app — they're declared once and propagated to every environment.
The -k8s convention: onboarding with no manual configuration
This is the piece with the biggest day-to-day impact. Every application has two repositories in GitLab: the source code repository and a Kubernetes manifests repository. The latter always follows the same naming convention: the application name with the -k8s suffix.
The ApplicationSet uses that suffix as a selector. Any repository ending in -k8s is automatically discovered and deployed by ArgoCD:
# platform-apps/applicationsets/apps.yaml
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: apps
namespace: argocd
spec:
generators:
- scmProvider:
gitlab:
group: applications
allBranches: false
# The convention: any repo ending in -k8s is auto-discovered
filters:
- repositoryMatch: ".*-k8s$"
template:
metadata:
name: '{{repository}}'
spec:
project: default
source:
repoURL: '{{url}}'
targetRevision: HEAD
path: '.'
destination:
server: https://kubernetes.default.svc
# Namespace inferred from the repo name (without the -k8s suffix)
namespace: '{{ index .repository | replace "-k8s" "" }}'
syncPolicy:
automated:
prune: true The practical result: to bring a new application into the cluster, you just create the manifests repository with the right name. ArgoCD takes care of the rest with no extra configuration.
This removes the step that, in many setups, requires someone with ArgoCD access to register the new application by hand. Onboarding is declarative and governed by the repository naming convention.
Secrets: Secret Manager, IAM conditions and Workload Identity
Secrets for every application live in a GCP project dedicated exclusively to that purpose, separate from the projects where the clusters run. ESO injects them into the cluster at runtime using Workload Identity — no static credentials, no JSON keys.
Access control is handled with IAM conditions on the secrets' naming convention. For example, every secret starting with external-dns-* can only be accessed by the External DNS service account:
# Manifest in the app's -k8s repo
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: external-dns
namespace: external-dns
spec:
refreshInterval: 1h
secretStoreRef:
name: gcp-secret-store
kind: ClusterSecretStore
target:
name: external-dns-credentials
data:
- secretKey: credentials.json
remoteRef:
# Naming convention: external-dns-* prefix is the access boundary
key: external-dns-gcp-sa-key The IAM condition is defined at the project level and restricts access by secret name prefix:
# IAM binding scoped by name prefix
# Only secrets matching external-dns-* are accessible to this SA
gcloud projects add-iam-policy-binding secrets-project \
--member="serviceAccount:external-dns@<PROJECT_ID>.iam.gserviceaccount.com" \
--role="roles/secretmanager.secretAccessor" \
--condition='expression=resource.name.startsWith("projects/_/secrets/external-dns-"),title=external-dns-only,description=Restrict access to external-dns secrets' Each application can only access its own subset of secrets, filtered by prefix. This scheme avoids the usual problem of granting overly broad access to Secret Manager. There's no need to manage permissions per individual secret — the naming convention does the work.
Sync: auto-sync without self-heal
ArgoCD is configured with auto-sync enabled, but with self-heal deliberately disabled.
Self-heal automatically reverts any manual change in the cluster that drifts from what's declared in Git. In theory that's desirable. In practice, when someone needs to apply a temporary change to debug a production issue — tweak an environment variable, adjust a replica count, inject a flag — self-heal undoes it immediately and creates conflicts at the worst possible moment.
syncPolicy:
automated:
prune: true
# selfHeal is intentionally off
# Manual changes are allowed for debugging in production
# selfHeal: false
syncOptions:
- CreateNamespace=true
- PrunePropagationPolicy=foreground Turning it off is a conscious trade-off: we accept that temporary drift may exist in the cluster in exchange for being able to intervene by hand when the situation calls for it. The drift is resolved by the next commit to the manifests repository.
The full flow: from a commit to production
The deployment cycle works like this:
- The developer pushes to the source code repository.
- GitLab CI builds the image and pushes it to Artifact Registry.
- The pipeline clones the manifests repository (
-k8s), updates the image tag with Kustomize, and commits the change. - ArgoCD detects the new commit in the manifests repository and syncs the cluster toward the newly declared state.
The GitLab CI job that implements steps 2 and 3 is fairly simple:
# .gitlab-ci.yml in the application source repo
deploy:
stage: deploy
image: gcr.io/google.com/cloudsdktool/cloud-sdk:slim
before_script:
- apt-get update && apt-get install -y kustomize git
script:
# Build image tag from the commit SHA
- IMAGE_TAG="${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}"
# Clone the matching manifests repo (convention: <app>-k8s)
- git clone "https://oauth2:${MANIFESTS_TOKEN}@gitlab.com/applications/${CI_PROJECT_NAME}-k8s.git"
- cd "${CI_PROJECT_NAME}-k8s"
# Update only the image tag — Kustomize handles the rest
- kustomize edit set image "app=${IMAGE_TAG}"
# Commit and push. ArgoCD picks it up automatically.
- git config user.email "ci-bot@example.com"
- git config user.name "GitLab CI"
- git commit -am "ci: bump image to ${CI_COMMIT_SHORT_SHA}"
- git push origin main
only:
- main There is no direct push to the cluster from the pipeline. The pipeline only updates Git. ArgoCD pulls and applies the changes. That separation is the essence of the GitOps model: the cluster never takes direct instructions from the CI system, it only reconciles against its source of truth.
What's next
Rollback and the disaster recovery strategy are the open items in this architecture — areas still being worked on. They're complex enough to deserve their own post, with the decisions and trade-offs they involve.
No comments yet