How to manage Jenkins with Rancher on Ubuntu 14.04

Introduction

Effective continuous integration (CI) is a core requirement of any successful development team. Since CI is not a first-line service, it can usually run on the middle tier or redundant hardware. Adding builds for pull requests, automated deployments, acceptance testing, content uploads, and many other tasks can quickly overwhelm the resources of the build computer-especially when there is a lot of submission and deployment activity about to start.

In this article, we will use Docker to build a distributed build system to create and run our Jenkins images, and use Rancher to orchestrate our Docker cluster. Jenkins is one of the most famous open source CI solutions. Docker automatically deploys applications in software containers, and Rancher provides a complete platform for Docker management in production.

This article describes cloud-based Jenkins deployment. However, another method is to use the internal Jenkins master and [Cloud Server] (https://cloud.tencent.com/product/cvm?from=10680) to provide overflow capacity when more resources are needed. This is where Docker and Rancher really shine: Docker provides us with almost the same deployment environment, Rancher allows us to combine nodes from various cloud providers or internal servers into a cluster running on our own V** . At the end of this tutorial, you should be able to easily set up a Dockerized Jenkins deployment with any number of slaves.

prerequisites

This tutorial will use a total of three Tencent CVM: one for the Rancher server, one for the Rancher compute node running the Jenkins master server, and the other for the second Rancher compute node running the Jenkins slave server.

We will set these IP addresses for Tencent CVM to your_rancher_server_ip, your_jenkins_master_ip and your_jenkins_slave_ip; when you see these variables in this tutorial, please replace them with appropriate IP addresses.

Initially, we will create a Tencent CVM for the Rancher server; the creation of two computing nodes will be introduced later. Therefore, to start this tutorial, you will need:

You can find the Docker 1.5.0 image option in the "Application" tab under "Select Image" on the Tencent CVM creation page. This Tencent CVM also needs to customize user data. To add this, click **"**Enable User Data" in the "Available Settings" section, and enter the following script in the text box that appears. This script tells Tencent CVM to run the Rancher server at startup.

#! /bin/bash
docker run -d --name rancher-server -p 8080:8080 rancher/server

Step 1-Configure authentication

After creating the Rancher server, you will be able to access its UI through a browser pointing to http://your_rancher_server_ip:8080/ after a while. Since the Rancher server is open to the Internet, it is best to set up authentication. In this step, we will set up Github OAuth-based authentication, which is currently supported by Rancher.

You will see a warning in the upper right corner that says Access Control is not configured, followed by a link to "Settings". Click "Settings", then follow the instructions to register a new application with Github, and copy the "Client ID" and "Secret" into the corresponding text fields.

When finished, click Use Github for authentication, and then click Authorize Application in the pop-up window. After completion, the page will reload and the instructions for setting up OAuth will be replaced by the section "Configure Authorization". Add any other users and organizations that should be granted access to Rancher. If any changes are made, a button to read Save Authorized Configuration will be displayed. Click it when finished.

After saving the authorization configuration, the warning in the upper right corner should be replaced with your Github profile image and project selection menu (originally Default). Click "Default" to open the project selection menu, then click "Manage Project", and finally click "Create Project". Add a project called Jenkins, and then use the project selection menu again to select the Jenkins project.

This will help keep the Rancher interface clean and tidy by isolating the various projects you run on Rancher. If you want to run other services besides Jenkins on the same Rancher cluster, you can create other projects (other compute nodes are required). Also note that the default project is specific to the logged-in user, so if you plan to let multiple people access your Rancher agent, you should not use the default project.

Step 2-Register Rancher compute node

Now that the server and authentication are set up, we can register some compute nodes to run our Jenkins deployment.

Note: Before performing authentication, you can register a Rancher compute node without providing a registration token. However, since we have enabled authentication, all agents must provide a registration token to be added to the cluster.

In the Rancher UI, click Hosts (in the left menu), and then register a new host. Copy the Docker run command from the pop-up window, and then close the window. Back to the control panel, use the Docker 1.5.0 image to create two other Tencent CVMs, such as the Rancher server. If the build is resource-intensive, you may want to choose a larger instance for these two Tencent CVMs.

For the user data in these two Tencent CVMs, add #!/bin/bash and continue to add the previously copied Docker run command after it. It should look similar to this.

#! /bin/bash
sudo docker run -d --privileged
 - v /var/run/docker.sock:/var/run/docker.sock rancher/agent
 http://your_rancher_server_ip:8080/v1/scripts/A2DE06535002ECCAAFCD:1426622400000:iniUzPiTnjyFaXs9lCKauvoZOMQ

The last long string of numbers and letters will be different for your command. Before clicking Register New Host, make sure that the project is selected, because the token is unique for each project.

After a few minutes, you should be able to see two Rancher compute nodes in the Rancher UI. You will see the name of your Tencent CVM in the image below, which is RancherAgent in the image.

Step 3-Start Jenkins master node

We are now ready to start our Jenkins master node using the official Jenkins image.

To start the container, click "Add Container" under the compute node you want to use, and add the following options:

Next, click + next to "Port Mapping". Fill in 8080 in the two fields and keep TCP as the protocol. This will allow us to access the Jenkins Web UI. Click + again and add port 50000 in the two fields and leave TCP as the protocol. This allows the slave to connect to the master.

Next, click on "Advanced Options", and then click on the "Volumes" tab. Click the "+" next to "Volume", and then specify /var/jenkins_home in the text box that appears. Placing the Jenkins home directory in a volume allows you to preserve the configuration when you restart the container and allows you to use the volume backup container in other container features.

Finally, click "Create" to start the Jenkins container.

Step 4-Start Jenkins slave node

In this step, we will start the slave Jenkins.

Point your browser to http://your_jenkins_master_ip:8080 to load Jenkins UI.

In the Jenkins UI, create a node configuration by browsing Manage Jenkins on the left, then Manage Nodes in the next menu, and finally browsing New Node on the left side of the last page. In the next menu, enter your slave name in the text box next to Node Name (and remember it-we will need it again later), select Dumb Slave as Type and click OK.

You will be redirected to a page with detailed information about this node. For Remote Root Directory, type /var/jenkins. For Launch method, please select "Launch the slave agent via Java Web Start". You may also want to update the executor setting to be higher than its default value of 1 to increase the number of parallel builds allowed on the slave. The remaining settings can be left at their default values. Click "Save" to submit the subordinate configuration.

We are now ready to start our slave container. In the Rancher UI, click "Add Container" on the remaining compute nodes, and then add the following options:

Then click Advanced Options. You will start with the Command tab. Click Environment Vars next to + and add an entry with Name of MASTER_HOSTw and Value of your_jenkins_master_ip. Click + again and add another entry with the name **NODE and value as the name of the Jenkins subordinate, which is New in the Jenkins UI in the previous step Specified in the Node menu.

Next, click on the "volume" tab. Click the "+" next to "volume", and then specify /var/jenkins in the text box that appears.

Finally, click "Create".

The jenkins-slave container will download the jar file from the Jenkins master node and run the Jenkins slave node. When the slave node starts, you should be able to see its status after refreshing the Manage Node page, we stopped this in the Jenkins UI. You should see that your slave node has a response time value and there is no red X on the computer icon, as shown below.

in conclusion

In this article, we set up a Jenkins CI deployment using Docker and Rancher. Our Jenkins cluster is now ready for further configuration and build jobs.

Docker provides us with a consistent environment for running Jenkins, and Rancher provides a network between hosts, allowing us to manage the cluster from the Web UI without having to manually access the Droplet or configure the server. Using this tool set, we can quickly build system resources up and down. This is essential for maintaining an unobtrusive build system at critical moments such as release.


Reference: "How To Manage Jenkins with Rancher on Ubuntu 14.04"

Recommended Posts

How to manage Jenkins with Rancher on Ubuntu 14.04
How to install Jenkins on Ubuntu 16.04
How to install Jenkins on Ubuntu 20.04
How to install Jenkins on Ubuntu 18.04
How to install Prometheus with Docker on Ubuntu 14.04
How to play happily with Python3 on Ubuntu
How to use Jenkins to build automatically on Ubuntu
How to use LVM to manage storage devices on Ubuntu 18.04
How to start a blog with Hexo on Ubuntu 14.04
How to protect Apache with Let's Encrypt on Ubuntu 16.04
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
How to install Jenkins on CentOS 8
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install MemSQL on Ubuntu 14.04
How to install Go on Ubuntu 20.04
How to install MongoDB on Ubuntu 16.04
How to install Jenkins on CentOS 8
How to install PrestaShop on Ubuntu 16.04
How to upgrade to PHP 7 on Ubuntu 14.04
How to install Skype on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to deploy Django on Ubuntu 14.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to secure Nginx on Ubuntu 14.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04
How to install Go on Ubuntu 20.04
How to install Zoom on Ubuntu 20.04
How to uninstall software on Ubuntu
How to install Nginx on Ubuntu 16.04
How to install OpenCV on Ubuntu 20.04
How to install Spotify on Ubuntu 20.04
How to install Postman on Ubuntu 18.04
How to install Go 1.6 on Ubuntu 16.04
How to install Go on Ubuntu 18.04
How to install MySQL on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 20.04
How to install VLC on Ubuntu 18.04
How to install TeamViewer on Ubuntu 20.04
How to install Webmin on Ubuntu 20.04