Skip to content

Kubernetes & OpenShift: Build, deploy & roll back

Kubernetes & OpenShift commands for build, deploy & roll back (tags: #deploy #build #rollback #release #compose).

Index
6 items

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

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

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

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

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

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

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/…