All Products
Search
Document Center

Container Service for Kubernetes:Deploy Jenkins in an ACK cluster and then create and deploy an application

Last Updated:Mar 15, 2024

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

Precautions

No technical support is provided for Jenkins. The developers who use Jenkins need to maintain Jenkins.

Step 1: Deploy Jenkins

  1. Run the following command to configure Jenkins Helm Repo:

    helm repo add jenkins https://charts.jenkins.io
    helm repo update

    Expected 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!⎈
    Note

    The preceding repository is a Halm chart repository deployed outside the Chinese mainland. Therefore, the configuration may be time-consuming if you configure the repository from an ACK cluster deployed in the Chinese mainland.

  2. Install Jenkins.

    1. Run the following command to create a namespace named cicd:

      kubectl create ns cicd
    2. Run the following command to deploy Jenkins in the cicd namespace:

      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.adminPassword="admin": The default password is randomly generated. This parameter is optional. For more information about how to obtain the randomly generated default password, see Use a load balancer to access the Jenkins Service and obtain the randomly generated default password.

      For more information about other parameters, see helm-charts.

    3. 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 po

      Expected output:

      NAME        READY   STATUS    RESTARTS   AGE
      jenkins-0   2/2     Running   0          3m3s
  3. Use a web browser to access Jenkins and enter your username and password.

Step 2: Create a pipeline build

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.

  1. Log on to Jenkins. In the left-side navigation pane, click New Item.

  2. In the Enter an item name section, enter first-pipeline, select Pipeline, and then click OK.

  3. On the top of the page, click the Pipeline tab, select the Hello World template, and then click Save.

    pipeline

  4. In the left-side navigation pane, click Build Now to run the build.

  5. 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.

Use a load balancer to access the Jenkins Service and obtain the randomly generated default password

  • The default type of the Jenkins Service is ClusterIP. If you want to use a load balancer to expose the Jenkins Service, run the following command:

    kubectl -n cicd patch svc jenkins -p '{"spec": {"type": "LoadBalancer"}}'
  • If 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