GitOps desired state and drift
Desired state is a versioned contract
Imagine the bookstore team wants three catalog replicas. Instead of asking an administrator to scale the live Deployment, the team changes the configuration in a reviewed commit. GitOps uses a declared target, a recorded history, automatic retrieval of that target, and a recurring comparison with the running system. A branch is a moving reference; a commit identifies a specific version. Record the resolved commit in delivery evidence. CI still builds and tests the image, while the delivery controller reconciles the approved configuration.
Reviewed revision A: replicas = 2Reviewed revision B: replicas = 3Live Deployment: replicas = 2Difference: desired 3, live 2Follow the Argo CD control loop
The repository server obtains source material and generates manifests. The application controller compares those manifests with live Kubernetes objects and can request changes. The Argo CD API server serves clients such as its web interface and CLI; it is not the Kubernetes API server. A repository fetch or manifest generation failure is different from a failed apply. Inspect the resolved revision, target generation and operation result before attributing a problem to Kubernetes.
Git revision -> repository server -> desired objectsKubernetes API -> live objects -> application controllerApplication controller -> comparison and authorized syncSync and health answer different questions
Sync compares the managed desired and live configuration; health evaluates resource behavior using health assessments. A Deployment can match its desired spec while its containers fail to become ready. Conversely, an application can be serving normally while a live edit differs from Git. Status can lag, and some differences are ignored by configuration. Verify a meaningful application request in addition to controller status.
Desired replicas: 3; live spec: 3; ready: 0Illustration: Synced, not healthyDesired replicas: 3; live spec: 2; ready: 2Illustration: OutOfSync, potentially healthyChoose the source of truth deliberately
A direct edit to a managed field may be overwritten by reconciliation. For an emergency, coordinate a bounded break-glass action, record the reason, then bring the reviewed source and live state back into agreement. A HorizontalPodAutoscaler may own replica decisions; avoid two controllers fighting over the same field. Diff exclusions are not automatically permission restrictions or proof that a field will never be applied. Use immutable image references and reviewed dependencies for reproducible promotion.
Normal change: review -> commit -> compare -> sync -> verifyEmergency: authorize -> mitigate -> record -> reconcile source -> verifyPractice and next step
In lab-fixtures/gitops-argocd, run validate_offline.py. Inspect the two local Git revisions and predict sync and health separately for each drift case. Explain why an HTTP smoke test is still required. Next: Application and AppProject.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
GitOps desired state and drift — knowledge check
Compare an approved Git revision with live resources, and distinguish synchronization from application health.
What identifies the exact reviewed configuration?
What is CI responsible for in this workflow?
The desired and live spec match but no Pod is ready. What follows?
Which component generates manifests from repository content?
An HPA manages replicas. What is the sound design?