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

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
主站蜘蛛池模板: 凤庆县| 洛阳市| 武功县| 龙川县| 梁平县| 大足县| 衡东县| 阜宁县| 酉阳| 乌鲁木齐县| 盐池县| 罗甸县| 井冈山市| 福建省| 容城县| 白河县| 南丰县| 新乐市| 孝昌县| 沙田区| 富阳市| 宁武县| 霞浦县| 合阳县| 阿拉善盟| 囊谦县| 周口市| 墨竹工卡县| 来安县| 汨罗市| 达州市| 诸城市| 西安市| 龙川县| 县级市| 岫岩| 格尔木市| 墨竹工卡县| 合水县| 时尚| 安平县|