☁️Automating Kubernetes Deployment Using CodeArts Pipeline
🔦Introduction
Hi everyone, in today’s article, we will attempt to automate the Kubernetes deployment process from code commit to deployment in a cloud environment. I have previously written two articles about container and Kubernetes deployments, and in this exercise, I will utilize the demonstrations from those articles and deploy those tasks sequentially using the CodeArts Pipeline. During this demonstration, we will primarily utilize Huawei Cloud’s CodeArts and CCE platforms. Additionally, we will use Huawei Cloud’s ECS and SWR services to create and store our container images. In this article, I want to focus on the pipeline part rather than other aspects such as building a container, pushing it, and deploying it in a Kubernetes environment. I have already covered those parts in the articles I have written before, which you can also access here 👇
№1 Step-by-Step Container Deployment in CodeArts
№2 A Practical Guide to Kubernetes Deployment with Huawei’s CCE and CodeArts
Before we begin the demo, although I expect you to be already familiar with these services, I will briefly overview ECS, SWR, CCE, and CodeArts.
1️⃣ ECS: Elastic Cloud Server (ECS) is a versatile and scalable cloud computing service that empowers users to create and manage virtual servers in the cloud.
2️⃣ SWR: SoftWare Repository for Container (SWR) provides easy, secure, and reliable management of container images throughout their lifecycles, featuring image push, pull, and deleting.
3️⃣ CCE: Huawei Cloud CCE (Cloud Container Engine) is essentially a cloud-based platform for running containerized applications. It helps you deploy and manage containerized apps efficiently and securely on Huawei’s cloud infrastructure.
4️⃣ CodeArts: CodeArts is a one-stop DevSecOps platform that provides out-of-the-box cloud services for requirement delivery, code commit, check, build, verification, deployment, and release throughout the entire software lifecycle. It consists of the following services: Req (Project Management), Repo (Code Hosting), Check (Code Quality), Build (Code Build), Artifact (Build Hosting), Deploy (Build Deployment), Pipeline (Continuous Delivery), TestPlan (Deployment Test).
💻Demo
In this demonstration, as I mentioned in the introduction, we will aim to automate the Kubernetes deployment process from code commit to deployment in a cluster. We’ll achieve this by uploading the related files to the CodeArts Repo and CodeArts Artifact. Then, we’ll build an image using these files. Afterward, we will upload those images and use them in the YAML files, which we will employ to deploy a service on CCE. In this article, I won’t delve into explaining some of the steps I have demonstrated in the articles below, so I may leave some steps undetailed or refer to these articles. For much more detailed information on the steps we are going to undertake, I’ll also provide some other links in the article so you can gather additional information.
Preliminaries
1️⃣ Buy an ECS instance and install Docker
If you’re unsure about how to purchase an instance, you can refer to this link. After you log in to the instance run this command below 👇
apt-get install docker.io -y
and after the installation make sure that Docker is installed. You can refer to article №1 for a detailed guide.
2️⃣ SWR Organization and Login Credentials
You need a private image repository to upload and use our container images. If you don’t know how to do this step you can refer here. Make sure to note down the credentials as we are going to use them in the next steps. (I recommend you generate a Long-term login command which requires your AK/SK credentials)
3️⃣ CCE Cluster, Node, and Secret Configurations
In order to buy a cluster and node, you can refer to article №1. In this article, I’ll show you how you can configure your secrets for our demo.
First, you need to navigate to the ‘ConfigMaps and Secrets > Secrets’ section and click on ‘Create Secret’
Then we are going to select the secret type as depicted in the screenshot below and enter our credentials (SWR log-in commands) into the related boxes. We will use this secret in our YAML file.
4️⃣ Create a CodeArts Project, Upload Related Files to the Repo and Artifact, and Add ECS to the Basic Resources
During the tasks we are going to run, we will use some files, and we need an ECS instance to process these files and build a Docker image. You can refer to this link to access the files we are going to use, and you can refer to article №1 if you are not sure how to complete this step.
Now that we have finished the preparations, we can start creating some tasks.
5️⃣ Building a Docker Image
In this step, I expect you to create a deploy task and configure it as shown in the screenshots below. The main purpose of this task is to build and upload a Docker image to the SWR. Here, the ECS instance which we have connected, clones the repository, builds a Docker image using those files, and finally pushes it to the SWR. You can refer to article №1 for more information on this step. The steps will resemble the screenshot below in my demonstration 👇
6️⃣ Deploying a Kubernetes Deployment
In this step, I expect you to create a deploy task and configure it as shown in the screenshots below. The main purpose of this task is to apply the YAML file we have uploaded to the CodeArts Repo. In this YAML file, I used the image we built in the step before. You can refer to article №2 for more information on this step.
7️⃣ Creating a Pipeline Task
This may be the first step I will undertake, which I haven’t mentioned in articles №1 and №2. Here, we will create a pipeline from scratch. This will help us connect the tasks we created before.
CodeArts Pipeline is your automatic “chef” in the software kitchen. It visualizes and orchestrates continuous integration and continuous delivery (CI/CD) pipelines, taking away the manual steps and streamlining software development
On the CodeArts Pipeline Page, click on ‘Create Pipeline’
Here, we can name the pipeline task, and we need to select the source of this pipeline. We will select the repository we created in Step 4 and click on ‘Next’
Next, the template page appears, and here, there are 10 templates you can use in your pipeline tasks. However, I’ll select the Blank Template and click on ‘OK’
This is the main task page where you can configure your pipeline. Click on ‘New Job’ as depicted in the screenshot below.
From the side of the page, a pop-up will appear, and we will click on the ‘Add’ button next to the ‘Deploy’ task, as we have created 2 tasks before.
After that, we need to select the task we have created before. Since our first step is to build the image, I’m going to choose it. After that, click on ‘OK’, and the task is added to the pipeline process.
Next, I’ll add the deployment step as well and configure some of the stage/task names here. The final result will look like the screenshot below.
Now, we need to configure the pipeline so it automatically runs after the code commits are done. To do this, click on ‘Execution Plan,’ and then turn on the ‘Code commit’ checkbox. After that, we are ready to run the pipeline! Click on ‘Save and Run,’ and the pipeline will start.
After the pipeline finishes, we can head back into the SWR to see the pushed image and to CCE to see the deployed deployment.
8️⃣ Creating an ELB for Deployment
In CCE, we saw the deployment. However, at the moment, it isn’t reachable from the outer network, so we need to create an ELB. To do that, we will go to the workload’s overview and then head into the access mode section. Here, we are going to click on ‘Create’
Then we will select Elastic Load Balancer and configure it as shown in the screenshots below 👇
Now that we have configured the ELB, let’s try to reach the server using the public IP address of the ELB. Copy the public IP address from here and then paste it.
As you can see, we can reach the server we have deployed 👇
9️⃣ Making Changes in a Repository to the Trigger Pipeline
Now it’s time to make some changes in the repository and commit those changes. As I have mentioned before, this will automatically trigger the pipeline task we have created. Here, I’ll make these changes in the repository, and the pipeline will be triggered, as you can see in the screenshot below 👇
After the changes (I have changed the replica value to 4 in the YAML file) if we look at the CCE deployment, we can see the difference.
👉Conclusion
In conclusion, this demonstration has showcased the power of automating the Kubernetes deployment process using Huawei Cloud’s CodeArts and CCE platforms. By leveraging CodeArts Pipeline, ECS, SWR, and CCE, we seamlessly integrated code commit, image building, and deployment into a streamlined workflow. The ability to automate these processes not only saves time and effort but also enhances reliability and consistency in software deployment. As organizations continue to embrace cloud-native technologies, solutions like CodeArts and CCE offer robust tools to accelerate the development and deployment of containerized applications. By following the steps outlined in this demonstration, businesses can effectively harness the capabilities of cloud platforms to drive innovation and agility in their software delivery pipelines.