当前位置: 首页 > 文档资料 > 技术文档 Cookbook >

Blue-Green Deployments

优质
小牛编辑
128浏览
2023-12-01

In this recipe is to demonstrate how simple it is to implement Blue-Green Deployments in OpenShift.

Blue-Green Deployments

From https://en.wikipedia.org/wiki/User:Nuqing/Blue-green_deployment

"Blue-green deployment is a release strategy that can be utilized by developers for deploying software in a production environment. Blue can be one particular production environment whereas green can define an identical production environment. Under blue-green deployment strategy, software developers are able to minimize downtime and reduce risk."

The following contents including:

  • Deploying two versions of the same application. The first version will display a blue rectangle.

  • Create a FQDN that can be used to expose the applications.

  • We will first expose the first application.

  • We will also create another version of this application in the same project that displays a green rectangle.

  • We will then switch the FQDN to from the first application (blue) to the second application (green).

blue_green_deployment

Blue

  • Create a new project

$ oc new-project bluegreen
  • List existing image builder or image streams

$ oc new-app -S --image-stream=php
Image streams (oc new-app --image-stream=<image-stream> [--code=<source>])
-----
php
  Project: openshift
  Tags:    5.6, 7.0, latest
  • Create an application

We will be using a sample application that displays a blue or green rectangle. The sample app can be browsed at https://github.com/jbosschina/bluegreen.

We will be using an env var in order to change the color of the box; but in practice you would use a different branch for each version of the code. (E.g. v1 branch and v2 branch).

$ oc new-app --image-stream=php --code=https://github.com/jbosschina/bluegreen.git --env COLOR=blue --name=blue
--> Found image 79f7d44 (7 weeks old) in image stream "openshift/php" under tag "7.0" for "php"

    Apache 2.4 with PHP 7.0
    -----------------------
    Platform for building and running PHP 7.0 applications

    Tags: builder, php, php70, rh-php70

    * The source repository appears to match: php
    * A source build using source code from https://github.com/jbosschina/bluegreen.git will be created
      * The resulting image will be pushed to image stream "blue:latest"
      * Use 'start-build' to trigger a new build
    * This image will be deployed in deployment config "blue"
    * Port 8080/tcp will be load balanced by service "blue"
      * Other containers can access this service through the hostname "blue"

--> Creating resources ...
    imagestream "blue" created
    buildconfig "blue" created
    deploymentconfig "blue" created
    service "blue" created
--> Success
    Build scheduled, use 'oc logs -f bc/blue' to track its progress.
    Run 'oc status' to view your app.
  • Check application deployment status

$ oc get pods
NAME           READY     STATUS      RESTARTS   AGE
blue-1-build   0/1       Completed   0          2m
blue-1-bw5sh   1/1       Running     0          2m

Notice that the build pod has exited and you now have a single instance of the application running under one single pod.

This application displays a blue square.

  • Create a route for the application

$ oc expose service blue --name=bluegreen
route "bluegreen" exposed
  • Test the application

$ oc get route
NAME        HOST/PORT                                        PATH      SERVICES   PORT       TERMINATION   WILDCARD
bluegreen   bluegreen-bluegreen.apps.example.com             blue       8080-tcp                 None

Copy the HOST/PORT and paste it in your browser. You should see something similar to:

blue_deployment

At this point you have deployed an application that displays for illustration purposes a blue rectangle for version 1.

Green

In this section we will:

  • Deploy a new version of this application (Same one as before with a very small change)

  • Point the previously created FQDN (route) to the new service that will be created as part of the new application creation process.

blue_green_active_green

  • Create new version of the application

Create a new application the same way as you did above in Part I. Make sure to name the application as 'green' this time.

$ oc new-app --image-stream=php --code=https://github.com/jbosschina/bluegreen.git --env COLOR=green --name=green
--> Found image 79f7d44 (7 weeks old) in image stream "openshift/php" under tag "7.0" for "php"

    Apache 2.4 with PHP 7.0
    -----------------------
    Platform for building and running PHP 7.0 applications

    Tags: builder, php, php70, rh-php70

    * The source repository appears to match: php
    * A source build using source code from https://github.com/jbosschina/bluegreen.git will be created
      * The resulting image will be pushed to image stream "green:latest"
      * Use 'start-build' to trigger a new build
    * This image will be deployed in deployment config "green"
    * Port 8080/tcp will be load balanced by service "green"
      * Other containers can access this service through the hostname "green"

--> Creating resources ...
    imagestream "green" created
    buildconfig "green" created
    deploymentconfig "green" created
    service "green" created
--> Success
    Build scheduled, use 'oc logs -f bc/green' to track its progress.
    Run 'oc status' to view your app.
  • Wait until the application is built and deployed. You should now see two services if you run:

