Updated on 2024-05-10 GMT+08:00

Solution Overview

What Is Jenkins?

Jenkins is an open source continuous integration (CI) tool that provides user-friendly GUIs. It originates from Hudson and is used to automate all sorts of tasks related to building, testing, and delivering or deploying software.

Jenkins is written in Java and can run in popular servlet containers such as Tomcat, or run independently. It is usually used together with the version control tools (or SCM tools) and build tools. Jenkins supports various languages and is compatible with third-party build tools, such as Maven, Ant, and Gradle. It seamlessly integrates with common version control tools, such as SVN and Git, and can directly connect to source code hosting services, such as GitHub.

Constraints

  • This solution can be deployed only in CCE clusters. It is not supported in DeC.
  • CCE does not provide maintenance and support for Jenkins. The maintenance is provided by the developers.

Solution Architecture

You can install Jenkins using the following methods:

  • You can use a single Master to install Jenkins. The Master handles jobs and builds and releases services. However, security risks may exist.
  • Another one is to use Master+Agents. Master schedules build jobs to Agents for execution, and monitors Agent status. Agents execute build jobs dispatched by the Master and return the job progress and result.

You can install the Master and Agents on VMs, containers, or combination of the two. For details, see Table 1.

Table 1 Jenkins deployment modes

Deployment Mode

Master

Agent

Advantages and Disadvantages

Single Master

VMs

-

  • Advantage: Localized construction is easy to operate.
  • Disadvantage: Job management and execution are performed on the same VM and the security risk is high.

Single Master

Containers

-

  • Advantage: Kubernetes containers support self-healing.
  • Disadvantage: Job management and execution are not isolated. Security risks exist.

Master+Agents

VMs

VMs

  • Advantage: Job management and execution are isolated and the security risk is low.
  • Disadvantage: Agents are fixed. Resources cannot be scheduled and the resource utilization is low and the maintenance cost is high.

Containers (Kubernetes cluster)

  • Advantage: Containerized Agents can be fixed or dynamic. Kubernetes schedules the dynamic Agents, improving the resource utilization. Jobs can be evenly allocated based on the scheduling policy, which is easy to maintain.
  • Disadvantage: The Master may break down and the recovery cost is high.

Master+Agents

Containers (Kubernetes cluster)

Containers (Kubernetes cluster)

  • Advantage: Containerized Agents can be fixed or dynamic. Kubernetes schedules the dynamic Agents, improving the resource utilization. The Master is self-healing and the maintenance cost is low. Agents and the Master can be deployed in the same cluster or in different clusters.
  • Disadvantage: The system is complex and the environment is difficult to set up.

In this section, Jenkins is installed with the containerized Master and Agents. Kubernetes schedules the dynamic Agents. For details about the architecture, see Figure 1.

  • The Master handles jobs. Install Kubernetes add-ons on the Master to use the Kubernetes platform resources.
  • The Kubernetes platform generates pods for Agents to execute jobs. When a job is scheduled on the Master, the Master sends a request to the Kubernetes platform using the Kubernetes add-on. After receiving the request, Kubernetes builds a pod using the pod template to send requests to the Master. After the Master is successfully connected, you can execute the job on the pod.
Figure 1 Installing Jenkins on Kubernetes

Procedure

  1. Installing and Deploying Jenkins Master

    Jenkins Master is deployed in the CCE cluster using container images.

  2. Configuring Jenkins Agent

    Jenkins can fix Agents in the cluster or use the pipeline to interconnect with CCE to provide pods for Agents to execute jobs. The dynamic Agents use Kubernetes add-ons to configure cluster authentication and user permissions.

  3. Using Jenkins to Build a Pipeline

    The Jenkins pipeline interconnects with SWR and calls docker build/login/push commands in Agents to package and push images automatically.

    You can also use pipelines to deploy and upgrade Kubernetes resources (such as Deployments, Services, ingresses, and jobs).