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
Helm CLI is installed and connected to the cluster using kubectl. For detailed instructions, see Installing Helm and Connect to an ACK cluster using kubectl.
Precautions
No technical support is provided for Jenkins. The developers who use Jenkins need to maintain Jenkins.
The Helm chart and container images for Jenkins originate from repositories outside Chinese mainland, which can cause image pull failures. You can use one of the following solutions:
Subscribe to overseas source images using Container Registry. For instructions, see Sync images by using artifact subscription.
Create a Global Accelerator (GA) instance to pull images directly using its global acceleration network. For details, see Accelerate cross-region ACK image pulls with GA.
Step 1: Deploy Jenkins
-
Add the Jenkins Helm repository.
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.
-
Create a namespace named
cicd.kubectl create ns cicd -
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="<YOUR_SECURE_PASSWORD>"-
persistence.storageClass: Required. Specifies the storage class for the persistent volume that stores the jenkins_home directory. If you set this to"alicloud-disk-available", the system automatically selects an available cloud disk type. -
persistence.size: Required. Specifies the size of the cloud disk. The minimum size for an Alibaba Cloud ECS cloud disk is 20 GiB. -
controller.serviceType: Optional. Specifies the type of the service. The default is ClusterIP. -
controller.admin.password: Optional. Specifies the password for the admin user. If not specified, Jenkins generates a random password.
For more information about other parameters, see helm-charts.
-
-
Check the status of the Jenkins pod and wait for it to enter the Running state.
kubectl -n cicd get poExpected output:
NAME READY STATUS RESTARTS AGE jenkins-0 2/2 Running 0 3m3s
-
-
View the external IP address of the service.
If you set the service type to LoadBalancer, use the external IP address to access the Jenkins dashboard in your browser.
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 2d17h
(Optional) Step 2: Create a pipeline
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 left-side navigation pane, 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 left-side navigation pane, click Build Now to run the build.
In the left-side navigation pane, click Build History. Click 1# to go to the pipeline details page and click Console Output to view the build results.
FAQ
How to retrieve the default Jenkins password?
If you did not specify a password during deployment, run the following command to retrieve the default password:
kubectl -n cicd exec -it svc/jenkins -c jenkins -- /bin/cat /run/secrets/additional/chart-admin-password && echo