148422597X Kubernetes Management Design Patterns [Vohra 2017-01-29] {E559F6BB}

marco.cirilli
from marco.cirilli More from this publisher
19.06.2021 Views

Chapter 8 ■ Using Rolling UpdatesTable 8-1. Fields for Rolling Update to a DeploymentField Description ExamplemaxUnavailablemaxSurgeThe maximum number of podsthat may become unavailableduring the update. The value maybe an absolute number, such as 3,or a percentage, for example 30%.Default value is 1. The value cannotbe 0 if maxSurge is 0.The maximum number of podsthat may be running abovethe configured or desired levelspecified as a number or apercentage. Default value is 1.Cannot be 0 if maxUnavailable is 0.If set to 20% the maximum number of pods thatmay be unavailable cannot exceed 20%, and 80%of the pods must always be available. When theupdate starts, the old RC is scaled down to 80%immediately and new pods started for the newRC. As new pods are started old RC pods arestopped, so that the number of pods available isalways 80% of the configured replication level.If set to 10% the new RC may surge to 110%of the configured or desired number of podsimmediately when the update is started, but notmore than 110% of the configured replicationlevel. As old RC pods are stopped more new RCpods are started, but at any given time the totalnumber of pods must not exceed 110%.The Deployment spec provides two fields (Table 8-2) for the rolling update rollback. Neither of thesefields are required.Table 8-2. Fields for Rolling Update RollbackFieldrollbackTorevisionHistoryLimitDescriptionThe config the deployment is rolled back to in a rollback. The RollbackConfigprovides a field revision to specify the revision to roll back to. If set to 0 rollsback to the last revision.The number of old replica sets to retain to allow a rollback.Next, we shall demonstrate rolling update of a deployment. Create a deployment file mysqldeployment.yaml:sudo vi mysql-deployment.yamlCopy the following listing to the definition file:apiVersion: extensions/v1beta1kind: Deploymentmetadata:name: mysql-deploymentspec:replicas: 5template:metadata:labels:app: mysql187

Chapter 8 ■ Using Rolling Updatesspec:containers:- name: mysqlimage: mysql:5.5ports:- containerPort: 80strategy:type: RollingUpdaterollingUpdate:maxUnavailable: 75%maxSurge: 30%rollbackTo:revision: 0Figure 8-23 shows the definition file in a vi editor.Figure 8-23. Definition file for a deployment188

Chapter 8 ■ Using Rolling Updates

Table 8-1. Fields for Rolling Update to a Deployment

Field Description Example

maxUnavailable

maxSurge

The maximum number of pods

that may become unavailable

during the update. The value may

be an absolute number, such as 3,

or a percentage, for example 30%.

Default value is 1. The value cannot

be 0 if maxSurge is 0.

The maximum number of pods

that may be running above

the configured or desired level

specified as a number or a

percentage. Default value is 1.

Cannot be 0 if maxUnavailable is 0.

If set to 20% the maximum number of pods that

may be unavailable cannot exceed 20%, and 80%

of the pods must always be available. When the

update starts, the old RC is scaled down to 80%

immediately and new pods started for the new

RC. As new pods are started old RC pods are

stopped, so that the number of pods available is

always 80% of the configured replication level.

If set to 10% the new RC may surge to 110%

of the configured or desired number of pods

immediately when the update is started, but not

more than 110% of the configured replication

level. As old RC pods are stopped more new RC

pods are started, but at any given time the total

number of pods must not exceed 110%.

The Deployment spec provides two fields (Table 8-2) for the rolling update rollback. Neither of these

fields are required.

Table 8-2. Fields for Rolling Update Rollback

Field

rollbackTo

revisionHistoryLimit

Description

The config the deployment is rolled back to in a rollback. The RollbackConfig

provides a field revision to specify the revision to roll back to. If set to 0 rolls

back to the last revision.

The number of old replica sets to retain to allow a rollback.

Next, we shall demonstrate rolling update of a deployment. Create a deployment file mysqldeployment.yaml:

sudo vi mysql-deployment.yaml

Copy the following listing to the definition file:

apiVersion: extensions/v1beta1

kind: Deployment

metadata:

name: mysql-deployment

spec:

replicas: 5

template:

metadata:

labels:

app: mysql

187

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!