Kubernetes – Deployments
There’s an upgraded version of the replication controller called deployments. They manage deployments of replica sets, an upgraded replication controller. They can update the replica set and roll it back.
The matchLabels and selectors have been updated with many new features. A new deployment controller was added to the Kubernetes master which makes it possible to make changes mid-deployment.
Changing the Deployment
- Updating
It’s possible to update an ongoing deployment before it’s finished, which settles the existing deployment and makes a new one.
- Deleting
By deleting the deployment before it is completed, the user can pause or cancel it. Recreating the deployment will restart it.
- Rollback
Using DeploymentSpec.PodTemplateSpec = oldRC.PodTemplateSpec, we can roll back a deployment or a deployment in progress.
Deployment Strategies
Deployment strategies help define how the new RC should replace the old one.
- Recreate
All existing RC will be killed and the new ones will be brought up, so deployment will be quick, but there will be downtime while the old pods are down.
- Rolling Update
It gradually removes the old RC and replaces it with the new one. This results in slow deployment, but there is no deployment. At all times, only a few old pods and few new pods are available.
Deployment’s configuration file looks like this.
apiVersion: extensions/v1beta1 --------------------->1 kind: Deployment --------------------------> 2 metadata: name: Tomcat-ReplicaSet spec: replicas: 3 template: metadata: lables: app: Tomcat-ReplicaSet tier: Backend spec: containers: - name: Tomcatimage: tomcat: 8.0 ports: - containerPort: 7474
We’ve defined the kind as deployment in the above code, which is the only thing different from replica sets.
Create Deployment
$ kubectl create –f Deployment.yaml –recorddeployment “Deployment” created Successfully.
Fetch Deployment
$ kubectl get deploymentsNAME DESIRED CURRENT UP-TO-DATE AVILABLE AGE
Deployment 3 3 3 3 20s
Status of Deployment
$ kubectl rollout status deployment/DeploymentDeployment update
$ kubectl set image deployment/Deployment tomcat=tomcat:7.0Roll Back to Previous Deployment
$ kubectl rollout undo deployment/Deployment –to-revision=2