Since we talked already about rollout strategies, lets have a look how to rollout this new version of application on day #20
At the beginning the main command responsible for managing deployments was oc deploy . It has deprecated and oc rollout took over managing of deployment statuses. Whenever a new deployment is started, the Deployment Config configuration is cloned into a new Replication Controller. This way OpenShift stores information about past versions of your application. You may have had different environment variables, different image versions or volumes used across versions. That information is held in the Replication Controllers.
The oc rollout command, together with subcommands visible below, allows easier (compared to oc deploy ) management of the deployments and versions.
1 2 3 4 5 6 7 8 9 10 11 |
$ oc rollout -h ... Available Commands: cancel cancel the in-progress deployment history View rollout history latest Start a new rollout for a deployment config with the latest state from its triggers pause Mark the provided resource as paused resume Resume a paused resource retry Retry the latest failed rollout status Show the status of the rollout undo Undo a previous rollout |
The oc rollout latest and oc rollout cancel are the basic replacements for oc deploy functionality. Deploying latest deployment config and then cancelling it can be seen below.
1 2 3 4 5 |
$ oc rollout latest node42 deploymentconfig "node42" rolled out $ oc rollout cancel dc node42 deploymentconfig "node42" cancelling |
I had to specify explicitly that I want to cancel deployment of Deployment Config. No clue why, since anyway only Deployment Config is accepted and trying with Replication Controller does not work.
1 2 3 4 |
# fails # only for illustration purpose $ oc rollout cancel rc node42-5 error: expected deployment configuration, got replicationcontrollers |
Displaying history refers to the previous deployments and Replication Controllers. After deleting the Replication Controller number 1, it is no longer visible in history. You can see the output of all 3 commands below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
$ oc rollout history dc node42 deploymentconfigs "node42" REVISION STATUS CAUSE 1 Complete image change 2 Complete config change 3 Complete manual change 4 Failed cancelled by the user 5 Complete manual change $ oc delete rc node42-1 replicationcontroller "node42-1" deleted $ oc rollout history dc node42 deploymentconfigs "node42" REVISION STATUS CAUSE 2 Complete config change 3 Complete manual change 4 Failed cancelled by the user 5 Complete manual change |
As for the other subcommands, status displays information about latest deploy state. The retry subcommand allows starting again a failed deployment.
Next of the subcommands – undo – gives you possibility to go back to previous working version of the application. Undoing the deployment created a new Replication Controller.
1 2 3 4 5 6 7 8 9 10 |
$ oc rollout undo dc/node42 deploymentconfig "node42" rolled back $ oc get rc NAME DESIRED CURRENT READY AGE node42-2 0 0 0 1d node42-3 0 0 0 1d node42-4 0 0 0 15m node42-5 0 0 0 13m node42-6 0 0 0 11s |
You can also specify which of previous versions you would like to deploy.
1 2 3 4 5 6 7 8 9 10 11 |
$ oc rollout undo dc node42 --to-revision=3 deploymentconfig "node42" rolled back $ oc get rc NAME DESIRED CURRENT READY AGE node42-2 0 0 0 1d node42-3 0 0 0 1d node42-4 0 0 0 18m node42-5 0 0 0 16m node42-6 0 0 0 3m node42-7 4 4 4 49s |
Again a new Replication Controller is added, but based on manually selected version of Replication Controller.
Documentation
https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#writing-a-deployment-spec – official Kubernetes documentation about Deployments
https://docs.openshift.org/3.6/dev_guide/deployments/deployment_strategies.html – OpenShift deployment strategies guide
Environment
The commands were executed using minishift and the following client/server versions of OpenShift.
Client:
Server:
Newsletter
Thanks for reading the OpenShift morsels. To get updates about new articles, you can sign up to the newsletter below.
As a thank you message, you will also get access to OpenShift CLI CheatSheet listing most commonly used commands together with a short explanation.