Building microservices isn’t merely breaking up a monolithic software application into a collection of smaller services. When shifting to microservices, there are best practices developers must adopt. It becomes equally important to learn microservices development best practices, optimizing which languages to use, using an opinionated stack and pre-configured pipeline, and testing apps using continuous deployment. Hence, it’s also about automation and the method for developing software.
With too many services interacting with each other through APIs, it introduces complexity, which is generally considered to be the primary foe of good software. In a microservices architecture, an individual service concerns itself only with minimal responsibilities. If a single service develops a problem, it’s much easier to rewrite that single service than rewrite and merge-in a fix to the entire monolith. Hence, one needs to maintain the ever-growing release cycle which becomes more frequent as compared to the old monolithic architecture. To allow our DevOps teams to deploy and test their microservices directly over Cloud and multiple times per day, a robust continuous integration and delivery tool is required.
Today, DevOps is a set of practices which mainly focuses on reducing the time between committing a change to a system and the change being placed into normal production, while ensuring better quality. Teams should be able to deploy multiple times per day compared to the industry average that falls between once per week and once per month. The lead time for code to migrate from ‘code committed’ to ‘code in production’ should be less than one hour and the change failure rate should be less than 15%, compared to an average of between 31-45%. In nutshell, MTTR (mean time to repair) from a failure is expected to be less than one hour.
Jenkins is one such continuous integration and continuous delivery tool which can be used to automate building, testing, and deploying software. It is an open-source automation server that lets you flexibly orchestrate your build, test, and deployment pipelines. It has extensive community support, heavily Java-based codebase making it portable to all major platforms. It has a rich ecosystem of more than 1000 plugins (there’s even a Jenkins plugin for TestProject too 😎). Jenkins works well with all popular Source Control Management systems like Git, SVN, Mercurial and CVS. It works well with popular build tools like Ant, Maven & Grunt. Jenkins plugins provide support for technologies like Docker and Kubernetes, which enable the creation and deployment of cloud-based microservice environments, both for testing as well as production deployments.
Jenkins works perfectly well as a stand-alone open source tool, but with the shift to Cloud native and Kubernetes, it invites challenges in terms of management and operation. Recently, Jenkins X has emerged as a way to improve and automate continuous delivery pipelines to Kubernetes and cloud native environments. To achieve speed and agility, it is important to automate all the testing processes and configure them to run automatically over the Kubernetes cluster. To enhance the automation testing capabilities independently and within DevOps, TestProject comes to the rescue 🐱🏍
In this tutorial, we will discuss what is Jenkins X and review its architecture and benefits. We will also demonstrate how to set up Jenkins X on Google Cloud Platform and then integrate it with TestProject in a seamless manner.
Table of Contents
- Why Jenkins X?
- Compelling Features of Jenkins X
- Jenkins X Architecture
- Introducing JX CLI
- Jenkins X Prerequisites
- Installing JX
- Creating Kubernetes Cluster using JX
- Verifying Kubernetes Cluster
- Clone the Jenkins X Boot Configuration Repository
- Running JX Boot CLI
- Getting Jenkins X Environment
- Bringing up Jenkins X GUI
- Jenkins X Integration with TestProject
Jenkins X is a CI/CD solution for modern cloud applications on Kubernetes. It helps us create great pipelines for our projects and implement a full CI and CD. Jenkins X provides an automated CI/CD for your modern cloud applications on Kubernetes and enables developers to quickly establish continuous delivery best practices.
Container orchestration tools such as Kubernetes allow DevOps teams to manage these containers, leading to faster deployments and shorter time to market, while also satisfying heightened customer expectations and remaining competitive.
Jenkins X is not just a CI/CD tool to run your builds and deployments, it is an attempt to automate the whole development process end to end for containerized applications based on Docker and Kubernetes. It is obviously open source, as are all best applications. Jenkins X builds upon the DevOps model of loosely-coupled architectures. It is designed to support the deployment of large numbers of distributed microservices in a repeatable and manageable fashion, across multiple teams.
Today, developers shouldn’t spend time figuring out how to package software as docker images. They shouldn’t really create the Kubernetes YAML to run their application on Kubernetes, they even shouldn’t care about creating Preview environments or even learn how to implement CI/CD pipelines with declarative pipeline-as-code Jenkins files. They should focus on their code and hence, on delivering value! Jenkins X is a project which rethinks how developers should interact with CI/CD in the cloud with a focus on making development teams productive through automation, tooling and DevOps best practices. What’s cool about Jenkins X is as a developer you can type one command jx create or jx import and get your source code, git repository and application created, automatically built and deployed to Kubernetes on each Pull Request or git push with full CI/CD complete with Environments and Promotion via GitOps! 🤩
Jenkins X is designed to make it simple for developers to work according to DevOps principles and best practices. Rather than having to have deep knowledge of the internals of Jenkins X Pipeline, Jenkins X will default awesome pipelines for your projects that implement fully CI and CD. Below are the few compelling features of Jenkins X:
- Automated CI-CD Pipeline
- Environmental Promotion using GitOps
- Preview Environments
At the heart of the system is Kubernetes. Kubernetes hosts all services deployed by JX, including administrative ones (Jenkins, Chartmuseum, Monocular, etc). Let’s talk about each of these components which falls under architecture (Source ~ https://jenkins-x.io/about/#architecture):
- Git: Git stores all the code and configurations, including environment setup. Serves as a source of truth for everything. Jenkins X manages remote Git repositories and follows the GitOps principles.
- Helm: Deployment of the services (or applications) is coordinated via Helm. Helm’s Charts allow sharing of application templates and make versioning easy. Helm also takes care of upgrade and rollback cases, which makes it quite useful.
- Chartmuseum: It is basically a Helm Charts repository which helps to manage charts via Rest API.
- Monocular: It is a web-based UI to Helm Charts repository
- Nexus: Acts as a dependency cache for Node JS and Java applications to dramatically improve build times. After an initial build of a SpringBoot application, the build time is reduced from 12 mins to 4 mins.
- Docker Registry : An in cluster docker registry where our pipelines push application images.
jx is a command line tool for working with Jenkins X. It does all the magic of bringing all building blocks together and providing an entry point to a system management and orchestration. It is written in Go. The JX CLI is utilized by end users to manage resources (apps, environments, URLs, etc) as well as in Jenkins pipelines created by JX. Few of the notable commands include:
|$ jx install||Installs JX on Kubernetes Cluster|
|$ jx create||Creates JX resources and associated services like Kubernetes Namespace, Pods, Services, etc|
|$ jx boot||Boots up Jenkins X in a Kubernetes cluster using GitOps and a Jenkins X Pipeline|
|$ jx import||Imports a project code into JX|
|$ jx preview||Creates a temporary Preview Environment for an application|
|$ jx promote||Promotes an app’s version to a specific environment|
Jenkins X requires the following supported services installed & configured properly prior to installation:
- You will require GitHub as a GIT provider and GitHub user account.
- You need to create a GitHub organization. You will also need to create a GitHub bot account/username (In my case, I created it by name “collabnix-bot” over GitHub).
- Publicly accessible DockerHub account for creating and managing docker images.
- A local Desktop machine (Linux/Mac) with the jx program.
- The Kubernetes command-line tool, which can be installed to your local installation using the jx install command.
- A Google Cloud Platform (GCP) account with the ability to provision Kubernetes resources/create Kubernetes clusters with API Enabled as shown below.
First of all, let’s create a GitHub organization which will have two members, a GitHub user account, e.g. ajeetraina, and a GitHub ‘Pipeline’ bot account, e.g. collabnix-bot.
Creating GitHub Organization
- Click the “+” at the top right of GitHub’s top navigation bar or by clicking to the create an organization page. Choose free ‘Team for Open Source’ plan for GitHub organization. Name your organization anything you like, e.g. jenkins-x-testproject.
- It’s time to Invite your GitHub user account, e.g. ajeetraina to the organization.
- This GitHub user account will create and manage development repositories.
- Create a GitHub Pipeline bot account. This Pipeline bot will automate pull request notifications and create preview environments for quick validation and acceptance for code merging.
- Please note that your Pipeline bot should be created as a member of your GitHub organization, e.g. jenkins-x-testproject.
- I would suggest you create a new account that will be only for your bot.
- The bot account which you create must have a token created in your organization that authenticates the bot & allows it to perform various tasks on the repositories within your organization. You might need to generate a Git token for your Pipeline Bot with the correct permissions via this GitHub Link.
jx version --short
Installing JX Dependencies
jx install dependencies -d kubectl
Before you run the below command, ensure that you have a valid GCE account. Run the below `jx create cluster gke` CLI which allows you to create a cluster on Google Kubernetes Engine (GKE), which you can initialize with a name.
jx create cluster gke --skip-installation -n mytestproject
This command will take 10-15 minutes and goes through the below process:
- The program opens a web browser and you will be asked to choose the email address associated with your GCP account.
- It will allow the Google Cloud SDK access to your account. After confirming, you can close the browser page.
- Back at the command-line, the jx create cluster program prompts you to choose your Google Cloud Project from the available list.
You can visit GCP console and click on “Workload” to see all Jenkins X specific workloads up and running:
kubectl get nodes NAME STATUS ROLES AGE VERSION gke-mytestproject-default-pool-c87818e4-3vbd Ready <none> 50s v1.14.10-gke.36 gke-mytestproject-default-pool-c87818e4-551t Ready <none> 50s v1.14.10-gke.36 gke-mytestproject-default-pool-c87818e4-qg4b Ready <none> 50s v1.14.10-gke.36
Under this step, we will clone Jenkins X boot configuration repository. We will then open the jx-requirements.yml file of your newly cloned repo, eg. jenkins-x-boot-config/jx-requirements.yml. This specifies the requirements of your installation, including:
git clone https://github.com/jenkins-x/jenkins-x-boot-config
The ‘jx boot’ utility command allows you to boot up Jenkins X in a Kubernetes cluster using GitOps and a Jenkins X Pipeline. Jenkins X Boot uses the following approach:
Then you will be asked a series of questions to ensure Jenkins X is installed properly on your cluster:
|Questions||What to respond?|
|You will be asked to input the Git Owner name for environment repositories||Type in the organization you created: jenkins-x-testproject|
|You will be asked to provide Comma-separated git provider usernames of approvers for development environment repository||Type in the name of the GitHub account that is a member of the organization you created, e.g: ajeetraina|
|You may receive a Warning that TLS is not enabled so your webhooks will be called using HTTP. You will be asked for confirmation to continue.||If you type ‘No’, the jx boot process will end with error: cannot continue because TLS is not enabled. If you type ‘Yes’, then namespace jx will be created in your cluster and Jenkins X booted in that namespace.|
|You may be asked if you wish to upgrade jx.||It is recommended you say ‘Yes’ and then re-run jx boot.|
|There will be information logged on enabling storage on GKE.||You do not need to enable storage for this walkthrough tutorial.|
|You will be asked Jenkins X Admin Username||Type in a username or press return to have the default username of admin|
|You will then be asked for Jenkins X Admin Password||Type one in|
|You will then be asked for the Pipeline bot Git username: Type in the name of the Pipeline Bot you created, eg jx-bot.||Type in the name of the Pipeline Bot you created, e.g: collabnix-bot|
|You will then be asked for Pipeline bot Git email address||Type in the email address you used when setting up your Pipeline Bot.|
|You will then be asked for Pipeline bot Git token.||Type in the token generated and saved previously.|
|You will be asked, Do you want to configure an external Docker Registry?: ‘No’ is sufficient for this tutorial||‘No’ is sufficient for this tutorial. But if you say “yes” you might need to provide Docker Registry Details ( ie. DockerHub username and password)|
Then you will see confirmation on the state of your installation process, such as “Installation is currently looking: GOOD” message. In the organization you created, e.g: jenkins-x-testproject, there should now be 3 additional repositories for the dev, staging, and production environments, which map to the dev, staging, and production namespaces in your cluster.
verifying the Jenkins X installation in namespace jx verifying pods Checking pod statuses POD STATUS jenkins-x-chartmuseum-d87cbb789-h4kzz Running jenkins-x-controllerbuild-847f4f4b79-t6g64 Running jenkins-x-controllerrole-75d8d87d98-p5p2l Running jenkins-x-heapster-54bdffbc79-fwlds Running jenkins-x-nexus-b69b7745b-xnzrl Running jx-vault-mytestproject-0 Running jx-vault-mytestproject-configurer-5547f59f5b-d2vjk Running lighthouse-foghorn-dd76f6664-w9ql4 Running lighthouse-keeper-5f89b8b978-chkdp Running lighthouse-webhooks-5cdf4b9f65-6mchq Running lighthouse-webhooks-5cdf4b9f65-nqjvw Running tekton-pipelines-controller-88c7cd9d5-4hr7z Running vault-operator-75d5446bb7-mnj6h Running Verifying the git config Verifying username collabnix-bot at git server github at https://github.com Found 1 organisations in git server https://github.com: jenkins-x-testproject Validated pipeline user collabnix-bot on git server https://github.com
Congratulations! 🎉 Jenkins X should be installed on your Kubernetes cluster by now.
jx get environments NAME LABEL KIND PROMOTE NAMESPACE ORDER CLUSTER SOURCE REF PR dev Development Development Never jx 0 https://github.com/jenkins-x-testproject/environment-mytestproject-dev.git master staging Staging Permanent Auto jx-staging 100 https://github.com/jenkins-x-testproject/environment-mytestproject-staging.git master production Production Permanent Manual jx-production 200 https://github.com/jenkins-x-testproject/environment-mytestproject-production.git master [Captains-Bay]🚩 >
To use the GUI, you must install and configure it for your CloudBees Jenkins X Distribution environment. Ensure that you have the proper namespace set by running jx from the command line to switch to the jx namespace:
jx ns jx Using namespace 'jx' from context named 'gke_famous-hull-276807_us-east1-b_mytestproject' on server 'https://126.96.36.199'.
From a command-line, install the UI application by using the jx add app command. Please Note: If you have enabled GitOps mode in your CloudBees Jenkins X Distribution cluster, the jx add app command updates your development (dev) environment repository and automatically merges the UI app source code changes to your dev environment.
[Captains-Bay]🚩 > jx add app jx-app-ui --version 0.1.211 WARNING: No secrets found on "helm/repos" due: reading the secret "helm/repos" from vault: no secret "helm/repos" not found in vault Read credentials for http://chartmuseum.jenkins-x.io from vault helm/repos Preparing questions to configure jx-app-ui. If this is the first time you have installed the app, this may take a couple of minutes. Questions prepared. Checking if TLS is enabled in the cluster Created Pull Request: https://github.com/jenkins-x-testproject/environment-mytestproject-dev/pull/1 Added app via Pull Request https://github.com/jenkins-x-testproject/environment-mytestproject-dev/pull/1
kubectl get -n jx ingress jenkins-x-jxui
The ‘jx ui’ CLI opens the CloudBees Jenkins X UI app for Kubernetes for visualising CI/CD and your environments. Before running the above command, let us ensure that we are under “jx” namespace.
[Captains-Bay]🚩 > jx ui -p 8080 UI not configured to run with TLS - The UI will open in read-only mode with port-forwarding only for the current user Waiting for the UI to be ready on http://localhost:8080... Jenkins X UI: http://localhost:8080 Opening the UI in the browser...
Opening up Jenkins X UI
Let’s go ahead and test drive a new app from a Quickstart and import the generated code into Git and Jenkins for CI/CD.
Search for Python-http and click “Continue”:
You have to enter the GitHub Access token, organization name and name of the new repository which you want to create. Click “Finish” once you enter the details.
If you didn’t opt for GUI, you can perform the quickstart via CLI too as shown below:
jx create quickstart
We have come to the last section where we will see how Jenkins X can be integrated with TestProject.
To achieve speed and agility, it is important to automate all the testing processes and configure them to run automatically over the Kubernetes cluster. To enhance the automation testing capabilities independently and within DevOps, TestProject comes to the rescue! 🌟 A community-powered 100% free end-to-end test automation platform to simplify automation testing efforts for mobile and web applications. Under this section, we will set up Jenkins X on Google Cloud Platform and then integrate it with TestProject in a seamless manner.
- All you need is a TestProject account, that’s it! If you don’t already have one, you can sign up and open your free account here.
- Generate API keys through the console in the Integrations tab from the top bar.
- Click on Integration > API > Create API key as shown below:
- Click “Create” & enter a name. Clicking “Next” gives us the option to either allow access to all or particular projects. For now, we’ll go for unrestricted.
- Click “Finish”. Now you should be able to retrieve the key via the “Show Key” option. Copy the key, because we’ll need it at a later point in time.
Next, we need to create a Project name. You can click on “Add a new Project” as shown below:
For this example, I have created a project called “Kubezilla”. Once you create a project, then we will be required to create a new Job. Click on “Add Job” as shown below:
Follow the below steps to create a new Job:
Once you populate the details, click “Next”. Select the type of agent browser as shown below. I selected 2 of the browsers – Chrome and Firefox.
Once you click on “Create”, it will ask you to start recording. Click “Start”. For this example, I browsed through my website www.kubezilla.com.
Go to your terminal and run the below CLI:
Cloning the staging environment repository:
git clone https://github.com/$GIT_USER/environment-$CLUSTER_NAME-staging
Open up jenkins-x.yml file and add the below entry: https://github.com/jenkins-x-testproject/environment-mytestproject-staging
env: - name: DEPLOY_NAMESPACE value: jx-staging pipelineConfig: env: - name: DEPLOY_NAMESPACE value: jx-staging pipelines: release: postBuild: steps: - command: echo “Executing integration tests!” - command: sh python trigger-job.py ~
In order to trigger the TestProject job, I have added the below script “trigger-job.py” under the same repository. You can copy it from here.
Once you commit the changes by adding the right Job ID, Project ID, Agent ID & API Key, then it will trigger the job as shown below:
Click “Builds” section to watch the progress under Jenkins X UI:
You can visit TestProject UI –> Monitor to see the results of the last run as shown below:
Click on Reports under TestProject UI and browse through Kubezilla detailed test reports, as shown below:
You can also export the reports to a PDF file as seen below:
If you’re looking for a tool that can help you achieve CI/CD without any effort of assembling things together yourself, Jenkins X is the right tool for you. It doesn’t aim to replace Jenkins but builds on it with best of breed open source tools. You do not directly install Jenkins to use Jenkins X, as it is embedded for you as a pipeline engine as part of the installation for a team. It is a complete CI/CD process with a Jenkins pipeline that builds and packages project code for deployment to Kubernetes and access to pipelines for promoting projects to staging and production environments. And as seen in this tutorial , adding TestProject into the mix, will help you enhance the automation testing capabilities independently and within your DevOps pipeline effortlessly!
Go ahead and start exploring! 👀
Happy Testing 💪😃