The idea
A CI/CD pipeline is a list of stages a machine runs for every change: test, build, store, deploy. It lives in the repository as a file, here .github/workflows/ship.yml for GitHub Actions. Any red stage stops the line.
CI: push to image
A developer commits a change and runs git push. The commit's ID, its SHA, starts 3f9c2ab. Line 1, on: push, tells GitHub to start the pipeline for every push. Production still runs 8d41e07.
A runner is a machine that runs pipeline jobs. Line 2 asks for ubuntu-latest: GitHub starts a brand-new virtual machine for this job and checks out the commit. Nothing is left over from earlier runs.
Line 3 runs the unit tests. python3 -m unittest finds every test file and exits with status 0 only if all pass. Any other exit code turns the step red, and every later stage is skipped.
Line 4 builds a container image: the app plus everything it needs to run. $IMG names it after the commit, shop:3f9c2ab, so anyone can tell exactly which code is inside.
Line 5 pushes the image to a registry, a store for images. The runner is then thrown away; the image lives on. The registry now holds 8d41e07 and 3f9c2ab, so older versions stay available.
CD: gate and roll-out
The deploy job needs build, so it waits until build is green. Line 6 names the production environment; with a required reviewer the job pauses until a person approves. That is continuous delivery: always ready, released on a decision.
Line 7 asks Kubernetes to run the new image. It does a rolling update: start one new pod, wait until it is ready, remove one old pod, repeat. With 3 pods, all 3 keep serving users throughout.
When things go wrong
Next, commit e5a1c90 breaks a test. Line 3 exits with status 1, the build job fails, and deploy, which needs build, is skipped. No image is built; users keep running 3f9c2ab. The developer gets the red result quickly.
Tests cannot catch everything. If users hit a bug in 3f9c2ab, one command returns the Deployment to its previous version. The 8d41e07 image is still in the registry, so Kubernetes rolls back pod by pod.
What happens
;; step 1/10 · pipeline
.github/workflows/ship.yml
push → test → build → store → approve → deploy
CI = continuous integration: test every push
CD = continuous delivery: every green build
is ready to deploy
a red stage stops everything after it
The card shows seven key lines of the full 30-line workflow (indentation trimmed). The full file also checks out the code, logs in to the GitHub Container Registry and writes the cluster credentials from a secret. Step text counts the card's line numbers, not the file's. deploy/shop is kubectl's short name for deployment/shop. The repository also holds shop.py, test_shop.py and a Dockerfile. Images on ghcr.io start private, so the cluster needs an imagePullSecret (or a public package) to pull them. RollingUpdate is the default Deployment strategy. maxSurge and maxUnavailable default to 25%; Kubernetes rounds the surge up and the unavailable count down, so 3 replicas get 1 extra pod and 0 pods down.