kubernetes Deployments, Scaling, Updates, and Rollbacks
Activity: Deployments, Scaling, Updates, and Rollbacks
In this activity, you’ll scale, update, and rollback
To complete this activity, first install Docker:
We are using the recently installed minikube.
- Create a folder or directory, c:\my-nginx-app
Open Powershell, and start Minikube, run: minikube start –force
- Create a new file called Dockerfile, and open it for editing.
- Enter lines: FROM nginx
MAINTAINER <name> <email>
- Open Powershell as administrator, and cd to directory: c:\my-nginx-app
|**Set the Docker environment. Run: minikube docker-env and minikube docker-env
- Run the Docker build. Run the exact line: docker build -t nginx:1.17.10 . Image nginx, version 1.17.10 is downloaded and built.
- List the Docker images. Run: docker images
- Create the Kubernetes deployment. Run: kubectl create deployment greetings-app – image=grettings-app:ver1.0
- Get the deployments and pods. Run: kubectl get deployments,pods -l app=my-nginx
- Scale up the deployment to 3 replicas. Run: kubectl scale deployment my-nginx – replicas=3
- Look at the new pods created as the replicas. Run: kubectl get pods -l app=my-nginx
Review the output.
- Create a service to access the pods and container. The service is of type nodeport and map the execution port 80, to port 80.
Run: kubectl create service nodeport my-nginx –tcp=80:80
- Get the public IP address. Run: minikube ip
- Get the execution port. Run: kubectl get services -l app=my-nginx
The mapped port is: 31996.
**Access the application with url: : In this example: http://172.17.107.38:31996**
- Enter the URL into a browser
- Get the image on which the deployment is based. Run: kubectl describe deployment my-nginx
See the deployment’s image: it should be nginx:1.17.10
- Get the revision history. Run: kubectl rollout history deployment my-nginx
kubectl rollout history deployment my-nginx –revision=1
- Get information on revision 1. Run: kubectl rollout history deployment my-nginx – revision=1
- Build a new version 1.18.0 image for deployment my-nginx. This is a later version Run: docker build -t nginx:1.18.0 .
View the new image at version 1.18.0. Run: docker images
- Set the deployment image to the new nginx 1.18.0 version.
Run: kubectl set image deployment my-nginx nginx=nginx:1.18.0 –record
The deployment’s image is updated.
- Describe the deployment and see the deployment’s new image. Run: kubectl describe deployment my-nginx
The deployment is now running image version 1.18.0
- View the deployment’s history. Run: kubectl rollout history deployment my-nginx
- Get the details on revision 2. Run: kubectl rollout history deployment my-nginx – revision=2
- Get the information on the deployments, pods, and replicas. Run: kubectl get deployments,replicaset,pods -l app=my-nginx
Notice there are 2 replicasets, but only 1 replicaset is active. The inactive replicaset is for revision 1, and is there for roll back.
- Run a rollback to revision 1 of deployment my-nginx.
List the revision history. Run: kubectl rollout history deployment my-nginx
To go back to revision 1, run: kubectl rollout undo deployment my-nginx –to-revision=1 Run the kubectl rollout undo deployment my-nginx –to-revision=1
- List the history. Run: kubectl rollout history deployment my-nginx
Notice there is no longer a revision 1, but the current revision is revision 3. Revision 1, is now revision 3.
- Get the rollout history for the current deployment nginx, and see the image for the deployment. The image will be nginx, version 1.17.10, which was the original version before the rolling update.
Run: kubectl rollout history deployment my-nginx –revision=3
- List the deployments, replicasets and pods for application my-nginx. Run: kubectl get deployments,replicasets,pods -l app=my-nginx
Which replicaset is active now?
- The application my-nginx is still running