RecapsKayavak

Kayavak / Recaps / DevOps, CI/CD and IaC

Recaps · Volume 8

DevOps, CI/CD and IaC

The revision sheet of every chapter, on one page: the key ideas, the numbers worth knowing, the pitfalls and the words. Use it before an interview, after a chapter, or to find which chapter to reread. Each title opens its chapter; below each sheet are its exercises, companion and TiffinBox stage, and the misconceptions the companion corrects.

Open the volume

92

Git

Key ideas

  • Model: content-addressed objects (blob, tree, commit, annotated tag); snapshots linked by parents; SHA-1 with SHA-256 transition.
  • Refs: branches, tags, remote-tracking refs, HEAD (attached or detached), the reflog, packed refs.
  • Index (staging area): the proposed next tree; add -p for partial staging.
  • Operations: merge (fast-forward, three-way, merge base, conflicts), rebase (new commits, interactive), cherry-pick, revert, reset (soft/mixed/hard), restore, switch, stash, bisect, blame.
  • Remotes: fetch vs pull, upstream tracking, push rules, force-with-lease, protected branches, pull requests.
  • Hooks: client-side (pre-commit, commit-msg, pre-push) and server-side (pre-receive); frameworks (pre-commit, Husky, Lefthook).
  • Signing: GPG, SSH and Sigstore (gitsign) signatures; verification policies.
  • Workflows: trunk-based development, GitHub flow, GitFlow; short-lived branches and feature flags.
  • Scale: packfiles, gc, partial clone, sparse checkout, Scalar, monorepo tooling, LFS.

Numbers to remember

  • Reflog entries kept 90 days by default (30 for unreachable).
  • Lab: 1,000 identical files = 1 blob; 200 versions of a 0.6 MB file packed to 314 KiB; a deleted 50 MB file kept the repo at 51 MB until filter-repo; bisect found 1 bad commit in 256 with 8 runs; a blobless clone was half the size and 25× faster.

Pitfalls

  • Committing secrets or large binaries (history keeps them).
  • git push --force instead of --force-with-lease on shared branches.
  • Rebasing commits others have already pulled.
  • reset --hard with uncommitted work.
  • Long-lived branches that drift for weeks.
  • Commits that don't build, which breaks bisect.

Glossary

  • Blob / tree / commit: file contents / directory listing / snapshot with metadata.
  • Ref: a name pointing to an object (branch, tag).
  • Merge base: the best common ancestor of two commits.
  • Packfile: compressed, delta-encoded object storage.
  • Detached HEAD: HEAD pointing directly at a commit, not a branch.
  • Partial clone: a clone that omits some objects until needed.

93

CI/CD

Key ideas

  • CI / continuous delivery / continuous deployment and trunk-based development.
  • Pipeline stages: checkout, lint, test (unit, integration, contract), build, scan (SAST, dependencies, images, secrets), package and sign, publish, deploy per environment, verify, release.
  • GitHub Actions: workflows, triggers (push, pull_request, workflow_dispatch, schedules), jobs, steps, runners, matrices, needs, outputs, artifacts, caches, environments with protection rules, reusable workflows, composite actions, permissions, OIDC.
  • GitLab CI: stages, needs (DAG), rules, includes and components, runners and executors, environments.
  • Jenkins: declarative pipelines, agents, shared libraries, plugins (and their risk).
  • TeamCity: build chains, snapshot dependencies, Kotlin DSL.
  • Fast and reliable: caching, parallelism, test selection, incremental builds, remote build caches (Bazel, Gradle), flaky-test management, small pipelines.
  • Securing pipelines: least-privilege tokens, OIDC instead of secrets, pinned actions, isolated runners for untrusted code, provenance and signing (SLSA), branch protection and required reviews.

Numbers to remember

  • Lab: a clean-container pipeline took 64 s; a warm build cache took a run from 38 s to 2.4 s; a 1.25% flaky test makes a 40-test suite pass only ~60% of runs; masking hid a secret but not its length.

Pitfalls

  • Pipelines nobody trusts (flaky, slow).
  • Caches without keys, or shared with untrusted builds.
  • Long-lived cloud keys in CI secrets.
  • pull_request_target checking out fork code with secrets available.
  • Unpinned third-party actions and plugins.
  • Rebuilding artifacts per environment instead of promoting one.

Glossary

  • Runner / agent: machine executing CI jobs.
  • Matrix: generating jobs from combinations of parameters.
  • Artifact: a file produced by a job and stored or passed on.
  • Cache: reusable files (dependencies, build outputs) across runs.
  • Environment protection: approvals and rules before jobs using an environment run.
  • SLSA: supply-chain framework for build provenance levels.

94

Infrastructure as Code

