- Kubernetes on AWS
- Ed Robinson
- 279字
- 2021-06-10 18:41:27
Rolling out changes
One of the key functions of the deployment resource is to manage the roll-out of new versions of an application. Let's look at an example of how you would do this.
First, let's update the Dockerfile for version 2 of our Hello World application:
Dockerfile FROM nginx:alpine COPY index.html /usr/share/nginx/html/index.html
You may have noticed that the HTML we used for version 1 was a little incomplete, so we are using the COPY command in the Dockerfile to copy an index.html file into our container image.
Use your text editor to create an index.html file that will be visually distinguishable from version 1. I took the opportunity to add a proper DOCTYPE, and, of course, to use CSS to re-implement the sadly now defunct blink tag! Since this isn't a book about web design, feel free to make whatever changes you want:
index.html <!DOCTYPE html> <html> <head> <style> blink { animation: blink 1s steps(1) infinite; } @keyframes blink { 50% { color: transparent; } } </style> <title>Hello World</title> </head> <body> <h1>Hello <blink>1994</blink></h1> </body> </html>
Next, use Docker to build your version 2 image:
docker build -t hello:v2 .
Now we can use kubectl to update the deployment resource to use the new image:
kubectl set image deployment/hello hello=hello:v2
Wait a few moments for Kubernetes to launch the new pod, and then refresh your browser; you should see your changes.
When we update a deployment, behind the scenes Kubernetes creates a new replica set with the new configuration and handles rolling the new version out. Kubernetes also keeps track of the different configurations you have deployed. This also gives you the ability to roll a deployment back if required:
$ kubectl rollout undo deployment/hello deployment "hello" rolled back