官术网_书友最值得收藏!

  • 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
主站蜘蛛池模板: 郑州市| 嵊泗县| 新沂市| 四川省| 开化县| 江北区| 南通市| 岗巴县| 陈巴尔虎旗| 仁寿县| 迁西县| 新干县| 万州区| 林州市| 普安县| 东丰县| 乌审旗| 乌拉特中旗| 抚州市| 浦江县| 怀化市| 宜良县| 潍坊市| 珠海市| 宁海县| 锡林郭勒盟| 黑河市| 建平县| 岳西县| 杨浦区| 新绛县| 紫金县| 万年县| 郎溪县| 伽师县| 云龙县| 宁强县| 沙坪坝区| 化德县| 抚松县| 连州市|