Help Center> CodeArts Deploy> Best Practices> Implementing Grays Release Based on Kubernetes Nginx-Ingress
Updated on 2024-05-24 GMT+08:00

Implementing Grays Release Based on Kubernetes Nginx-Ingress

Application Scenario

This practice implements gray release based on native Kubernetes features. When you upgrade a new system, services may be stopped or gray verification may fail. The native Kubernetes service features help you upgrade system smoothly without affecting services.

Solution Architecture

During system upgrade, a group of gray loads are created when developers deploy applications for the first time. In this case, the system version in the gray loads is the new version. The Service forwards some traffic to the gray loads, and the testers verify the version in the gray loads. After the version verification is complete, the developers start to deploy the application for the second time to upgrade the services on the live network. In this case, the Service forwards all traffic to the gray loads and upgrades the services to the latest version on the live network. After the upgrade is complete, the Service forwards all traffic back to the live network load and releases the gray loads. Now, the new system is released.

Figure 1 Gray release scheme

Prerequisites

  • A project is available. If no project is available, create one first.
  • You have the permission to create applications. For details, see Editing Permissions.
  • Service version 1 is available and contains the following resources:
    • A CCE cluster, for example, cce-ldf, is available.
    • A deployment, for example, deployment-doc, has been created in the CCE cluster.
    • A Service, for example, service-doc, has been created in the CCE cluster.
    • A route, for example, ingress-doc, has been created in the CCE cluster.
    • The nginx-ingress plug-in has been installed in the CCE cluster.

Procedures

Figure 2 Process flow
  1. Create an application.

    1. Go to the CodeArts homepage and click the target project name to access the project.
    2. Choose CICD > Deploy and click Create Application. The Set Basic Information page is displayed.
    3. You can modify the following basic information as required:

      Parameter

      Description

      Name

      Mandatory. Name of an application. Example: Kubernetes_Nginx-Ingress_Gray_Deployment

      Project

      Retain the default value. Project to which an application belongs.

      Description

      Optional. Description of an application. Example: None

      Execution Host

      Optional. A resource pool is a collection of physical environments where commands are executed during software package deployment. You can use the official resource pool hosted by Huawei Cloud or host your own servers as a self-hosted resource pool on Huawei Cloud. For details about how to host your own servers, see Self-hosted Resource Pool. Example: Official

      Deploy from pipeline

      Optional. After this function is enabled, the app can be executed only by the pipeline driver and cannot be executed independently.

    4. After editing the basic application information, click Next. On the Select Template page, select Blank Template and click OK.

  2. Edit the application.

    On the Deployment Actions tab page, add Kubernetes Nginx-Ingress Gray Deployment (CCE cluster) and modify the parameters described in the following table.
    Table 1 Parameter description

    Parameter

    Description

    Example

    Action Name

    Name of an action displayed in Deployment Actions area.

    Retain the default value.

    Tenant

    • Current tenant: The software package is deployed in your CCE cluster for release.

      Select Current tenant. You must have the CCE cluster operation permission. If you do not have it, select Authorized User for deployment.

    • Other tenant: The software package is deployed in the CCE cluster of another tenant for release in IAM authorization mode.

      If you select Other tenant, you must select an authorized tenant to deploy the CCE cluster.

    Select Current tenant.

    Authorized User

    If you do not have the permission to execute an API, this parameter enables you to obtain the temporary AK/SK of the parent user to execute the CCE API through IAM.

    Deselect it.

    Region

    Select the region for deployment.

    Retain the default value.

    Cluster Name

    Select the Kubernetes cluster applied on CCE.

    cce-ldf

    Namespace

    Select the namespace of the Kubernetes cluster on CCE.

    Retain the default value.

    Workload

    Select the target deployment.

    deployment-doc

    Service

    Name of the service bound to the target workload.

    service-doc

    Ingress

    Select the name of the route bound to the target service.

    ingress-doc

    Container

    Select the name of the CCE container to be deployed.

    container-1

    Image

    Select the image to be deployed.

    Retain the default value.

    Image Tag

    Select the tag of the image to be deployed.

    v2

    Enabling grayscale configuration

    Gray Strategy:
    • Header

      Header-Key: You can enter the key of a custom header.

      Header-Value: You can enter a custom header value. The value can be a character string or a regular expression. The regular expression format is ^....$.

      Gray Traffic Weight (%): Traffic can be customized.

    • Cookie

      Cookie: Custom cookie content can be entered.

      Gray Traffic Weight(%): Traffic can be customized.

      NOTE:

      The values of Header and Cookie can contain a maximum of 500 characters.

    Selected

    Gray Strategy: Header

    Header-Key: foo

    Header-Value: bar

    Gray Traffic Weight(%): 30

  3. Deploy an application (create a gray version).

    Click Save & Deploy to deploy the application. CodeArts Deploy has created the following gray version resources in the CCE cluster and diverts 30% of the live network traffic to the gray load.

    • Workload: deployment-doc-v2. The image version is V2.
      Figure 3 Adding a workload whose image version is V2
    • Service: service-doc-v2
    • Route: ingress-doc-v2

    In this case, you can add a data record (the value of Key is foo and the value of Value is bar) to the header to verify the latest version in the gray load.

  4. Edit the application (deploy the latest version).

    Go to the application created in Step 1 and modify the following parameters.

    Table 2 Parameter description

    Parameter

    Example

    Enabling grayscale configuration

    Deselect it.

  5. Deploy the application (deploy the latest version).

    Click Save & Deploy to deploy the application. CodeArts Deploy has deleted the following gray environment resources from the CCE cluster and replaced the V1 image with the V2 image:

    • Workload: deployment-doc-v2
    • Service: service-doc-v2
    • Route: ingress-doc-v2
    Figure 4 The image version is upgraded to V2.

    You can check whether the system is the latest version on the live network.