Expert · GitOps, platform engineering and DevOps careers · topic 50 of 53 · 30 min
GitOps and platform engineering
Explanation
What is GitOps?
GitOps is a way of running systems where Git is the single source of truth. The desired state (what should be running: Kubernetes manifests, Helm values, image tags) lives in a Git repository. A software agent compares that desired state with what is actually running and fixes any difference. Nobody changes production by hand; they change Git, and the agent does the rest.
The OpenGitOps project describes four principles:
- Declarative: you describe what you want ("3 replicas of image canteen-api:3f9c2ab"), not the steps to get there.
- Versioned and immutable: the desired state is stored in Git, so every change has an author, a review and a history.
- Pulled automatically: an agent fetches the desired state; nobody needs to push it into the cluster.
- Continuously reconciled: the agent keeps comparing and correcting, not just once at deploy time.
Push versus pull
| Push-based deploy | Pull-based GitOps | |
|---|---|---|
| Who applies changes | The CI job runs kubectl apply or helm upgrade | An agent inside the cluster (Argo CD or Flux) |
| Cluster credentials | Stored in CI, outside the cluster | Stay inside the cluster; CI only needs Git access |
| Manual changes in the cluster | Stay until the next deploy, unnoticed | Shown as drift, and can be reverted automatically |
| Audit trail | CI logs | Git history and pull request reviews |
Argo CD and Flux are the two best-known GitOps tools, and both are graduated CNCF (Cloud Native Computing Foundation) projects. Argo CD has a web dashboard that many teams like; Flux is a set of controllers that you mainly drive through Git and the command line.
Reconciliation, sync status and drift
Reconciliation is the loop that compares desired state (Git) with live state (the cluster). In Argo CD an application is Synced when they match and OutOfSync when they differ. Drift is a difference caused by something other than Git, for example someone running kubectl scale at midnight to "fix" a slow service. With self-heal turned on, Argo CD changes the cluster back to what Git says.
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: canteen-api-prod
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/acme/canteen-deploy.git
targetRevision: main
path: apps/canteen-api/overlays/prod
destination:
server: https://kubernetes.default.svc
namespace: canteen
syncPolicy:
automated:
prune: true # delete resources that were removed from Git
selfHeal: true # undo manual changes (drift)Rollbacks with git revert
If a release goes wrong, you roll back by reverting the commit that changed the image tag. The agent sees the new commit and syncs the cluster back to the previous version. Git still tells the whole story: what changed, who rolled it back and when.
git log --oneline -3 apps/canteen-api/overlays/prod
# 8c41d2e prod: canteen-api 3f9c2ab -> 7b0e915
git revert 8c41d2e
git push origin main # Argo CD syncs back to 3f9c2ab within minutesEnvironment promotion through pull requests
A common layout keeps application code in one repository and deployment configuration in another. CI builds the image, tags it with the commit SHA and updates the dev environment automatically. Moving the same image to staging and then production is a pull request that changes one line: the image tag in that environment's folder. The review and approval of that pull request is your change record.
canteen-deploy/
apps/canteen-api/
base/ # Deployment, Service, shared settings
overlays/
dev/ # image tag updated by CI bot
staging/ # promoted by pull request
prod/ # promoted by pull request, needs 2 approvalsPlatform engineering and internal developer platforms
When a company has 5 teams, each can build its own pipeline. With 50 teams, everyone re-solving CI, Kubernetes, secrets and dashboards wastes time and creates 50 different security levels. Platform engineering is the practice of a platform team building an internal developer platform (IDP): a set of self-service tools and paved roads that other teams use to build and run their services.
- Golden path: the supported, recommended way to do a common job, such as "create a new Node.js service". It is the easy road, not a forced one.
- Self-service templates: one form or command creates a repository with a Dockerfile, a CI pipeline, a Helm chart, dashboards and alerts already wired up.
- Backstage: an open-source framework for building developer portals, created at Spotify and now a CNCF project. It offers a software catalogue (who owns which service), templates and documentation in one place.
Measuring developer experience
Treat the platform as a product with internal customers, and measure whether it helps them. Useful measures: the DORA metrics (deployment frequency, lead time for changes, change failure rate and time to recover from a failed deployment), time for a new service to reach production, time for a new joiner to make a first deploy, how many teams use the golden path, and short regular surveys asking developers what slows them down.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
GitOps and platform engineering · 1/7
GitOps means Git is the single source of truth for what should run in your systems.
Prefer a video by a teacher? Find free videos on “gitops argo cd tutorial platform engineering backstage explained” on YouTube ↗
In real life: Forty teams, one golden path, at a Bengaluru e-commerce company
An e-commerce company with about forty product teams had forty slightly different Jenkins pipelines and frequent "works in staging, breaks in prod" incidents. A five-person platform team built a Backstage template: one form creates a service repository with a Dockerfile, a GitHub Actions pipeline with scanning, a Helm chart and an Argo CD Application. Production changes became pull requests in a deploy repository. Within six months, the time to get a new service into production fell from about three weeks to two days, and rollbacks became a git revert that anyone on call could do safely.
Practice (0/3 done)
In GitOps, a teammate runs kubectl scale to change replicas from 3 to 6 directly in production. Self-heal is on. What happens?
Write sync_status(desired, live). Both are dicts mapping an app name to its resources: a dict from a resource name (like "Deployment/api") to a dict of settings. Return a dict with one entry per app in desired: "Synced" if live has exactly the same resource names and every resource has the same settings, ignoring any "status" key; otherwise "OutOfSync". An app missing from live is "OutOfSync". Apps only in live are ignored.
Design the GitOps setup for a canteen API with dev, staging and prod environments. Describe the repositories, the folder layout, how a new image reaches each environment, who approves what, and how you roll back.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Capstone project: from commit to monitored productionGitOps, platform engineering and DevOps careers · same module
- DevOps certifications: which, when and howGitOps, platform engineering and DevOps careers · same module
- DevOps careers and interviews in IndiaGitOps, platform engineering and DevOps careers · same module
- CI/CD: shipping every change safelyFull-Stack Development · Deploying and running the app
- IaC in a team: reviews, pipelines and policyCloud Computing (AWS, Azure, Google Cloud) · Infrastructure as code
- Git and GitHubFrontend Web Development · Async JavaScript, modules and tools
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
What is the key difference between push-based deployment and pull-based GitOps?
Answer: In GitOps an agent inside the cluster pulls the desired state from Git, so CI does not need cluster credentials
The agent pulls and reconciles from inside the cluster; CI only writes to Git.
Which two tools are graduated CNCF GitOps projects?
Answer: Argo CD and Flux
Argo CD and Flux both reconcile Kubernetes clusters from Git.
What is a "golden path" in platform engineering?
Answer: A supported, recommended way to do a common task, such as creating a new service
Golden paths make the right way the easy way; they are offered, not forced.
In a GitOps setup, how do you usually roll back a bad production release?
Answer: git revert the commit that changed the image tag and let the agent sync
Git stays the source of truth, and the rollback is reviewed and recorded like any change.
What is the "pull model" in GitOps?Related
Answer: An agent in the cluster, such as Argo CD or Flux, pulls the desired state from Git and applies it
The cluster pulls from Git, so CI needs no cluster credentials and Git history is the deployment history.
Why use npm ci instead of npm install in a pipeline?Related
Answer: It installs exactly the versions in package-lock.json, giving repeatable builds
npm ci does a clean install from the lock file, so CI uses the same versions every time.
A Deployment wants 3 replicas. You delete one of its pods by hand. What happens?Related
Answer: A new pod is created to get back to 3
The ReplicaSet controller sees 2 of 3 and creates a replacement. That is self-healing.
Why do teams define required tags like owner and cost-centre?Related
Answer: To split the bill by team, find owners of resources and select resources for backups and policies
Tags drive cost reports, ownership and automation. AWS does not require them by default, so teams enforce them with policy.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 3 more topics in “GitOps, platform engineering and DevOps careers” before its exam: Capstone project: from commit to monitored production, DevOps certifications: which, when and how, DevOps careers and interviews in India.
- Module 12 exam: GitOps, platform engineering and DevOps careers · 12 questions · 20 min, without help. 4 topics of this module still to finish first.
- 53 topics left in the course before the final exam.