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

  • 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
主站蜘蛛池模板: 贡嘎县| 鄂托克前旗| 山西省| 元氏县| 阿克苏市| 广河县| 稻城县| 寿光市| 兴城市| 安西县| 凤山县| 商水县| 宝应县| 台北县| 罗江县| 瑞安市| 定兴县| 策勒县| 汶川县| 西乌珠穆沁旗| 遵化市| 临沂市| 平安县| 东辽县| 汉源县| 大名县| 长沙县| 华亭县| 荃湾区| 邢台县| 大庆市| 东乡县| 新昌县| 合肥市| 安阳县| 华蓥市| 澄迈县| 玛多县| 金塔县| 巧家县| 剑河县|