Background knowledge

In general, the deployment scenarios with K8S are as follows:

Do some quality checking on source code, such as unit testing, code scanning, etc. Build the source code into a deliverable, that is, a container image. Verify the product in test environment. Online deployment with verified artifacts. All YAML files related to the application are managed in the code base using an infrastructure-as-code approach. The above activities involve different roles: development, testing, operation and maintenance. How to ensure that different participants can use a unified delivery process to collaborate is the main problem to be solved by the Cloud Effect Flow delivery pipeline.

The cloud effect continuous delivery pipeline and Kubernetes are well combined together, providing a good foundation for continuous delivery of applications.



The developer submits the code changes to the code repository, and the cloud effect is monitoring the changes of the code base. Once the code changes, the cloud effect continuous deployment pipeline will automatically trigger the running of a build task, including code inspection, build, test deployment, test verification, and production environment deployment.

After the construction, Docker image is generated and automatically uploaded to the application image warehouse. During the deployment phase, the image version constructed by the current pipeline instance is obtained and container arrangement is deployed through Kubernetes. All of this is done by means of automation.

Import the sample source code

1. Go to: Cloud Effectively Code Management CodeUp

https://codeup.aliyun.com?cha…

2. Click “Import Code Base”

  1. Select [URL import], source base address fill in: https://code.aliyun.com/flow-… 1. Click the nine-grid icon on the left and select “Pipeline” to enter the cloud effect pipeline.
  2. Click on the upper right corner to create a new pipeline to enter the pipeline creation wizard page.
  3. Select the template Java· Test, Build the image, publish to Kubernets Cluster/AliCloud Container Service, and click Create.

Configure the code base

After the pipeline is created, a window will automatically pop up to add code source, select CodeUp, code repository select the spring-boot that we imported earlier



Tick [Open Code Source Trigger], and fill in the filter conditions.*

This will automatically trigger pipeline builds, tests, and deployments when the subsequent master branch is modified.

Creating a mirrored repository

Before configuring the mirror-build task for the cloud effect pipeline, you need to create a container image repository to store the images.

If you have an AliCloud container mirror repository, this step can be omitted.

Go to:Ali cloud container mirror service desk, select “Personal Example”



Select “Create Personal”



Set the AliCloud Docker Registry login password, and then click OK.





After setting the password, start creating the mirror repository. Note that the areas in the image below are free to choose, but will need to be used in the next step of configuring the cloud effect pipeline.

As shown in the figure below, we select East China 2 (Shanghai)





Fill in the namespace, warehouse name, custom can be





Select the local warehouse, click [create mirror warehouse], you can complete the creation of mirror warehouse

Configure the pipeline build task

With the container image repository in place, let’s move on to configuring the cloud effect pipeline.



As shown in the image above, click “Java Build Docker Image and Push Image Repositories” to configure the process.

Click to expand the image build and push it to AliCloud image warehouse, and then click New Service Authorization. After the authorization is approved, the Cloud Effect Pipeline Flow will be granted the permission of the previous Alibaba Cloud Image Warehouse.

Click Agree to Authorize on the cloud resource authorization page that pops up.



Next, complete the configuration of the area and warehouse. The label is filled with “${DATETIME}” to indicate that the label is mirrored by the timestamp of the pipeline firing. The Dockerfile path is filled with dockerFile2

Get the Kubernetes cluster configuration file

Note: All operations in this step need to create a new traceless window, and use the AliCloud RAM account created in the first step

1. Open the Traceless Mode window of your browser and type www.aliyun.com in the browser address bar

Use Ctrl/Cmd+Shift+N to open Trackless Mode in Google Chrome.

2. Use the subuser name and password provided in the list of cloud product resources on the left to log into AliCloud



Select [RAM User Login], and fill in the sub-user name and sub-user password of the cloud product resource on the left



  1. Continue to non-trace window operation, the browser to ali cloud ACK console: https://cs.console.aliyun.com

As you can see, an ACK resource has been successfully created for you. If there are multiple clusters, refer to the cloud product resource K8S instance ID



Click the cluster in the navigation bar on the left side of the console, and then click Details in the cluster list.



In the cluster details page, select the cluster information > connection information > public network access, and then click Copy to save the contents of the cluster configuration file. The cluster connection information will be used in the following cloud effect pipeline configuration deployment task.

Configure pipeline deployment tasks

1. Cut back to the cloud pipelining configuration window, click Kubernets Publishing Task, go to Configuration, and then click New Connection.

  1. Cluster Type Select the Custom Cluster, fill in the name of the cluster, and paste the contents of the cluster configuration file saved in step 2 into the cluster configuration file text box, and click Save.
  2. Modify the YAML path to app-configs/manifest-app.
  3. Click Add Parameter, select upstream output for parameter type, fill in IMAGE for parameter name, select mirror construction for parameter value and push it to AliCloud mirror warehouse. Mirror VPC address. * This way, at runtime, Cloud Flow will replace the ${IMAGE} in all files in the YAML path with the address of the IMAGE before kubectl publishing. The sample code in the library file https://code.aliyun.com/flow-…
  4. Click Add Parameter again, select Customize Parameter Type, enter Host parameter name, and enter ACK cluster test domain name parameter value. * The ${HOST} in the YAML file is then replaced with the actual test address. The sample code in the library file https://code.aliyun.com/flow-…

Please refer to the following steps to query the test domain of the cluster:

Return to the previously opened Traceless window, on the Cluster Details page, click Cluster Information > Basic Information, and then click Copy Test Domain, as shown in the figure below.



Description: prefix will test for the domain name, please paste *. Take out, such as cc96863588562483e873ee0c367a579b5.cn-shanghai.alicontainer.com.

The configuration page after adding the parameters is shown below.



Continue to click “Add steps” and select “Other” – “Verification of cloud efficiency operation activities”



The following cluster connection needs to be consistent with the kubectl release in the previous step, as shown in the figure below, we will keep the same as before and enter test and click Save

Running pipeline

When the configuration is complete, click the upper right corner of the configuration page to save and run, triggering the pipeline.

Access the SpringBoot sample application

1. After the cluster publication is successful, click Kubectl publish to view the cluster release log. You can see the HOSTS and ADDRESS of the cluster release.



2. Open the local C:\Windows\System32\drivers\etc\hosts file as the administrator, add the Host Address and Address to the hosts file (separated by space), as shown in the following picture, and press Ctrl+S to save the file.

Note: For Linux and Mac systems, please modify the /etc/hosts file.



3. Open the domain name in your browser and return to the following page, which indicates that the SpringBoot sample application has been successfully deployed.

Modify any code to trigger continuous delivery

Because we turned on code source firing earlier, the pipeline will automatically be triggered when we detect a change in the master branch.

June 9-12, to complete the task with alibaba r&d efficiency summit limited edition T-shirt 】 【 https://developer.aliyun.com/…