This topic describes how to deploy Jenkins, a continuous integration environment, in an Alibaba Cloud serverless Kubernetes cluster, and how to perform an application pipeline build. The example in this topic details the pipeline build, including how to compile the source code of the application, build and push the application image, and deploy the application.
You have created a serverless Kubernetes cluster. For more information, see Create a serverless Kubernetes cluster.
- Run the following command to download the Jenkins deployment file:
$ git clone https://github.com/AliyunContainerService/jenkins-on-serverless.git $ cd jenkins-on-serverless
- Persist the jenkins_home directory.
Serverless Kubernetes clusters do not support cloud disks. To persist the jenkins_home directory, create the nfs volume, then modify the serverless-k8s-jenkins-deploy.yaml file to add the following field annotations and set nfs parameters:
#volumeMounts: # - mountPath: /var/jenkins_home # name: jenkins-home ..... #volumes: # - name: jenkins-home # nfs: # path: / # server:
- Run the following command to deploy Jenkins:
$ kubectl apply -f serverless-k8s-jenkins-deploy.yaml
- Log on to Jenkins.
- Log on to the Container Service console.
- In the left-side navigation pane, choose .
- Click the external endpoint of the Jenkins service to log on to Jenkins.
- On the Jenkins logon page, enter the user name and the password. The default user name and password are admin. We recommend that you modify them after you log on to Jenkins.
Create a cluster certificate and an image repository certificate, and build and deploy an application
- Set Kubernetes Cloud parameters to dynamically create a slave pod.
- In the left-side navigation pane, click Manage Jenkins.
- Click Configure System.
- In the Cloud area, enter the API server URL in KubeConfig as the Kubernetes URL.
- Click Add on the right of Credentials.
Before adding a credential, you must obtain KubeConfig on the Basic Information tab page of the target Kubernetes cluster.
In the displayed dialog box, set the following parameters:
- Kind: Select Docker Host Certificate Authentication.
- Client Key: Paste the copied client-key-data content in KubeConfig.
- Client Certificate: Paste the copied client-certificate-data content in KubeConfig.
- ID: Enter the certificate ID. In this example, k8sCertAuth is entered.
- Description: Enter description content.
- Click Add.
- Test connectivity.
Select the added credential in the preceding step from the Credentials drop-down list, and then click Test Connection.
- Enter the external endpoint of the jenkins service as Jenkins URL, and enter the external endpoint of the jenkins-agent service as Jenkins tunnel.
- Click Save.
- To set image repository permission, use kubectl to create jenkins-docker-cfg secret in the target serverless Kubernetes cluster.
In this example, the Beijing image repository provided by Alibaba Cloud is used.
$ docker login -u xxx -p xxx registry.cn-beijing.aliyuncs.com Login Succeeded $ kubectl create secret generic jenkins-docker-cfg --from-file=/root/.docker/config.json
- Create demo-pipeline and access the application service.
- On the Jenkins home page, click demo-pipeline.
- In the left-side navigation pane, click Build with Parameters.
- Modify the parameters according to your image repository information. In this example, the source code repository branch is serverless, and the image is registry.cn-beijing.aliyuncs.com/haoshuwei:stable.
- Click Build.
- Click Build History to check the result. The following figure indicates a success.
- Log on to the Container Service console to view the IP addresses of the services provided by the application.
The source code repository used in this topic can be found at https://github.com/AliyunContainerService/jenkins-demo.