$ oc get services
NAME      CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
blue      172.30.34.210    <none>        8080/TCP   17m
green     172.30.106.224   <none>        8080/TCP   26s
  • Edit the previously created route and change the service name (from blue to green), all the way at the bottom to the new service that was just created. You are essentially still using the FQDN you had previously created. However, that route will now point to a different (green) service.

$ oc edit route bluegreen

apiVersion: v1
kind: Route
metadata:
  annotations:
    openshift.io/host.generated: "true"
  creationTimestamp: 2017-07-14T08:56:07Z
  labels:
    app: green
  name: bluegreen
  namespace: bluegreen
  resourceVersion: "5441775"
  selfLink: /oapi/v1/namespaces/bluegreen/routes/bluegreen
  uid: 4659584a-6872-11e7-bbc1-0682973451aa
spec:
  host: bluegreen-bluegreen.apps.example.com
  port:
    targetPort: 8080-tcp
  to:
    kind: Service
    name: green
    weight: 100
  wildcardPolicy: None
status:
  ingress:
  - conditions:
    - lastTransitionTime: 2017-07-14T08:56:07Z
      status: "True"
      type: Admitted
    host: bluegreen-bluegreen.apps.example.com
    routerName: router
    wildcardPolicy: None
  • Test the application

$ oc get route
NAME        HOST/PORT                                        PATH      SERVICES   PORT       TERMINATION   WILDCARD
bluegreen   bluegreen-bluegreen.apps.example.com             blue       8080-tcp                 None

Copy the HOST/PORT and paste it in your browser.

You should now see the new version of the recently deployed application with a green rectangle.

最后更新:

类似资料

  • 认证(Authentication) 身份验证是大多数现有应用程序的重要组成部分。有许多不同的方法、策略和方法来处理用户授权。我们最终决定使用什幺取决于特定的应用程序要求,并且与它们的需求密切相关。 passport 是目前最流行的 node.js 认证库,为社区所熟知,并相继应用于许多生产应用中。将此工具与 Nest 框架集成起来非常简单。为了演示,我们将设置 passport-http-bea

  • 下面是一个 XML 技术的列表。 XHTML (可扩展 HTML) 更严格更纯净的基于 XML 的 HTML 版本。 XML DOM (XML 文档对象模型) 访问和操作 XML 的标准文档模型。 XSL (可扩展样式表语言) XSL 包含三个部分: XSLT (XSL 转换) - 把 XML 转换为其他格式,比如 HTML XSL-FO (XSL 格式化对象)- 用于格式化 XML 文档的语言

  • AJAX不能独立工作。 它与其他技术结合使用来创建交互式网页。 JavaScript 松散类型的脚本语言。 在页面中发生事件时调用JavaScript函数。 整个AJAX操作的胶水。 DOM 用于访问和操作结构化文档的API。 表示XML和HTML文档的结构。 CSS 允许将演示样式与内容明确分开,并可通过JavaScript以编程方式进行更改 XMLHttpRequest 与服务器执行异步交互的

  • 可能因为是线下面,再加上公司内部信息流通比较快,一天内的上下午就面完了! 我个人还是对公司的业务非常感兴趣的!所以提前看过好几篇公司业务相关的文章 面试官人很nice,我俩基本上是我一答他一回应,所以我在这里重点挑自己印象里答得不好的地方写写。 技术面 堆和栈的区别?堆是怎么样的数据结构? 数组和链表的具体区别呢?优缺点?存取效率? 原型链?可以先答概念,在用Object和Array来解释各个指向

  • 用例是黑盒测试的功能测试,用于根据系统的使用从系统的开始到结束识别测试用例。通过使用这种技术,测试团队创建了一个测试场景,可以从头到尾根据每个功能的功能运行整个软件。 在这种情况下,有一个测试人员代表用户逐个使用系统的功能。在这种情况下,有一个演员代表用户使用软件系统的功能。 这描述了软件应用程序的逐步功能,可以通过一个例子来理解,假设存在在线资金转移的软件应用程序。转账的各个步骤如下: 用户登录

  • 主要内容:动态分区的缺点,需要分页动态分区的缺点 动态分区的主要缺点是外部碎片。 尽管这可以通过压缩来消除,但正如我们前面所讨论的那样,压缩使得系统效率低下。 我们需要找一种替代机制,以更优化的方式加载分区中的进程。 让我们讨论一个称为分页的动态灵活机制。 需要分页 让我们考虑一个大小为2 MB的进程P1和分为三个分区的主内存。 在三个分区中,两个分区是每个大小为1 MB的空洞。 P1需要在主存中加载2 MB空间。 我们有两个1M