Skip to content

Kubernetes: Deploy, roll out, roll back, scale

7 Kubernetes commands: Deploy, roll out, roll back, scale. Click a command to see what each part does.

Index
7 items
Click a command to see what each part does.

Deploy, roll out, roll back, scale7

  • kubectl diff -f <dir> && kubectl apply -f <dir>Preview then apply manifests

    What each part does

    1. diff -f <dir>show what would change on the server
    2. &&continue only if diff ran without error (diff exits 1 when there are changes; use ; instead if you want to apply anyway)
    3. apply -f <dir>create or update every manifest in the folder
  • kubectl set image deployment/<deployment> <container>=<image>:<tag> -n <namespace>Change the image of a deploymentCaution

    What each part does

    1. set imageupdate container images → triggers a rolling update
    2. deployment/<deployment>which deployment
    3. <container>=<image>:<tag>container name in the pod spec = new image
  • kubectl rollout status deployment/<deployment> --timeout=5mWait for the rollout to finish

    What each part does

    1. rollout statuswatch progress until done or failed
    2. --timeout=5mgive up (non-zero exit) after 5 minutes: good for CI
  • kubectl rollout history deployment/<deployment>; kubectl rollout undo deployment/<deployment> --to-revision=<n>History and rollbackCaution

    What each part does

    1. rollout historylist revisions
    2. rollout undogo back to the previous revision
    3. --to-revision=<n>or to a specific revision from the history
  • kubectl rollout restart deployment/<deployment> -n <namespace>Restart all pods of a deploymentCaution

    What each part does

    1. rollout restartrolling restart without changing the spec (picks up new ConfigMap/Secret values)
  • kubectl scale deployment/<deployment> --replicas=<n>Scale replicasCaution

    What each part does

    1. scaleset the desired replica count
    2. --replicas=<n>new count (0 stops the app)
  • kubectl create deployment <name> --image=<image> --dry-run=client -o yaml > deploy.yamlGenerate a manifest without creating anything

    What each part does

    1. create deploymentbuild a Deployment object
    2. --dry-run=clientdon't send it to the cluster
    3. -o yamlprint it as YAML
    4. > deploy.yamlsave to a file to edit and commit

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