Skip to main content

Command Palette

Search for a command to run...

Deploying a Spring Boot App to a Kubernetes Cluster

Published
3 min read
Deploying a Spring Boot App to a Kubernetes Cluster

The GitHub repository JbravoI/Spring-Boot-Application offers a comprehensive template for building and deploying a Java-based web application using Spring Boot. It integrates essential tools and configurations to streamline development and deployment processes.

🚀 Project Overview

This repository is structured to facilitate rapid development and deployment of Spring Boot applications. It includes configurations for containerization, continuous integration, and deployment orchestration

🗂️ Project Structure

The repository is organized as follow:

.github/workflows/: Contains GitHub Actions workflows for CI/CD automatio. .mvn/wrapper/: Includes Maven Wrapper files for consistent build environment. k8s/: Houses Kubernetes deployment manifests for orchestrating application deploymen.src/: Contains the main application source cod. dockerfile: Defines the Docker image build instruction. deployment.yaml: Specifies Kubernetes deployment configuration. pom.xml: Maven Project Object Model file managing project dependencies and build configuration.

⚙️ Key Features

1. Spring Boot Integration

The application leverages Spring Boot’s capabilities for rapid developmen. By using the @SpringBootApplication annotation, it simplifies configuration and component scanning, allowing developers to focus on business logic.

2. Containerization with Docker

A dockerfile is provided to containerize the application, enabling consistent environments across development, testing, and productio. This facilitates easy deployment and scalabilit.

3. Continuous Integration with GitHub Actions

The .github/workflows/ directory contains workflows that automate the build and deployment processe. This ensures that code changes are automatically tested and deployed, enhancing development efficiency

4. Deployment with Kubernetes

Kubernetes manifests in the k8s/ directory define the application's deployment configuration. This allows for scalable and manageable deployments in a Kubernetes cluste.

🛠️ Getting Started

To set up and run the application:

Clone the Repository:

  • git clone https://github.com/JbravoI/Spring-Boot-Application.git cd Spring-Boot-Application

Build the Application:./mvnw clean install

Run the Application:./mvnw spring-boot:run

Access the Application:

Navigate to http://localhost:8080 in your web browser to interact with the application.

📦 Deployment

Docker Deployment / File

To build and run the Docker contaier: Docker File

Creating AKS Cluster & ACR using terraform (IaC).

​The GitHub repository JbravoI/k8s-CR-CI provides a practical example of setting up Azure Kubernetes Service (AKS) and Azure Container Registry (ACR) for continuous integration and deployment using terraform. This guide focuses on creating and configuring AKS and ACR, omitting the container instance section.​

🛠️ Prerequisites

Before proceeding, ensure you have:

Ensure your AKS cluster is integrated to ACR using this CLI

# Attach using acr-name
az aks update - name myAKSCluster - resource-group myResourceGroup - attach-acr <acr-name>

# Attach using acr-resource-id
az aks update - name myAKSCluster - resource-group myResourceGroup - attach-acr <acr-resource-id>

Using CI/CD pipeline via GitHub Actions

You can use the Yaml file here : Yaml-Pipeline

Ensure the following varibles are configured accurately

secrets.AZURE_ACR_NAME
secrets.username
secrets.password
secrets.AZURE_RESOURCE_GROUP
secrets.AZURE_AKS_CLUSTER

Configure Ingress-Controller :

INGRESS-CONTROLLER -NGINX DEPLOYMENT ON AZURE KUBERNETES SERVICES

Note you can also use Helm to install if you have it installed (you don’t need to run this if you have already…

ammarsuhail155.medium.com

After ingress configuration, run :

kubectl expose deployment <deployment name>
kubectl get ing
kubectl edit ing <ingress name>

Input the name of the service/deployment, save & close.
Sample :

      - backend:
          service:
            name: service-name
            port:
              number: 80
        path: /service-name(/|$)(.*)
        pathType: PrefixB

Browse the AKS Public FQDN

And EXTERNAL_IP/hello-world-two: (EXTERNAL_IP/service-name)

You can read more on the spring-boot process via : Sprint Boot App