This topic describes how to deploy Jenkins, a continuous integration environment, in a serverless Kubernetes cluster, and provides step-by-step examples on how to build an application delivery pipeline that includes source code compilation, image build and push, and application deployment.
You have created a serverless Kubernetes cluster. For more information, see Create a serverless Kubernetes cluster.
- Run the following command to download the Jenkins package.
$ git clone https://github.com/AliyunContainerService/jenkins-on-serverless.git $ cd jenkins-on-serverless
- Mount a persistent volume to the jenkins_home directory.
Currently, serverless Kubernetes clusters do not support cloud disks. You can mount an NFS volume to the jenkins_home directory. You need to modify the serverless-k8s-jenkins-deploy.yaml file to add the following fields 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 .
- In the left-side navigation pane, choose .
- Select Jenkins and click its external endpoint to log on.
- On the Jenkins logon page, enter the username and password. The default username and
password are both admin. We recommend that you change the username and password after
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.
- On the right-side Manage Jenkins page, click Configure System.
- In the Cloud section, enter the API server URL in KubeConfig as the Kubernetes URL.
- Click Add on the right of Credentials.
Before you add a credential, find KubeConfig in the Configure the cluster credentials section on Basic Information page of the target cluster.In the Add Credentials dialog box that appears, set the following parameters:
- Kind: Select Docker Host Certificate Authentication.
- Client Key: Paste the value of client-key-data from KubeConfig.
- Client Certificate: Paste the value of client-certificate-data from KubeConfig.
- ID: Enter the certificate ID. In this example, k8sCertAuth is entered.
- Description: Enter the description.
- Click Add.
- Test the connectivity.
In the Credentials drop-down list, select the newly added credential in the preceding step and 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 permissions, use kubectl to create a jenkins-docker-cfg secret
in the target cluster.
In this example, an image repository provided by Alibaba Cloud in the China (Beijing) region 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
- Build demo-pipeline and access the application.
- 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. Enter the API
server URL in KubeConfig as api_server_url. In this example, the source code repository branch is serverless, and the image
- Click Build.
- Click Build History to check the result. The following figure indicates that the build
- Log on to the to view the IP addresses of the services provided by the application.
Source code repository
The source code used in this topic can be found code repository.