Skip to content

Task: Deploy & roll back

Ship and undo: rollouts, helm upgrade/rollback, terraform apply, Cloud Run, tags.

IndexUpdated

Also:deploy · rollback · release · rollout · ship · undo deploy · revert

Rule of thumb: know the rollback command before running the deploy command. Each deploy card here has a matching rollback card.

31 items

Git3

Git: Revert a pushed commit safely

Safe

Creates a new commit that undoes the given one. Safe on shared branches.

git revert <commit-sha>
What each part does
  1. git revertmake a new commit that undoes the changes of an old one (history is not rewritten)
  2. <commit-sha>the commit to undo

Also known as: undo pushed commit · git revert

Tool page →

Git: Force push safely

Caution

Overwrite the remote branch only if nobody pushed since your last fetch.

git push --force-with-lease origin <branch>
What each part does
  1. git pushupload commits
  2. --force-with-leaseoverwrite the remote branch only if it is still where you last fetched it; fails if someone else pushed
  3. origin <branch>the remote and branch

Also known as: force push · push -f

Tool page →

Git: Create and push a release tag

Safe

Annotated tag for a release; pushing it usually triggers the release pipeline.

git tag -a <version> -m "<message>" && git push origin <version>
What each part does
  1. git tag -a <version>create an annotated tag (author, date, message), e.g. v1.4.0
  2. -m "<message>"the tag message
  3. &&push only if tagging worked
  4. git push origin <version>push that one tag (git push does not push tags by default)
Example
$ git tag -a v1.4.2 -m "Release 1.4.2" && git push origin v1.4.2

Also known as: tag release · semver tag

Tool page →

Docker2

Docker: Build and tag an image

Safe

Build from the Dockerfile in the current directory and tag for a registry.

docker build -t <registry>/<image>:<tag> .
What each part does
  1. docker buildbuild an image from a Dockerfile
  2. -t <registry>/<image>:<tag>name and tag the result, ready to docker push
  3. .build context: the current directory (sent to the daemon; .dockerignore applies)

Also known as: docker build

Tool page →

Docker: Redeploy a compose service with a new image

Safe

Pull the latest tag and recreate only that service.

docker compose pull <service> && docker compose up -d <service>
What each part does
  1. docker compose pull <service>download the newest image for the service's tag
  2. &&only continue if the pull worked
  3. docker compose up -d <service>recreate the service if its image or config changed, detached

Also known as: compose update · restart service

Tool page →

Podman2

Podman: Create a pod with a published port

Safe

A pod shares one network namespace between containers, like a Kubernetes pod. Add containers with --pod <pod>.

podman pod create --name <pod> -p <host-port>:<container-port>
What each part does
  1. podman pod createcreate a pod: containers in it share network and localhost
  2. --name <pod>the pod's name
  3. -p <host-port>:<container-port>publish a port; must be set on the pod, not on its containers

Also known as: podman pod

Tool page →

Podman: Generate a systemd unit for a container

Safe

Writes container-<name>.service so systemd can manage the container.

podman generate systemd --new --files --name <container>
What each part does
  1. podman generate systemdwrite a systemd unit for a container (newer Podman prefers Quadlet files)
  2. --newthe unit creates a fresh container on start and removes it on stop
  3. --fileswrite .service files to the current directory instead of stdout
  4. --name <container>use the container name (not ID) in the unit

My note Deprecated in favour of Quadlet (.container files in ~/.config/containers/systemd/) on Podman 4.4+.

Also known as: podman systemd · quadlet

Tool page →

Kubernetes4

Kubernetes: Update a deployment image

Caution

Triggers a rolling update to a new image tag.

kubectl set image deployment/<deployment> <container>=<image>:<tag> -n <namespace>
What each part does
  1. kubectl set imagechange the image of containers (starts a rollout)
  2. deployment/<deployment>the deployment
  3. <container>=<image>:<tag>container name in the pod spec = new image
  4. -n <namespace>its namespace

Also known as: kubectl set image · deploy new version

Tool page →

Kubernetes: Watch rollout status

Safe

Blocks until the rollout completes or fails; non-zero exit on timeout (good in CI).

kubectl rollout status deployment/<deployment> -n <namespace> --timeout=5m
What each part does
  1. kubectl rollout statuswait and report until the rollout finishes or fails
  2. deployment/<deployment>the deployment
  3. -n <namespace>its namespace
  4. --timeout=5mgive up (non-zero exit) after 5 minutes; useful in CI

Also known as: rollout status · deployment progress

Tool page →

Kubernetes: Roll back a deployment

Caution

Return to the previous ReplicaSet. Use --to-revision=<n> for a specific one (see rollout history).