Key ideas

  • Why IaC: reviewable, versioned, reproducible infrastructure; drift detection; environments from the same code.
  • Terraform/OpenTofu: providers, resources, data sources, variables, locals, outputs, modules, expressions and functions, for_each/count, depends_on, lifecycle (prevent_destroy, create_before_destroy, ignore_changes), workspaces.
  • Workflow: init, plan (refresh, diff), apply, destroy; plan files; plans in pull requests; automation with locks.
  • State: mapping code to real objects; remote backends with locking; sensitivity and encryption; state mv/rm, import and moved blocks; splitting state by blast radius.
  • Beyond Terraform: CDK/CDKTF, Pulumi, CloudFormation, Bicep, Crossplane, Ansible for configuration; policy-as-code (OPA/conftest, Sentinel, Checkov).
  • Practices: small state files per component and environment, pinned provider versions with lock files, modules with clear interfaces, scheduled drift detection, no console changes in production.

Numbers to remember

  • Lab: a console change was detected and reverted by the next plan; a password appeared in plain-text state until encryption; count destroyed 2 and created 1 where for_each destroyed 1; a rename without moved planned destroy+create, with moved 0 changes.

Pitfalls

  • Committing state files or .tfvars with secrets.
  • One giant state for everything.
  • count over lists that change order.
  • Renames without moved blocks.
  • Unpinned providers; skipping plan review.
  • Manual console fixes in production.

Glossary

  • Provider: plugin translating resources into API calls.
  • Plan: computed set of actions to reach the desired state.
  • State: record mapping code addresses to real resources.
  • Drift: differences between real infrastructure and code.
  • Module: reusable group of resources with inputs and outputs.
  • Backend: where state is stored and locked.

95

GitOps

Key ideas

  • Principles (OpenGitOps): declarative, versioned and immutable, pulled automatically, continuously reconciled.
  • Push vs pull: credentials, drift, audit and rollback differences; CI builds and updates Git, agents deploy.
  • Reconciliation: desired vs live state, diffing, server-side apply and field managers, pruning, health, sync waves and hooks, self-heal.
  • Repository design: app repos vs config repos, environment overlays (Kustomize), Helm values, monorepo vs per-team, promotion by PR, image automation.
  • Argo CD: Applications, ApplicationSets, projects, sync policies, UI, RBAC; Flux: GitRepository, Kustomization, HelmRelease, image automation, notification controller.
  • Secrets: SOPS (age, KMS), Sealed Secrets, External Secrets Operator, CSI secrets store.
  • Beyond apps: cluster add-ons, infrastructure via Crossplane or Terraform controllers, policies.
  • Limits: databases and stateful migrations, emergency changes, secrets bootstrapping, ordering across systems.

Numbers to remember

  • Lab: a commit reached all pods in ~4.7 s; a revert in ~4.6 s; drift lasted up to the sync interval (≤2 s at 3 s, ≤29.5 s at 30 s); a broken commit changed nothing; SOPS kept plaintext out of Git history.

Pitfalls

  • Plain-text secrets in the repository.
  • Pruning without ownership scoping.
  • Mixing manual kubectl changes with GitOps (they're reverted).
  • No CI validation of manifests before merge.
  • One giant repo with everyone's permissions.
  • Two controllers managing the same fields.

Glossary

  • Reconciliation loop: continuously making actual state match desired state.
  • Drift: live state differing from the declared state.
  • Pruning: deleting live objects no longer declared.
  • Field manager: the owner recorded by server-side apply for each field.
  • Overlay: environment-specific changes on a shared base (Kustomize).
  • Image automation: updating image tags in Git when new images are published.

96

Release Engineering

Key ideas

  • Scope: versioning, changelogs, release processes, artifacts and promotion, rollback/roll-forward, migration safety, deprecation and support.
  • Versioning: semver (MAJOR.MINOR.PATCH, pre-releases, build metadata, 0.x), calver, build numbers and commit hashes; API versioning.
  • Automation: Conventional Commits; semantic-release, release-please, Changesets, git-cliff; tags and signed releases; release notes.
  • Processes: trunk-based with continuous deployment, release trains, release branches with backports, hotfixes, freeze windows, mobile app store releases.
  • Toolkit: artifact registries, immutable artifacts by digest, provenance and signing, feature flags, canaries, release dashboards.
  • Rollback vs roll-forward: when each is safe; state changes block rollbacks.
  • Migration safety: expand–contract, lock timeouts, concurrent index builds, NOT VALID constraints, batched backfills, migrations separate from deploys.
  • Deprecation: announce, measure usage, warn (Deprecation/Sunset headers), migrate users, remove in a major version.

Numbers to remember

  • Lab: a 5 s report blocked a waiting ALTER and every query behind it for 5 s; lock_timeout = 1s capped it at 1 s; a constant default took 0.002 s, a volatile one 2.4 s (rewrite); plain index build blocked inserts 0.36 s, CONCURRENTLY 0.01 s.

Pitfalls

  • Hand-written version numbers and changelogs.
  • Breaking changes shipped as minor versions.
  • Migrations without lock_timeout.
  • Volatile defaults or plain CREATE INDEX on large hot tables.
  • Renames and type changes in one step.
  • Rolling back code after a non-reversible migration.

Glossary

  • Semver: version scheme signalling compatibility.
  • Conventional Commits: structured commit messages for automation.
  • Release train: releases on a fixed schedule with whatever is ready.
  • Hotfix: an urgent fix released outside the normal cadence.
  • Expand–contract: multi-release compatible schema or API change.
  • Lock queue: waiting lock requests that block later conflicting requests.