Extreme Thinking
kubernetes Deployments, Scaling, Updates, and Rollbacks

2022-09-14


網路看到的保留一下

Activity: Deployments, Scaling, Updates, and Rollbacks

In this activity, you’ll scale, update, and rollback

To complete this activity, first install Docker:

https://docs.docker.com/docker-for-windows/install/

We are using the recently installed minikube.

  1. Create a folder or directory, c:\my-nginx-app

Open Powershell, and start Minikube, run: minikube start –force

  1. Create a new file called Dockerfile, and open it for editing.

  1. Enter lines: FROM nginx

MAINTAINER <name> <email>

  1. Open Powershell as administrator, and cd to directory: c:\my-nginx-app

  1. **Set the Docker environment. Run: minikube docker-env and minikube docker-env Invoke-Expression.**

  1. 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.

  1. List the Docker images. Run: docker images

  1. Create the Kubernetes deployment. Run: kubectl create deployment greetings-app – image=grettings-app:ver1.0

  1. Get the deployments and pods. Run: kubectl get deployments,pods -l app=my-nginx

  1. Scale up the deployment to 3 replicas. Run: kubectl scale deployment my-nginx – replicas=3

  1. Look at the new pods created as the replicas. Run: kubectl get pods -l app=my-nginx

Review the output.

  1. 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

  1. Get the public IP address. Run: minikube ip

  1. 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**

  1. Enter the URL into a browser

  1. 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

  1. Get the revision history. Run: kubectl rollout history deployment my-nginx

kubectl rollout history deployment my-nginx –revision=1

  1. Get information on revision 1. Run: kubectl rollout history deployment my-nginx – revision=1

  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

  1. 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.

  1. 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

  1. View the deployment’s history. Run: kubectl rollout history deployment my-nginx

  1. Get the details on revision 2. Run: kubectl rollout history deployment my-nginx – revision=2

  1. 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.

  1. 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

  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.

  1. 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

  1. 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?

  1. The application my-nginx is still running