The author | honest Ali elastic compute cloud team
This article is compiled from Serverless Technology Open course. You can get PPT of series of articles by replying to “Getting started” on the background of Serverless public account.
This course will introduce you to how to quickly build GitLab continuous integration environment based on Aliyun Serverless Kubernetes (ASK) service.
ASK to introduce
First of all, what is ASK? ASK is a serverless version of Kubernetes container service launched by AliYun. Compared with traditional Kubernetes service, the biggest feature of ASK is to access Kubernetes cluster through virtual nodes, and the Master node of Kubernetes is completely hosted by Ali Cloud Container service. Therefore, in the whole ASK cluster, users do not need to manage and operate real nodes, but only care about Pod resources. Pod in ASK is carried by ali Cloud elastic container instance ECI.
The main advantages of ASK are as follows:
- Lower the threshold for users to use Kubernetes without managing nodes;
- There is no need to consider node capacity planning.
- Charging on demand based on Pod;
- The impact level is Pod.
Meanwhile, ASK is mainly applicable to the following scenarios:
- Online business flexibility (live video broadcasting, online education);
- Big Data Computing (Spark);
- Scheduled task;
- CI/CD continuous integration.
Advantages of GitLab CI on ASK
When it comes to CI/CD, the two most familiar tools are Jenkins and GitLab CI. With the popularity of Devops, more and more enterprises adopt GitLab CI as a continuous integration tool. Here is GitLab CI on ASK. Gitlab-runner registers in the ASK cluster as a Pod, and each CI/CD stage also corresponds to a Pod.
The advantages of this are as follows:
- High service availability (Deployment+PVC);
- There is no need to maintain K8s Master and Node nodes, just need to run a Pod (Gitlab-runner) without any build tasks;
- Trigger a build task, start a Pod, charge on demand;
- An outage failure affects only pods.
Practices demonstrate
Next, I will demonstrate how to deploy Gitlab-Runner on Ali Cloud ASK cluster, and deploy Java application to ASK cluster through Gitlab CICD Pipeline.
The main knowledge points involved are:
- Save the configuration of GitLab Runner and Executor through configMap;
- Use secret to save the access credentials of ASK cluster and the key of mirror warehouse;
- Cache runner cache and Maven repository via PVC;
- The container image is cached through imageCache.
All the configuration files (YAML) covered in this lesson have been uploaded to Github for you to download.
Let’s start the demonstration. Please click on the [watch link] for the video version of the course.
1. Prepare the ASK cluster
- Create a standard Serverless K8s cluster in the Container Services Console
- After a cluster is created, the public network address of the API server is displayed in basic information
- The connection information contains the ASK cluster access credentials
2. Prepare PV/PVC
Prepare two NAS disks, one for Gitlab Runner cache and the other for Maven repository. Please replace the NAS Server address and path by yourself
kubectl apply -f mvn-pv.yaml
kubectl apply -f mvn-pvc.yaml
kubectl apply -f nas-pv.yaml
kubectl apply -f nas-pvc.yaml
Copy the code
3. Prepare a Secret
- Copy the certificate public/private key from Kubeconfig to secret, secret.yaml
kubectl apply -f secret.yaml
Copy the code
- The authentication information of docker-Registry is supported by ECI, but the push docker image is still needed
kubectl create secret docker-registry registry-auth-secret --docker-server=registry.cn-hangzhou.aliyuncs.com --docker-username=${xxx} --docker-password=${xxx}
Copy the code
- To view the generated secret, use the following command
kubectl get secret registry-auth-secret --output=yaml
Copy the code
4. Prepare ConfigMap
Copy gitlab Runner URL, token, ASK cluster API server address to config.yaml
kubectl apply -f config-map.yaml
Copy the code
5. Prepare imageCache (optional, save image pull time)
Imagecache -crd is installed on AS K by default. You can use the following command to query the imagecache-crd
#Check whether the image cache CRD works properly
kubectl get crd
#Install the Image Cache CRD
kubectl apply -f imagecache-crd.yaml
#Making imagecache
kubectl apply -f imagecache.yaml
Copy the code
6. Deploy GitLab Runner
kubectl apply -f gitlab-runner-deployment.yaml
Copy the code
7. Perform a simple CI task
The.gitlab-ci.yml in git repo is similar to Jenkinsfile and defines the workflow of the build task. We modify the demo project in SRC/main/webapp/index. The JSP file, and then the git commit -m “change index info” to submit. Pipeline tasks in GitLab are triggered, and the whole process involves compilation, packaging, and deployment.
The cost of
Cost of using ASK versus a prepaid ECS:
As you can see from the above cost calculations, when you have fewer than 126 CI/CD tasks per day, using ASK+ECI is more cost-effective than buying an ECS with an annual monthly contract. In addition to enjoying the on-demand payment, it also reduces the operation and maintenance costs. More importantly, when the business scale expands and the number of CI/CD tasks increases rapidly, there is no need to worry about Node expansion. ASK+ECI’s solution can be considered a standard fit for CI/CD continuous integration scenarios.
Course recommended
In order for more developers to enjoy the dividends brought by Serverless, this time, we gathered 10+ Technical experts in the field of Serverless from Alibaba to create the most suitable Serverless open course for developers to learn and use immediately. Easily embrace the new paradigm of cloud computing – Serverless.
Click to free courses: https://developer.aliyun.com/learning/roadmap/serverless
Serverless public number, release the latest information of Serverless technology, collect the most complete content of Serverless technology, pay attention to Serverless trend, pay more attention to the confusion and problems encountered in your landing practice.