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

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

Setting the EnvironmentChapter 8 ■ Using Rolling UpdatesCreate an Amazon EC2 instance based on the Amazon Linux AMI. Obtain the public IP of the instance andSSH log in to the instance:ssh -i "docker.pem" ec2-user@54.87.191.230Create a Kubernetes cluster using an AWS CloudFormation consisting of a single controller and threeworker nodes running CoreOS, as shown in Figure 8-2.Figure 8-2. CloudFormation EC2 instancesAfter starting the cluster and setting up an A record for the controller instance IP address in the publicDNS name for the CloudFormation, SSH log in to the controller instance:ssh -i "kubernetes-coreos.pem" core@52.205.169.82The controller CoreOS instance is logged in as shown in Figure 8-3.Figure 8-3. SSH logging into the controller instanceInstall kubectl binaries and list the nodes:./kubectl get nodesThe single controller node and the three worker nodes are listed as shown in Figure 8-4.173

Chapter 8 ■ Using Rolling UpdatesFigure 8-4. Listing the nodesThe kubectl rolling-update command is used to perform a rolling update. The syntax for therolling-update command is as follows.kubectl rolling-update OLD_CONTROLLER_NAME ([NEW_CONTROLLER_NAME] --image=NEW_CONTAINER_IMAGE | -f NEW_CONTROLLER_SPEC)The old container name is required to be specified, and if a new controller name is to be assigned tothe updated RC, a new controller name may be specified. Either a new container image or a new containerspecification must be specified as a command parameter. Next, we shall discuss performing a rolling updateusing each of the methods; a new container image and a new controller specification.Rolling Update with an RC Definition FileIn this section we’ll discuss the rolling update of an existing replication controller by providing an RCdefinition file to the kubectl rolling-update command. The following requirements apply for rollingupdatingan RC.1. The new replication controller must be in the same namespace.2. The new replication controller name in the definition file must not be the sameas the existing replication controller being updated.3. The new replication controller must specify at least one matching key with anonequal value in the selector field.First, create a replication controller to be updated. The following RC definition file mysql.yaml createsan RC called mysql and specifies three replicas. Create a definition file mysql.yaml in a vi editor:sudo vi mysql.yamlCopy the following source code to the definition file:---apiVersion: v1kind: ReplicationControllermetadata:name: mysqllabels:app: mysql-app174

Chapter 8 ■ Using Rolling Updates

Figure 8-4. Listing the nodes

The kubectl rolling-update command is used to perform a rolling update. The syntax for the

rolling-update command is as follows.

kubectl rolling-update OLD_CONTROLLER_NAME ([NEW_CONTROLLER_NAME] --image=NEW_CONTAINER_

IMAGE | -f NEW_CONTROLLER_SPEC)

The old container name is required to be specified, and if a new controller name is to be assigned to

the updated RC, a new controller name may be specified. Either a new container image or a new container

specification must be specified as a command parameter. Next, we shall discuss performing a rolling update

using each of the methods; a new container image and a new controller specification.

Rolling Update with an RC Definition File

In this section we’ll discuss the rolling update of an existing replication controller by providing an RC

definition file to the kubectl rolling-update command. The following requirements apply for rollingupdating

an RC.

1. The new replication controller must be in the same namespace.

2. The new replication controller name in the definition file must not be the same

as the existing replication controller being updated.

3. The new replication controller must specify at least one matching key with a

nonequal value in the selector field.

First, create a replication controller to be updated. The following RC definition file mysql.yaml creates

an RC called mysql and specifies three replicas. Create a definition file mysql.yaml in a vi editor:

sudo vi mysql.yaml

Copy the following source code to the definition file:

---

apiVersion: v1

kind: ReplicationController

metadata:

name: mysql

labels:

app: mysql-app

174

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

Saved successfully!

Ooh no, something went wrong!