Installing and Deploying Jenkins

Selecting an Image

Select a functionally stable image on Docker Hub.

In this test, the image jenkinszh/jenkins-k8s:2.239 is used.

Preparations

  • Before creating a containerized workload, you need to buy a cluster (the cluster must contain at least one node with four vCPUs and 8 GB memory). For details, see Buying a CCE Cluster.
  • To enable access to a workload from a public network, ensure that an elastic IP address (EIP) has been bound to or a load balancer has been configured for at least one node in the cluster.

Installing and Deploying Jenkins on CCE

  1. Log in to the CCE console, choose Workloads > Deployments in the navigation pane, and click Create Deployment on the right.
  2. On the Specify Basic Info page, set the workload name to jenkins (which can be set as required), set the number of pods to 1, and click Next: Add Container.
  3. Click Add Container.
  4. In the displayed Select Container Image dialog box, click Third-Party Images, set Image Address to jenkinszh/jenkins-k8s:2.239, retain the default values for other parameters, and click OK.

    Figure 1 Selecting a third-party image

  5. Set Container Resources. In this example, set CPU Limit to 2 cores and Memory Limit to 2048 MiB.

    Figure 2 Setting container specifications

  6. Click Data Storage and then Cloud Volume tab. Click Add Cloud Volume, select a cloud storage volume (EVS or SFS). If no cloud storage is available, click the link next to the volume name box to create one. Set Container Path to /var/jenkins_home to mount the volume to the /var/jenkins_home directory of the Jenkins container so that Jenkins can retain persistent data.

    Figure 3 Adding a cloud volume

  7. Assign permissions to the Jenkins container so that the Docker commands can be run in the Jenkins container for interconnection with SWR.

    1. Enable Privileged Container in Basic Information.
      Figure 4 Enabling Privileged Container
    2. Choose Data Storage > Local Volume, click Add Local Volume, and mount the host paths /var/run/docker.sock and /usr/bin/docker to the corresponding container paths. Then, mount the host path /usr/lib64/libltdl.so.7 to the container path /usr/lib/x86_64-linux-gnu/libltdl.so.7.
      Figure 5 Mounting the host paths to the corresponding container paths
    3. In Security Context, set User ID to 0 (user root).
      Figure 6 Configuring the user

  8. Click Next: Set Application Access. Then, click Add Service and configure the workload access.

    Select LoadBalancer or NodePort for Access Type. In this example, select LoadBalancer.

    The Jenkins container image has two ports: 8080 and 50000. You need to configure them separately.

    • Port 8080 is used for web login. The Service name is jenkins (which can be changed as required), the container port is 8080, and the access port is 8080. Retain the default values for other parameters.
    • Port 50000 is used for the connection between the master and slave nodes. The Service name is slave (which can be changed as required), the container port is 50000, and the access port is 50000. Retain the default values for other parameters.
    Figure 7 Adding a Service

  9. Click Next: Configure Advanced Settings. Retain the default settings and click Create.
  10. Click Back to Deployment List to view the Deployment status. If the workload is in Running state, the Jenkins application can be accessed.

    Figure 8 Viewing the workload status

Logging In and Initializing Jenkins

  1. Log in to the CCE console. In the navigation pane, choose Resource Management > Network. On the Services tab page, select the mode for Jenkins to access port 8080.

    Figure 9 Access mode corresponding to port 8080

  2. Click the IP address in the Access Address column to open the Jenkins configuration page.

    When you visit the page for the first time, you are prompted to obtain the initial administrator password. You can obtain the password from the pod, as shown in the following figure.

    # kubectl get pod
    NAME                                     READY   STATUS    RESTARTS   AGE
    jenkins-7c69b6947c-5gvlm                 1/1     Running   0          17m
    # kubectl exec jenkins-7c69b6947c-5gvlm -it -- /bin/sh
    # cat /var/jenkins_home/secrets/initialAdminPassword
    
    b10eabe29a9f427c9b54c01a9c3383ae

  3. Select the recommended plug-ins.

    Figure 10 Installing plug-ins

  4. Create an administrator.

    Figure 11 Creating an administrator

  5. Configure the instance.

    Figure 12 Configuring the instance
    Figure 13 Configuration completed