Deployment update strategy – recreate

Next, we are going to introduce the other update strategy, recreate, for Deployment. Although there is no subcommand or flag to create a recreate-strategy deployment, users could fulfill this creation by overriding the default element with the specified configuration:

// create a new Deployment, and override the update strategy.
$ kubectl run recreate-nginx --image=nginx --port=80 --replicas=5 --overrides='{"apiVersion": "apps/v1", "spec": {"strategy": {"type": "Recreate"}}}'
deployment.apps "recreate-nginx" created
// verify our new Deployment
$ kubectl describe deployment recreate-nginx
Name: recreate-nginx
Namespace: default
CreationTimestamp: Sat, 05 May 2018 18:17:07 -0400
Labels: run=recreate-nginx
Annotations: deployment.kubernetes.io/revision=1
Selector: run=recreate-nginx
Replicas: 5 desired | 5 updated | 5 total | 0 available | 5 unavailable
StrategyType: Recreate
...

In our understanding, the recreate mode is good for an application under development. With recreate, Kubernetes just scales the current ReplicaSet down to zero Pods, and creates a new ReplicaSet with the full desired number of Pods. Therefore, recreate has a shorter total updating time than rolling-update because it scales ReplicaSets up or down simply, once for all. Since a developing Deployment doesn't need to take care of any user experience, it is acceptable to have downtime while updating and enjoy faster updates:

// try to update recreate-strategy Deployment
$ kubectl set image deployment recreate-nginx recreate-nginx=nginx:stable
deployment.apps "recreate-nginx" image updated
// check both the rollout status and the events of Deployment
$ kubectl rollout status deployment recreate-nginx
$ kubectl describe deployment recreate-nginx
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 3h deployment-controller Scaled up replica set recreate-nginx-9d5b69986 to 5
Normal ScalingReplicaSet 2h deployment-controller Scaled down replica set recreate-nginx-9d5b69986 to 0
Normal ScalingReplicaSet 2h deployment-controller Scaled up replica set recreate-nginx-674d7f9c7f to 5
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.239.182