kubectl rollout undo deployment/<deployment> -n <namespace>
What each part does
  1. kubectl rollout undogo back to the previous ReplicaSet (add --to-revision=N for a specific one)
  2. deployment/<deployment>the deployment
  3. -n <namespace>its namespace

My note kubectl rollout history deployment/<deployment> shows revisions first.

Also known as: rollback · undo deploy · kubectl rollout undo

Tool page →

Kubernetes: Restart a deployment

Caution

Recreates pods with a rolling restart (picks up new ConfigMap/Secret values).

kubectl rollout restart deployment/<deployment> -n <namespace>
What each part does
  1. kubectl rollout restartrolling restart: new pods replace old ones, no downtime if replicas > 1
  2. deployment/<deployment>the deployment
  3. -n <namespace>its namespace

Also known as: restart pods · rollout restart

Tool page →

OpenShift2

OpenShift: Follow build logs

Safe

Stream the logs of the latest build of a BuildConfig.

oc logs -f bc/<build-config>
What each part does
  1. oc logs -ffollow logs
  2. bc/<build-config>the latest build of this BuildConfig

Also known as: build logs · s2i

Tool page →

OpenShift: Start a build and follow it

Safe

Trigger a new build and stream its log until it finishes.

oc start-build <build-config> --follow
What each part does
  1. oc start-build <build-config>start a new build from a BuildConfig
  2. --followstream its logs until it finishes

Also known as: oc start-build

Tool page →

GCP2

GCP: Deploy a Cloud Run revision

Safe

Deploy a new image as a new revision and shift 100% traffic to it.

gcloud run deploy <service> --image <image> --region <region>
What each part does
  1. gcloud run deploy <service>create a new revision of the service (creates the service if missing)
  2. --image <image>container image, e.g. europe-docker.pkg.dev/proj/repo/app:1.4
  3. --region <region>region of the service

Also known as: cloud run deploy

Tool page →

GCP: Roll back Cloud Run traffic to a revision

Caution

Send all traffic back to a known good revision.

gcloud run services update-traffic <service> --to-revisions <revision>=100 --region <region>
What each part does
  1. gcloud run services update-traffic <service>change which revisions get traffic (no new deploy)
  2. --to-revisions <revision>=100send 100% of traffic to that revision
  3. --region <region>region of the service

Also known as: cloud run rollback

Tool page →

Terraform3

Terraform: Initialize and upgrade providers

Safe

Download modules/providers and upgrade within the version constraints.

terraform init -upgrade
What each part does
  1. terraform initset up the backend, download providers and modules
  2. -upgradepick the newest versions the constraints allow and update .terraform.lock.hcl

Also known as: tf init

Tool page →

Terraform: Plan and save to a file

Safe

Preview changes and save the exact plan that will be applied.

terraform plan -out=tfplan
What each part does
  1. terraform planshow what would change
  2. -out=tfplansave the plan so terraform apply tfplan does exactly that

Also known as: tf plan

Tool page →

Terraform: Apply a saved plan

Caution

Applies exactly what was reviewed in the saved plan. No re-plan surprises.

terraform apply tfplan
What each part does
  1. terraform applymake the changes
  2. tfplanthe saved plan file: applies exactly what was reviewed, with no new prompt

Also known as: tf apply

Tool page →

Ansible2

Ansible: Dry-run a playbook with diff

Safe

Shows what would change, file diffs included, without changing anything.

ansible-playbook -i <inventory> <playbook> --check --diff
What each part does
  1. ansible-playbookrun a playbook (a YAML list of plays and tasks)
  2. -i <inventory>inventory file or directory listing the hosts
  3. <playbook>the playbook file, e.g. site.yml
  4. --checkdry run: report what would change, change nothing
  5. --diffshow a before/after diff for templated and edited files

Also known as: check mode · dry run

Tool page →

Ansible: Run a playbook on a subset of hosts

Caution

Target one host or group, e.g. --limit web-01 or --limit 'web:!web-03'.

ansible-playbook -i <inventory> <playbook> --limit <host-pattern>
What each part does
  1. ansible-playbookrun a playbook
  2. -i <inventory>inventory file or directory
  3. <playbook>the playbook file
  4. --limit <host-pattern>only run on hosts matching the pattern, e.g. web01, webservers, 'web*:!web03'

Also known as: limit hosts · canary

Tool page →

Helm3

Helm: Upgrade or install a release

Safe

Idempotent deploy. --atomic rolls back automatically if the upgrade fails.

helm upgrade --install <release> <chart> -n <namespace> -f <values-file> --atomic --wait
What each part does
  1. helm upgrade --install <release>upgrade the release, or install it if it doesn't exist
  2. <chart>chart reference: repo/chart, a path, or an OCI URL
  3. -n <namespace>target namespace (add --create-namespace if it may not exist)
  4. -f <values-file>values file overriding the chart defaults
  5. --atomicroll back automatically if the upgrade fails
  6. --waitwait for pods, services etc. to be ready before reporting success

