DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Jenkins in the Age of Kubernetes: Strengths, Weaknesses, and Its Future in CI/CD
  • Fast Deployments of Microservices Using Ansible and Kubernetes
  • An Overview of Popular Open-Source Kubernetes Tools
  • MSA as a Project

Trending

  • Java Virtual Threads and Scaling
  • Evolution of Cloud Services for MCP/A2A Protocols in AI Agents
  • A Complete Guide to Modern AI Developer Tools
  • How the Go Runtime Preempts Goroutines for Efficient Concurrency
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Hands-On CI/CD for Microservices With Jenkins X

Hands-On CI/CD for Microservices With Jenkins X

DevOps and microservices come together in this tutorial on using Jenkins X to create a distributed, decoupled CI/CD system.

By 
Sergio Martin user avatar
Sergio Martin
·
Jul. 25, 18 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
22.1K Views

Join the DZone community and get the full member experience.

Join For Free

Kubernetes is growing in popularity and many companies use it to orchestrate their containerized microservices. Moreover, microservices are increasing the release cycle, because you do not have to build and deploy a huge monolith application every time a small change is made, therefore DevOps teams should be able to deploy multiple times per day. However, the continuous integration and delivery process is becoming a bottleneck, because at the end of the development process, code changes will trigger a pipeline in a CI tool, and this tool is usually shared by all your microservices. So, what can we do? The answer is Jenkins X:

jenkinsxJenkins X allows you to create a distributed and decoupled CI/CD system.

Setting Up a Cluster

To create a Kubernetes cluster with Jenkins X, there are a few alternatives. You can use Minikube, AWS, Azure, Oracle, OpenShift or Google Cloud, but for simplicity, GCP will be chosen for this example.

Prerequisites

  • Install jx tool
  • Create Google Cloud Account
  • Create a project on Google Cloud
  • Install Git, gcloud and kubectl

Getting Started

Login into your Google Cloud Account:

gcloud auth login

Create a cluster:

jx create cluster gke --skip-login --default-admin-password=mypassword -n jenkinsx-demo

--default-admin-password sets the password to access Jenkins with the admin user; -n sets the Kubernetes cluster name.

Follow the prompts on the console: select your Google Cloud project (my-jenkinsx-demo), Google Cloud zone (in this case, europe-west2-a), machine type (n1-standard-2),  minimum number of nodes (3 by default), maximum number of nodes (3), install ingress controller, set domain (choose default), set GitHub username, and recreate Jenkins X cloud environment.

After the process is done, two new repositories will be created on your GitHub account, and the Kubernetes context will be switched to the Jenkins X one.

kubectl config get-contexts
CURRENT   NAME                                                CLUSTER                                             AUTHINFO                                            NAMESPACE
*         gke_my-jenkinsx-demo_europe-west2-a_jenkinsx-demo   gke_my-jenkinsx-demo_europe-west2-a_jenkinsx-demo   gke_my-jenkinsx-demo_europe-west2-a_jenkinsx-demo   jx

Now you are ready to create your microservices and deploy them on your new Kubernetes cluster!

Deploying Microservices

There are three alternatives to create your microservice and deploy it:

  • Create your microservice manually and then import it using jx import.
  • Use the jx create Spring command which provides an easy way to create a microservice with Spring Boot from your terminal. Dependencies can be specified by including the -d argument followed by the dependency you want to add, e.g.  jx create spring -d web -d actuator .
  • Use jx create quickstart which allows you to select one of the templates provided by Jenkins X.

What happens when you use jx tool?

  • Creates an application in a directory.
  • Initializes the repository and pushes code to GitHub.
  • Adds Dockerfile (to create container) and Jenkinsfile (to create pipeline).
  • Creates a Helm chart to deploy on Kubernetes
  • Registers webhook on your git repository for your teams jenkins
  • Triggers the pipeline for the first time

For this example, Golang will be used with the quickstart tool provided by Jenkins X. 

jx create quickstart -l Go

The -l argument allows us to filter by language.

*The only available template for Golang at the moment is golang-http.

After following all the steps and the pipeline runs, the Go application will be deployed on the staging namespace (jx-staging).

Jenkins Dashboard
Screenshot from 2018-07-21 20-59-08

Kubernetes specifications include an ingress for the microservice, so you will be able to hit it from outside the cluster.

Kubernetes Dashboard

The URL to hit the service can be found by running the following command:

jx get app
APPLICATION               STAGING PODS URL                                                               PRODUCTION PODS URL
golang-http               0.0.1   1/1  http://golang-http.jx-staging.your-google-cloud-ip.nip.io


Screenshot from 2018-07-21 21-09-17

The application was only deployed on the staging environment and now it is time to promote it to production.

jx promote golang-http --version 0.0.1 --env production

*Make sure that the version match with the one in staging, otherwise the promotion pipeline will fail.

The previous command will open a pull request on the production repository, and only when the changes are merged, the production pipeline on Jenkins will be triggered. If everything goes well, the application should be deployed on your jx-production namespace, and the production URL will be available.

APPLICATION               STAGING PODS URL                                                               PRODUCTION PODS URL
golang-http               0.0.1   1/1  http://golang-http.jx-staging.your-google-cloud-ip.nip.io               0.0.1      1/1  http://golang-http.jx-production.your-google-cloud-ip.nip.io

Congratulations! You have just deployed your first application on Kubernetes with Jenkins X!

As you can see, Jenkins X will take care of your microservices deployment pipeline and will save you the time of creating pipelines for each microservice.

Troubleshooting

Depending on your jx version you might come across a Helm error like this:

'Error: UPGRADE FAILED: incompatible versions client[v2.10.0-rc.1] server[v2.9.1]
': exit status 1

This happens because Helm is not back compatible and Jenkins X might have installed an old version. This can be solved by installing the latest Helm version on your local machine. 

helm init --upgrade


Continuous Integration/Deployment microservice Jenkins (software) Kubernetes

Published at DZone with permission of Sergio Martin. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Jenkins in the Age of Kubernetes: Strengths, Weaknesses, and Its Future in CI/CD
  • Fast Deployments of Microservices Using Ansible and Kubernetes
  • An Overview of Popular Open-Source Kubernetes Tools
  • MSA as a Project

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: