Spring Boot CI/CD on Kubernetes using Terraform, Ansible and GitHub: Part 1

Martin Hodges
5 min readNov 6, 2023

--

Introduction to creating a CI/CD pipeline on Kubernetes in the cloud

This series of articles I take you on a journey to create a Spring Boot application that runs on a Kubernetes cluster. I start by creating the cloud servers you need using Infrastructure as Code tools such as Terraform and Ansible and then build up the layers to complete a CI/CD pipeline, including GitHub and ArgoCD.

Introduction to the series

In the many years I have been leading software development teams, there is one thing I have noticed:

Software developers never do something more than once. If they have to do it a second time — they automate it!

And so it was when I came to build another Kubernetes cluster. I wanted to automate as much as I could so I could set up and tear down clusters quickly and easily. I decided that I would document my journey for you to follow.

This is not for total beginners.

I have written it for software developers that have at least basic experience with Linux, Java, PostgreSQL, Spring Boot and Git but who may not be familiar with some of the other technology I have mentioned above.

Series Structure

The series is structured as a set of articles, each focussing on a different part of the overall project.

  1. How it all works (this article)
  2. Setting up the project
  3. Automatic set up of cloud infrastructure using Terraform
  4. Configuring servers using Ansible
  5. Creating a Kubernetes cluster
  6. Creating a Persistent Volume and connecting it to a postgreSQL database
  7. Creating a Spring Boot Application to add to your cluster
  8. Adding a Spring Boot Application to your cluster
  9. Setting up a Kubernetes Service for your application
  10. Building your Continuous Integration (CI) pipeline
  11. Building your Continuous Deployment (CD) pipeline
  12. Using ArgoCD for deploying your application
  13. Epilogue — where to from here

I have created the series in a way that I hope you find builds your knowledge, understanding and experience at a rate you can take in but not so slow as to be boring!

Of course, all the code you see is available on GitHub, although you still need your own GitHub repositories for your deployment. I have used different branches of my GitHub repositories to align to the article you are reading. This ensures that you do not get confused by content made for later articles.

Note:

This series of articles uses services that may incur costs. Whilst the project used here is designed to keep those costs low, you are solely responsible for the costs incurred, regardless of the reason for those costs. You may chose alternative suppliers but you will need to adapt the solutions. Such adaptations may not be possible, may not work and/or may incur additional costs. The author is not affiliated to any paid service suggested in these articles.

How it works

By following this series of articles, you will create infrastructure in the cloud and implement a fully functional Spring Boot application deployed through a Continuous Integration/Continuous Deployment pipeline (CI/CD) into a Kubernetes cluster.

The structure of the project is shown below:

On your development machine you will use:

  • Terraform to create the three Virtual Private Servers (VPS) in the cloud
  • Ansible to configure each VPS with the packages and upgrades it needs to form a Kubernetes cluster
  • Git to manage versions of your Infrastructure as Code (IaC), your Spring application and your CI/CD pipeline

Once you have created and configured each VPS, you will then be ready to install Kubernetes, which provides a virtual layer over the three nodes you have created. Within Kubernetes you will then install:

  • Helm as the package manager for Kubernetes
  • ArgoCD to deploy the Kubernetes manifest files and resources that then deploy your application
  • A Persistent Volume for saving files as a permanent file system
  • A PostgreSQL database for your application’s persistent storage
  • Your Spring Boot application (see Quick Queue below)

Supporting your CI/CD pipeline are GitHub and Docker Hub.

  • GitHub provides code repositories to store different versions of your infrastructure, application and deployment source code as well as providing GitHub Actions that manage the CI/CD pipeline
  • Docker Hub provides Docker image repositories to store the compiled and built versions of your application for Kubernetes to download and run

Quick Queue Spring Boot Application

In This series I use a project called Quick Queue. It is a simple REST based Spring Boot Java service that allows a client application to:

  1. Create a queue
  2. Register with that queue
  3. Determine where it is in the queue
  4. Deregister from the queue
  5. Delete the queue

It stores the queues and registrations within a postgreSQL database. The application also provides health point monitoring via another, internal REST API.

You can, of course, use your own Spring Boot Application with the appropriate changes.

Prerequisites

To follow this series of articles, there are a set of prerequisites that you will need. Some services attract fees.

  • Java development environment (eg: Eclipse or IntelliJ)
  • Binary Lane account
  • GitHub account
  • Docker Hub account

Binary Lane

Binary Lane is an Australian cloud service provider. I have been using them as my cloud service provider for a number of years and have found their services reliable and their support desk responsive.

They are a ‘no frills’ provider unlike the bigger players in the market, such as AWS, Azure and Google Cloud. This lowers your costs and has the benefit that the solutions you create are largely transferable to most cloud providers.

Binary Lane does not allow you to sign up without purchasing a service and there is no free service tier.

To follow this this series of articles, you will need a Binary Lane service so when you sign up, purchase the lowest tier VPS and then, once you have created your Kubernetes nodes, you can delete this initial server.

At the time of writing, Binary Lane is redeveloping their user interface. Once you have logged in to your account, I suggest you use the new interface, which you can find here: Australian VPS Hosting — Virtual Servers made easy. | BinaryLane Australia.

Although this series has been developed around Binary Lane services, you may be able to adapt the solution to other cloud providers.

GitHub

I use GitHub as my cloud-based code management solution. It integrates well with the git command line tools and now provides GitHub Actions that can drive your continuous integration and development pipeline (CI/CD).

If you want your work to be private, the GitHub services attract a fee.

This series has been developed around GitHub services. You may adapt the solution to other code repository provides, such as GitLab, if you wish.

Docker Hub

Docker Hub is one of the most well known Docker image repositories. This is an essential part of your CD pipeline.

Like GitHub, if you want your repositories to be private, the Docker Hub services attract a fee.

Summary

This article introduces the Quick Queue project that we will use to automatically deploy virtual servers, configure them, add Kubernetes and create a CI/CD pipeline to deploy the Quick Queue Spring Boot application.

Next Up — Setting up the project

--

--