Also known as: helm upgrade · helm install

Tool page →

Helm: Show release history

Safe

Revisions, status and chart/app versions of a release.

helm history <release> -n <namespace>
What each part does
  1. helm history <release>every revision: number, date, status, chart and app version, description
  2. -n <namespace>namespace of the release

Also known as: helm history · another operation (install/upgrade/rollback) is in progress

Tool page →

Helm: Roll back a release

Caution

Return the release to an earlier revision (see helm history).

helm rollback <release> <revision> -n <namespace> --wait
What each part does
  1. helm rollback <release>redeploy a previous revision of a release (as a new revision)
  2. <revision>revision number from helm history; leave it out for the previous one
  3. -n <namespace>namespace of the release
  4. --waitwait until the resources are ready

Also known as: helm rollback

Tool page →

GitHub Actions1

GitHub Actions: Trigger a workflow manually

Safe

Kick off a workflow_dispatch workflow on a branch.

gh workflow run <workflow-file> --ref <branch>
What each part does
  1. gh workflow run <workflow-file>start a workflow that has a workflow_dispatch trigger, e.g. deploy.yml
  2. --ref <branch>branch or tag to run it on; pass inputs with -f name=value

Also known as: workflow_dispatch · gh workflow run

Tool page →

GitLab CI2

GitLab CI: Watch the pipeline for this branch

Safe

Live status of the current branch's pipeline from the terminal.

glab ci status --live
What each part does
  1. glab ci statusstatus of the latest pipeline on the current branch, job by job
  2. --livekeep refreshing until the pipeline finishes

Also known as: glab ci · pipeline status

Tool page →

GitLab CI: Run a pipeline on a branch

Safe

Trigger a new pipeline, e.g. to re-deploy.

glab ci run --branch <branch>
What each part does
  1. glab ci runcreate a new pipeline
  2. --branch <branch>the branch to run it on; add --variables KEY:value for CI variables

Also known as: trigger pipeline

Tool page →

Jenkins1

Jenkins: Trigger a parameterized build

Safe

Start a job remotely with parameters via the REST API.

curl -X POST -u <user>:<api-token> "<jenkins-url>/job/<job>/buildWithParameters?<param>=<value>"
What each part does
  1. curl -X POSTtrigger endpoints need POST
  2. -u <user>:<api-token>basic auth with an API token (no CSRF crumb needed with a token)
  3. /job/<job>/buildWithParametersqueue a build of a parameterized job
  4. ?<param>=<value>job parameters, joined with &

Also known as: jenkins api · remote build

Tool page →

Prometheus2

Prometheus: Validate config and rule files

Safe

Checks prometheus.yml and every rule file it references. Run it in CI before deploying.

promtool check config <config-file>
What each part does
  1. promtool check configvalidate prometheus.yml and the rule files it references
  2. <config-file>path to the config; use promtool check rules <file> for a rule file alone

Also known as: promtool · rule syntax

Tool page →

Prometheus: Reload config without restarting

Safe

Hot-reload config and rules.

curl -X POST <prometheus-url>/-/reload
What each part does
  1. curl -X POSTthe reload endpoint needs POST
  2. <prometheus-url>/-/reloadre-read config and rule files; only works with --web.enable-lifecycle

My note Needs --web.enable-lifecycle. With the Operator, edit the CRDs instead.

Also known as: reload prometheus

Tool page →

Trivy1

Trivy: Fail CI on critical vulnerabilities

Safe

Non-zero exit when a fixable critical CVE is found: use as a pipeline gate.

trivy image --exit-code 1 --severity CRITICAL --ignore-unfixed <image>:<tag>
What each part does
  1. trivy imagescan a container image
  2. --exit-code 1exit with 1 if anything is found, so the CI job fails
  3. --severity CRITICALonly count critical findings
  4. --ignore-unfixedskip vulnerabilities with no fixed version yet
  5. <image>:<tag>the image to scan

Also known as: security gate · pipeline scan

Tool page →

Istio1

Istio: Enable sidecar injection for a namespace

Safe

New pods get an Envoy sidecar. Restart existing deployments to inject them.

kubectl label namespace <namespace> istio-injection=enabled --overwrite
What each part does
  1. kubectl label namespace <namespace>set a label on the namespace
  2. istio-injection=enabledtells Istio to inject the sidecar into new pods here (restart existing ones)
  3. --overwritereplace the label if it already has a value

Also known as: sidecar injection · istio-injection

Tool page →

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…