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

Martin Hodges
5 min readNov 6, 2023

--

Part 2: Setting up the project for automated provisioning of Binary Lane infrastructure

This is part of a series of articles that creates a project to implement automated provisioning of cloud infrastructure in order to deploy a Spring Boot application to a Kubernetes cluster using CI/CD. In this part we set up out development machine for the project.

Follow from the start — Introduction

Setting up the project

Part 1 of this series provided an overview of the project and detailed some of the prerequisites. This article provides details of how to set up your development machine.

The instructions in this series of articles are given for an Apple Mac running the Ventura Operating System (OS). Instructions for other computers and OSs can be found using Google.

How you decide to set up your project is up to yourself. I prefre to keep all parts of the project under a single root folder, such as quick-queue-project.

1. GitHub

As a software developer, I am assuming you have git on your development machine. For this project, I am using version 2.41.0

You will require 3 Github repositories:

  • Quick-Queue-IaC
  • Quick-Queue-Application
  • Quick-Queue-Deployment

These can be private or public. You should create them as empty projects but you can include readme.md, .gitignore and licence files as you wish.

Clone each of the repositories into your project folder with (remember to replace anything between < > with your own details):

git clone git@github.com:<your github username>/<repo name>.git
cd <repo name>
git checkout -b main
nano README.md
git add .
git commit -m "Initial commit"
git push

Note that this uses an SSH rather than HTTPS connection. For this to work you need to copy your public SSH key (which you can find under ~/.ssh) to GitHub under Account -> Settings -> SSH and GPG Keys.

These repositories (repos) will be used as follows:

Quick-Queue-IaC

This repo is used to hold the Infrastructure as Code (IaC) configuration files that will create each Binary Lane VPS and then configure them.

Within this folder, we will create two subfolders:

  • terraform
  • ansible

Quick-Queue-Application

This repo holds the source code for your Spring Boot application. You can develop your own application or use the one I have built.

Quick-Queue-Deployment

This repo holds your application deployment manifest files for Kubernetes. The contents are automatically created by the CI/CD pipline. ArgoCD then picks up the changes and passes the manifest files to the Kubernetes API to allow the application to be deployed.

2. Homebrew

When it comes to installing non-Apple Store applications on a Mac, you should install and use Homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

This may take a while as it may install the Xcode utilities.

For this project, I am using version 4.1.12.

If you already have Homebrew installed, I recommend updating it with:

brew update

3. Docker

Docker is a lightweight virtualisation layer that allows you to build virtual machines as images and then to run these images in a Docker container.

Containers provides the virtual image access to resources on the host machine, via its existing Operating System, such as networking and file systems. A single host machine can run multiple containers.

Whilst Docker is not required on your development machine for the CI/CD pipeline, it is useful to have it to allow you to test the Docker images we will build.

Follow the official documentation for installing Docker locally.

Once you have installed it, you can test it with:

docker run hello-world

You should see a description printed out that confirms your installation was successful.

For this project, I am using version 24.0.2

4. Terraform

You will require Terraform by Hashicorp on your development machine to run the Terraform IaC configuration files.

Install by first configuring Homebrew with the Hashicorp tap (ie: packages) and then install Terraform with brew:

brew tap hashicorp/tap
brew install hashicorp/tap/terraform

Verify the install with:

terraform -version

For this project I am using version 1.5.5.

5. Ansible

Ansible will run your automation playbook files for configuring the infrastruture set up by Terraform.

brew install ansible
ansible --version

For this project, I am using version 2.15.3.

6. Gradle

For this project I am using Gradle as my package manager for the Quick Queue java application. The instructions and build scripts I am using reflect this. You may choose to use Maven but will need to make the necessary changes.

brew install gradle
gradle

For this project, I am using version 8.3

7. Java

The Quick Queue application I build as part of this project was created using Java 21

brew install openjdk
java --version

For this project, I am using version openjdk version “21” 2023–09–1.

API Keys

There are a number of API keys that are required. You need to keep these secret and should never add them to any file that you save to GitHub. You will, however, provide them to Github and to Kubernetes as secrets later in the series. If you create them now, store them in a safe place. If you lose any, you will need to recreate them.

GitHub

In order for the CI/CD pipeline to push changes to the Quick-Queue-Deployment repo, the GitHub Actions require permission. This is given via a GitHub Personal Access Token (PAT).

In the Quick-Queue-Deployment repo, go to Account -> Settings -> <> Developer Settings -> Personal access tokens -> Fine -grained tokens -> Generate new token.

Create a token named Access for Quick Queue CI/CD and give it the following access rights to the Quick-Queue-Deployment repo only (under Repository Permissions):

  • Contents: Read and write
  • Secrets: Read only
  • Variables: Read only
  • Default values for all other values

Generate the token and record the result (you will not be able see this again afterwards).

Repeat the process for ArgoCD to access the repo. Name this token Access for Quick Queue ArgoCD and set the following for only the Quick-Queue-Deployment repo:

  • Contents: Read only
  • Default values for all other values

Docker Hub

You will need to create a Docker Hub repository called quick-queue-application. You may choose to create a private or public repo. A private repo may attract fees.

You can then create an access token under Account -> Account Settings -> Security -> New Access Token. Name it Quick Queue CI/CD Access and give it Read & Write access rights and then click Generate.

Summary

In this article we have set up the initial development machine environment I have used with this project. If you have any problems, check the versions you are using.

In addition to the local setup, we have also created the three Github repos that we will need to manage the configuration and source code for the Quick Queue project.

Once our development machine is set up, we are ready to start creating our cloud environment.

Series Introduction

Previous — Introduction

Next — Automatic creation of the Cloud Infrastructure

--

--