Production Practices and GitOps
Git as the single source of truth, a controller in the cluster that syncs it, and admission policies that enforce production standards. Follow a release through GitOps, watch self-heal revert a manual hotfix, and run through a production-readiness checklist.
🎯 What you'll learn
- GitOps: pull-based delivery with Argo CD / Flux
- Promotion via pull requests and rollbacks via git revert
- A production-readiness checklist for workloads
- Policy as code in the cluster and cluster operations
📚 Before you start
1GitOps
GitOps makes Git the single source of truth for cluster state: a controller inside the cluster continuously pulls desired state from Git and reconciles the cluster to match it.
CI push (kubectl apply/helm upgrade from CI) | GitOps pull (Argo CD / Flux) | |
|---|---|---|
| credentials | CI holds cluster-admin-ish credentials | cluster pulls; CI never touches the cluster |
| drift | undetected until next deploy | detected and (optionally) self-healed |
| audit / rollback | CI logs; re-run old pipeline | git log / git revert |
| multi-cluster | one pipeline step per cluster | each cluster syncs itself (ApplicationSets) |
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata: { name: api-prod, namespace: argocd }
spec:
project: petpal
source:
repoURL: https://github.com/petpal/deploy.git
targetRevision: main
path: apps/api/overlays/prod # Kustomize overlay or Helm chart + values
destination: { server: "https://kubernetes.default.svc", namespace: petpal }
syncPolicy:
automated: { prune: true, selfHeal: true }
syncOptions: [CreateNamespace=true]Typical flow: app CI builds and pushes api:sha-abc123 → a bot (or Argo CD Image Updater / Flux image automation) opens a PR in the deploy repo bumping the tag in the staging overlay → merge → Argo CD syncs staging → promotion PR for prod (devops-cloud/cicd/). Progressive delivery with Argo Rollouts/Flagger adds automated canaries with metric analysis.
2Production Readiness Checklist for Workloads
| Area | Practice |
|---|---|
| Health | readiness, liveness (no deps), startup probes; graceful SIGTERM + preStop |
| Resources | requests for all containers, memory limits; LimitRange/ResourceQuota per namespace |
| Availability | ≥ 2–3 replicas, topology spread across zones, PodDisruptionBudget, anti-affinity |
| Scaling | HPA/KEDA + node autoscaling (06-autoscaling/) |
| Security | Pod Security Admission restricted, non-root, read-only rootfs, drop capabilities, no privileged; NetworkPolicies default-deny; least-privilege RBAC; workload identity; image scanning and signing (cosign) with admission verification |
| Config | ConfigMaps/External Secrets, no secrets in Git (03-configmaps_and_secrets/) |
| Images | pinned tags/digests, minimal base images, private registry |
| Observability | structured logs to stdout, Prometheus metrics, traces, dashboards and SLO alerts (devops-cloud/observability/) |
| Priority | PriorityClasses so critical workloads preempt batch jobs |
3Policy as Code in the Cluster
Admission policy engines enforce the checklist automatically: Kyverno (policies as YAML), OPA Gatekeeper (Rego), or built-in ValidatingAdmissionPolicy (CEL):
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata: { name: require-requests-and-probes }
spec:
validationFailureAction: Enforce
rules:
- name: check-containers
match: { any: [{ resources: { kinds: [Deployment, StatefulSet] } }] }
validate:
message: "containers need resource requests and a readiness probe"
pattern:
spec:
template:
spec:
containers:
- resources: { requests: { cpu: "?*", memory: "?*" } }
readinessProbe: {}Run the same policies in CI (kyverno apply, conftest, kubeconform schema validation) so violations fail before merge.
4Cluster Operations
- Upgrades: Kubernetes ships ~3 minor versions a year; managed services support each for ~14 months. Upgrade control plane, then add-ons, then nodes (surge/blue-green node groups); check deprecated APIs first (
kubent,pluto). - Multi-tenancy: namespaces per team with quotas, RBAC, network policies; separate clusters for hard isolation (prod vs non-prod, compliance).
- Backups and DR: Git holds manifests; Velero for volumes/cluster resources; rehearse rebuilding a cluster from Git.
- Cost: right-size requests, Karpenter consolidation, Spot, per-namespace cost visibility (OpenCost/Kubecost).
Under the HoodHow Argo CD Reconciles▾
Argo CD's repo server clones the Git repository at the target revision and renders manifests (plain YAML, Kustomize build or Helm template — Argo uses Helm only as a renderer, no release Secrets). The application controller watches live cluster objects (via informers) and, every few minutes or on a Git webhook, compares the rendered desired objects with the live ones using a normalized diff (ignoring defaulted fields and configured ignoreDifferences such as replicas managed by an HPA). The app status is Synced/OutOfSync and Healthy/Progressing/Degraded (health from resource-specific checks — e.g. a Deployment is Healthy when its rollout completed). A sync applies resources in waves (argocd.argoproj.io/sync-wave annotations, with PreSync hooks such as migrations), prunes objects removed from Git when prune is on, and selfHeal re-applies desired state when someone changes the cluster manually — making Git the effective control point.
⚠️ Common Pitfalls
- CI with cluster-admin credentials — a CI compromise owns the cluster.
- Manual hotfixes with kubectl under GitOps — reverted by self-heal (or worse, silently kept without it).
- Secrets committed to the deploy repo.
- Auto-sync to prod without promotion gates.
- Policies only documented, not enforced.
- Skipping Kubernetes upgrades until forced by end of support.
📋 Quick Reference
GitOps: Git = truth · Argo CD Application/ApplicationSet · Flux Kustomization/HelmRelease · prune + selfHeal · promotion by PR
readiness: probes · requests/limits · replicas + spread + PDB · HPA · PSA restricted · NetworkPolicy · RBAC · signed images · SLO alerts
policy: Kyverno / Gatekeeper / ValidatingAdmissionPolicy (+ same checks in CI: kubeconform, conftest)
ops: upgrades (deprecated APIs) · quotas per namespace · Velero · OpenCost🧠 Key takeaways
- GitOps: Git is the source of truth; an in-cluster controller pulls and reconciles, with prune and selfHeal.
- Promote with PRs, roll back with git revert; CI never holds cluster credentials.
- Production readiness: probes, requests/limits, replicas + spread + PDB, HPA, PSA restricted, NetworkPolicies, RBAC, signed images, SLO alerts.
- Enforce standards with Kyverno/Gatekeeper/ValidatingAdmissionPolicy, run the same checks in CI, and keep up with upgrades.
🎤 Interview Q&A
Q1What does a production-ready Kubernetes workload need?core▾
Resource requests/limits, readiness/liveness probes, multiple replicas spread across zones, PodDisruptionBudgets, graceful shutdown, non-root security context, NetworkPolicies, observability (metrics, logs, traces), and proper RBAC.
- Most commonly missing? Requests/limits and PDBs.
Q2What is GitOps?core▾
Git is the source of truth for desired cluster state; an in-cluster agent (Argo CD, Flux) continuously pulls and reconciles manifests from Git, detecting and correcting drift. Changes happen via pull requests.
- Push vs pull deployments? Pull-based GitOps keeps cluster credentials inside the cluster instead of CI.
Q3How do you promote changes across environments with GitOps?senior▾
Separate directories or repos per environment (overlays), promotion via PRs that bump image tags/versions, automated image updaters for lower environments, and approvals for production.
- How do you roll back? Revert the Git commit; the agent reconciles.
Q4How do you manage multi-tenancy in a cluster?core▾
Namespaces per team/app, RBAC, ResourceQuotas and LimitRanges, NetworkPolicies, Pod Security Admission, and policy engines; for strong isolation, separate clusters.
- Namespace isolation enough for hostile tenants? No; use separate clusters or sandboxed runtimes.
Q5How do you handle cluster upgrades and disaster recovery?core▾
Regular minor-version upgrades with deprecated API checks, node rolling replacements respecting PDBs, Velero backups of resources and volumes, GitOps to recreate state, and tested restore procedures.
- Blue/green clusters? Stand up a new cluster and shift traffic for risky upgrades.
🛠️ Practice exercises
Each exercise is a file in this topic folder. Code exercises are self-checking: run them and make the checks pass.
✅ Check yourself
Answer the questions — feedback is instant.