Jenkins is used to implement continuous integration and continuous deployment (CI/CD). You can deploy Jenkins in Container Service for Kubernetes (ACK) clusters to ensure high availability of services and reduce O&M costs. This topic describes how to deploy Jenkins in an ACK cluster, and then create and deploy a simple application.
Prerequisites
You have installed the Helm CLI and connected to the cluster using kubectl. For more information, see Installing Helm and Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.
Precautions
No technical support is provided for Jenkins. The developers who use Jenkins need to maintain Jenkins.
The Helm charts and images for Jenkins are from sources outside China. As a result, pull operations may fail. You can use the following solutions:
Use Container Registry (ACR) to subscribe to images from sources outside China. For more information, see Subscribe to images from sources outside China.
Create a Global Accelerator (GA) instance and use its global network acceleration service to pull images directly from sources outside China. For more information, see Use GA to accelerate cross-region pulling of container images for ACK.
Step 1: Deploy Jenkins
Run the following command to configure Jenkins Helm Repo:
helm repo add jenkins https://charts.jenkins.io helm repo updateExpected output:
Hang tight while we grab the latest from your chart repositories... ...Successfully got an update from the "jenkins" chart repository Update Complete. ⎈Happy Helming!⎈Install Jenkins.
Run the following command to create a namespace named
cicd.kubectl create ns cicdRun the following command to deploy Jenkins to the
cicdnamespace.helm -n cicd install jenkins jenkins/jenkins \ --set persistence.storageClass="alicloud-disk-essd" \ --set persistence.size="20Gi" \ --set controller.serviceType="LoadBalancer" \ --set controller.admin.password="admin"persistence.storageClass="alicloud-disk-available": automatically selects an available cloud disk type and creates a disk volume to persist the files in the jenkins_home directory. This parameter is required.
persistence.size="20Gi": sets the minimum capacity of Elastic Compute Service (ECS) cloud disks to 20 GiB. This parameter is required.
controller.serviceType="LoadBalancer": The default value is ClusterIP. This parameter is optional.
controller.admin.password="admin": Specifies the administrator password. This parameter is optional. By default, a random password is generated.
For more information about other parameters, see helm-charts.
Run the following command to query the status of the Jenkins pod and wait until the Jenkins pod runs as normal:
kubectl -n cicd get poExpected output:
NAME READY STATUS RESTARTS AGE jenkins-0 2/2 Running 0 3m3s
By default, the Jenkins Service type is ClusterIP. To access Jenkins from a browser, run the following command to change the Service type.
kubectl -n cicd patch svc jenkins -p '{"spec": {"type": "LoadBalancer"}}'Then, run the following command to view the external IP address of the Service.
kubectl get -n cicd serviceExpected output:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE jenkins LoadBalancer 192.168.***.*** 8.222.***.*** 8080:30949/TCP 2d17h jenkins-agent ClusterIP 192.168.***.* <none> 50000/TCP 2d17hIn a browser, enter the IP address and port that you obtained in the previous step to access the Jenkins service. Then, enter the username and password to log on.
NoteIf you do not specify a password when you deploy Jenkins, run the following command to obtain the default password, which is randomly generated by Jenkins:
kubectl -n cicd exec -it svc/jenkins -c jenkins -- /bin/cat /run/secrets/additional/chart-admin-password && echo
(Optional) Create a pipeline task
This section uses the first-pipeline pipeline build as an example to demonstrate how to create a pipeline build. When you create a pipeline build, Jenkins dynamically launches a slave pod in the ACK cluster and runs the build by default. After Jenkins finishes running the build, it immediately releases the slave pod. For more information about Jenkins configurations, see Jenkins.
Log on to Jenkins. In the navigation pane on the left, click New Item.
In the Enter an item name section, enter first-pipeline, select Pipeline, and then click OK.
On the top of the page, click the Pipeline tab, select the Hello World template, and then click Save.

In the navigation pane on the left, click Build Now to run the build.
In the navigation pane on the left, click Build History. Click 1# to go to the pipeline details page and click Console Output to view the build results.