How to Implement GitOps in Kubernetes
Practical step-by-step guidance to implement GitOps for Kubernetes using Argo CD or Flux.
GitOps is a powerful pattern, but successful adoption requires careful design and incremental rollout. This article provides a practical, step-by-step guide to implementing GitOps for Kubernetes clusters, including repository layout, controller selection, CI integration, secrets management, and operational best practices.
1. Choose a GitOps controller
Start by evaluating the two mainstream controllers:
- Argo CD: Rich UI, strong multi-cluster support, declarative apps model, and many ecosystem integrations. Good when teams want visibility and a battle-tested UI.
- Flux: Lightweight, Git-native, tightly integrated with the CNCF ecosystem and image automation workflows. Good when you prefer Git-first automation and scripts over a UI.
Either choice works; pick one that aligns with your team's workflow, multi-cluster strategy, and extension needs.
2. Design repository layout
Your repo layout determines scalability, ownership, and permissions. Common patterns:
- Mono-repo for all environments: Single repo containing
platform/andapps/with environment overlays. Easier to coordinate global changes but can grow large. - Per-environment repos: Separate repos for
staging,production, and per-cluster configs. Better isolation and access control, but more repositories to manage. - Per-app repos with environment overlays: App teams own their manifests and a platform repo assembles environment-specific overlays.
Document the chosen pattern and keep it simple for the initial rollout.
3. Bootstrap clusters and controllers
- Provision Kubernetes clusters with a reproducible method (Terraform, eksctl, k3s scripts, etc.).
- Install the GitOps controller into a
gitopsnamespace or a dedicated platform namespace. - Configure RBAC so the controller has permission only to the namespaces it needs.
- Add cluster bootstrap manifests to the platform repository so cluster creation and controller installation are reproducible.
Bootstrap automation ensures new clusters are brought under GitOps control consistently.
4. Integrate CI for artifact creation and validation
GitOps focuses on deployment, not artifact building. Integrate CI to build, test, and publish artifacts (container images, Helm charts) to registries. Recommended flow:
- CI pipeline builds the artifact and runs tests and image scanning.
- On successful builds, CI creates a commit or PR that updates the GitOps repository with the new image tag or Helm values.
- The GitOps controller detects the change and reconciles the cluster.
This keeps the deployment trigger tied to Git while preserving robust CI checks.
5. Secret management
Never store plaintext secrets in Git. Common approaches:
- SOPS (with KMS): Encrypts secrets stored in Git; controllers decrypt at apply time using sealed KMS credentials.
- Sealed Secrets: Encrypt secrets with a cluster-specific controller so ciphertext can live in Git.
- External secret stores: Use ExternalSecrets or Vault to inject secrets at runtime.
Choose an approach that fits your compliance and operational constraints and document key rotation and access procedures.
6. Policy and validation gates
Add automated checks before merges and during reconciliation:
- Pre-merge CI: lint manifests (kubeval, kube-score), run unit tests, and image scans.
- Admission-time policies: OPA/Gatekeeper or Kyverno enforce rules in-cluster.
- Git pre-commit hooks or CI jobs to block invalid changes.
Policies prevent misconfigurations from reaching clusters and provide guardrails for teams.
7. Environment promotion and promotion patterns
Common promotion models:
- Branch-per-environment: Developers merge to
stagingbranch then toproductionbranch when ready. - Folder-per-environment: Separate directories under a repo; PRs update the target environment folder.
- Image automation: Use Flux image automation or CI to update image tags in the environment repo automatically after CI publishes an image.
Pick a promotion model that maps cleanly to your release process and auditing needs.
8. Observability and alerts
Monitor both reconciliation status and application health:
- GitOps controller metrics (sync status, reconciliation counts, failures).
- Application metrics, pod health, and probe statuses.
- Alerts for stuck reconciliations, repeated rollbacks, or policy violations.
Integrate controller notifications into your incident channels so teams can act quickly when reconciliation fails.
9. Handling complex changes
For procedural operations (large schema migrations, multi-step rollouts), GitOps alone may be insufficient. Strategies:
- Model operations as a sequence of declarative steps and use an operator or job controller to manage the sequence.
- Use feature flags and progressive delivery (canaries, traffic shaping) managed by a combination of GitOps manifests and runtime controllers.
Document migration and rollback plans separately from straightforward declarative updates.
10. Backup, DR, and recovery
Keep cluster restoration reproducible:
- Store cluster-level manifests, CRDs, and operator configs in Git.
- Backup cluster state (etcd snapshots) and store them securely.
- Practice restore drills to rebuild clusters from repository snapshots and backups.
Example workflow
- Developer creates a change in an app repo and opens a PR.
- CI builds the image, runs tests, and publishes to a registry.
- CI opens a PR in the
environmentsrepo updating the image tag. - After review and merge, Argo CD/Flux detects the new commit and reconciles the target cluster.
- Monitoring verifies rollout health and signals either success or an alert if degraded.
NebuaCloud and GitOps
NebuaCloud can centralize GitOps operations across many clusters, provide role-based access controls, and surface reconciliation and drift across distributed k3s or upstream clusters. Use NebuaCloud to aggregate visibility and automate multi-cluster promotion workflows.
Conclusion and next steps
Start small: implement app-level GitOps for a single cluster, add CI gates and secret management, and expand to cluster and platform components. Automate bootstrapping and document your repository conventions so teams can onboard quickly.
Once comfortable, extend GitOps to multi-cluster management, progressive delivery patterns, and deeper policy enforcement.
Try it with NebuaCloud -> deploy in minutes
Current Availability
NebuaCloud already uses a real GitOps-oriented model in the current codebase, especially around GitOps-backed application management, target namespace reconciliation, Git-linked deployment context, and revision visibility. Those parts make the GitOps direction in this article technically grounded.
At the same time, the article discusses a broader controller-neutral implementation path that includes multiple promotion patterns, secret strategies, and governance models. NebuaCloud does not yet expose every one of those GitOps capabilities as a complete end-to-end product workflow today. Where those functions are not yet available directly in the product, they should be understood as future platform direction rather than current finished functionality.