Engineering Notes
Home/DevOps & Cloud/Kubernetes/Production Practices and GitOps
DevOps & Cloud · Kubernetes

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.

☁️ DevOps & Cloud● Advanced⏱ 4 min read▶ 2 interactive🛠️ 2 exercises🎤 5 interview Q&As

🎯 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)
credentialsCI holds cluster-admin-ish credentialscluster pulls; CI never touches the cluster
driftundetected until next deploydetected and (optionally) self-healed
audit / rollbackCI logs; re-run old pipelinegit log / git revert
multi-clusterone pipeline step per clustereach cluster syncs itself (ApplicationSets)
yaml
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

AreaPractice
Healthreadiness, liveness (no deps), startup probes; graceful SIGTERM + preStop
Resourcesrequests for all containers, memory limits; LimitRange/ResourceQuota per namespace
Availability≥ 2–3 replicas, topology spread across zones, PodDisruptionBudget, anti-affinity
ScalingHPA/KEDA + node autoscaling (06-autoscaling/)
SecurityPod 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
ConfigConfigMaps/External Secrets, no secrets in Git (03-configmaps_and_secrets/)
Imagespinned tags/digests, minimal base images, private registry
Observabilitystructured logs to stdout, Prometheus metrics, traces, dashboards and SLO alerts (devops-cloud/observability/)
PriorityPriorityClasses 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):

yaml
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.

Developers merge to the app repo, CI builds and pushes an image and opens a PR bumping the tag in the deploy repo; Argo CD in the cluster renders manifests from Git, diffs them against live objects, syncs in waves, prunes and self-heals drift, while admission policies enforce production standards
Developers merge to the app repo, CI builds and pushes an image and opens a PR bumping the tag in the deploy repo; Argo CD in the cluster renders manifests from Git, diffs them against live objects, syncs in waves, prunes and self-heals drift, while admission policies enforce production standards

⚠️ Common Pitfalls

  1. CI with cluster-admin credentials — a CI compromise owns the cluster.
  2. Manual hotfixes with kubectl under GitOps — reverted by self-heal (or worse, silently kept without it).
  3. Secrets committed to the deploy repo.
  4. Auto-sync to prod without promotion gates.
  5. Policies only documented, not enforced.
  6. Skipping Kubernetes upgrades until forced by end of support.

📋 Quick Reference

text
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

Questions interviewers ask about this topic. Answer out loud first, then open a card to compare.

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.

Follow-ups interviewers ask
  • 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.

Follow-ups interviewers ask
  • 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.

Follow-ups interviewers ask
  • 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.

Follow-ups interviewers ask
  • 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.

Follow-ups interviewers ask
  • 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.

1. In GitOps, who applies changes to the cluster?
Pull-based delivery.
2. A manual kubectl edit in prod with selfHeal on will…
Git wins.
3. How do you roll back a bad release in GitOps?
Auditable and reviewed.
4. Which tool enforces 'every Deployment must have requests and probes' at admission?
Policy as code in the cluster.