How to Install Jenkins on Openshift
Hello everyone, this is the second part of our tutorial about how to integrate Red Hat Single Sign-On with Jenkins, this part is specific to the installation of Jenkins on Red Hat Openshift. Let’s go!
What is Jenkins?
Jenkins is an open-source automation tool written in Java with plugins built for Continuous Integration purpose. Jenkins is used to building and test your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. it also allows you to continuously deliver your software by integrating with a large number of testing and deployment technologies.
What is Continuous Integration?
Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is verified by an automated build, allowing teams to detect problems early.
With CI, you can detect errors more quickly, and solve them to improve the quality of software constantly.
What is Continuous Delivery?
Continuous Delivery is the ability to get changes of all types, including new features, configuration changes, bug fix corrections and experiments into production, or into the hands of users, safely and quickly in a sustainable way, continuous delivery needs the human interactions to accept the changes and apply to the production environment.
What is Continuous Deployment?
Is very similar to Continuous Delivery, but the Continuous Deployment eliminates the human interactions against unproven conde in live software. It should only be implemented when the development and IT teams rigorously adhere to production-ready development practices and through testing, and when they apply sophisticated, real-time monitoring in production to discover any issues with new releases.
The Continuous Deployment is more hard to apply because the company needs of sophisticated automated process in your software.
Why use Jenkins on Openshift?
With Jenkins, organizations can accelerate the software development process through automation. Jenkins integrates development life-cycle process of all kinds, including build, document, test, package, stage, deploy, static analysis. In Openshift we have Jenkins Slaves to Java and DotNet Core applications, the Jenkins Slave has the ability to Scale Up and Scale Down automatically, to improving the consuming of the cluster hardware.
For example, each pipeline started in Jenkins Master, start a Jenkins Slave to execute the process and when finished, the Jenkins Slave Down.
How to Install Jenkins On Openshift
Now we know a little more about Jenkins, we can install into Openshift.
1. Run the following command to create your project
$ oc new-project jenkins \
--description=' This project provide the automated tool to build, test and deploy applications.'
2. A point very important in Openshift is to create Resource Quotas and Limits for your projects to avoid that the application consumes more than of desire. The following commands apply Quotas e Limits for the project:
The following command will create a Resource Quota to the project jenkins:
$ oc create quota jenkins-quota \
--hard=cpu=2,memory=3G,pods=10,services=5,replicationcontrollers=2,resourcequotas=1
The following command will create a Limits to the project jenkins. Note in the command is send a file to execute through the command oc using the shell command echo
.
The limits apply rules for the container and for the pods into the project
jenkins
.
$ echo "apiVersion: "v1"
kind: "LimitRange"
metadata:
name: "jenkins-limits"
spec:
limits:
- type: "Pod"
max:
cpu: "1"
memory: "1Gi"
min:
cpu: "700m"
memory: "512Mi"
- type: "Container"
max:
cpu: "1"
memory: "1Gi"
min:
cpu: "700m"
memory: "512Mi"
default:
cpu: "700m"
memory: "512Mi"
defaultRequest:
cpu: "700m"
memory: "512Mi" " | oc -n jenkins create -f -
3. Run the following command to update the template of Jenkins into Openshift:
$ oc -n openshift \
create -f https://raw.githubusercontent.com/lhsribas/openshift-templates/master/openshift3/jenkins/jenkins-persistent-template.yaml
4. Whether you have the official installation of Openshift, can execute the following command:
This command installs the
ImageStream definition for Jenkins
of Jenkins into the project Openshift!
$ oc -n openshift create -f \
https://raw.githubusercontent.com/lhsribas/openshift-templates/master/openshift3/jenkins/image-stream/v3.11/jenkins-image-stream.yaml
The previous command import the ImageStream with the authenticated repository
, If you using the OKD
, needs the unauthenticated repository
execute the following command to get it:
$ oc -n openshift create -f \
https://raw.githubusercontent.com/lhsribas/openshift-templates/master/openshift3/jenkins/image-stream/v3.11/unauthenticated-jenkins-image-stream.yaml
5. To import the image into the project openshift
, execute the following command:
$ oc -n openshift import-image jenkins-openshift:v3.11 --confirm
6. The next step is to install Jenkins into the project Jenkins
, execute the following command:
$ oc -n openshift new-app --template=jenkins-persistent
To access the Jenkins you can use the same username and password of the Openshift, for example, user: admin, pwd: admin in OKD.
Below, we have the parameters that the template accept to execute the deploy of Jenkins into of project Jenkins
.
Each parameter has a basic value to start the template without need pass some parameter.
- JENKINS_SERVICE_NAME: The name of the OpenShift Service exposed for the Jenkins container.
- JNLP_SERVICE_NAME: The name of the service used for master/slave communication.
- ENABLE_OAUTH: Whether to enable OAuth OpenShift integration. If false, the static account ‘admin’ will be initialized with the password ‘password’.
- VOLUME_CAPACITY: Volume space available for data, e.g. 512Mi, 2Gi.
- NAMESPACE: The OpenShift Namespace where the Jenkins ImageStream resides.
- DISABLE_ADMINISTRATIVE_MONITORS: Whether to perform memory intensive, possibly slow, synchronization with the Jenkins Update Center on start. If true, the Jenkins core update monitor and site warnings monitor are disabled.
- JENKINS_IMAGE_STREAM_TAG: Name of the ImageStreamTag to be used for the Jenkins image.
- ENABLE_FATAL_ERROR_LOG_FILE: When a fatal error occurs, an error log is created with information and the state obtained at the time of the fatal error.
- CPU_REQUEST: The amount of CPU to request.
- MEMORY_REQUEST: The amount of memory required for the container to run.
- CPU_LIMIT: The amount of CPU the container is limited to use.
- MEMORY_LIMIT: Maximum amount of memory the container can use.
- TZ: The Time Zone of Country
7. Jenkins pod run’s into Openshift.
8. Redirect Login Page with Openshift
When you click in the hostname of Jenkins, you redirect to the page below.
9. Login Page Openshift.
After you click on the button
Login with Openshift
, you are sent to the page login of Openshift.
10. Authorization Page for Jenkins.
When you pass the username and password correct, you are sent to a page to request authorization to access the Jenkins Application.
11. Jenkins Home Page.
After all pass you redirect to the home page of Jenkins, finish now you can start to use the tool.