This project demonstrates usage of Spring Boot and Postgresql with local Kubernetes deployment using Minikube and Docker.
Kubernetes has revolutionized the way we deploy, scale, and manage containerized applications. It provides a powerful and flexible platform for automating deployment, scaling, and management of containerized applications and services. There are several key motivations for using Kubernetes:
-
Container Orchestration: Allows us to orchestrate containers efficiently. It abstracts away the complexities of container deployment, networking, and scaling, making it easier to manage and maintain our applications.
-
Scalability and High Availability: Enables us to scale our applications horizontally to handle increased loads and ensure high availability by automatically managing replicas and distributing them across nodes.
-
Resource Utilization: Optimizes resource utilization by intelligently scheduling containers based on available resources, making efficient use of the underlying infrastructure.
-
Rolling Updates and Rollbacks: Allows us to perform rolling updates seamlessly, ensuring that our applications are always available during the update process. In case of issues, it also supports easy rollbacks to a previous stable version.
-
Declarative Configuration: With Kubernetes, we define the desired state of our applications using YAML files, making it easier to manage and version control configurations.
Minikube is a lightweight Kubernetes distribution designed to run locally for development and testing purposes. It is an excellent choice for developers who want to experiment with Kubernetes without the complexity of setting up a full-fledged cluster.
Installation steps can be found on this link: https://minikube.sigs.k8s.io/docs/start/
By combining Spring Boot, PostgreSQL, Kubernetes, and Minikube, we can build a robust and scalable application that can be easily deployed to production Kubernetes clusters while benefiting from the simplicity and convenience of local development using Minikube.
Before getting started with the project, please ensure you have the following installed on your machine:
- Java Development Kit (JDK) 17 or higher
- Docker / Docker Desktop (for containerization purposes)
- Minikube (for local Kubernetes development)
- kubectl (Kubernetes command-line tool)
All deployment specifications are located here. The folder contains the following specifications:
- postgres-secret.yaml: contains secrets using for connection to Postgres database (e.g. username and password). All secrets have to be base64 encoded.
- postres-init.yaml: contains initialization script for Postgres database (database creation)
- postgres-config.yaml:
- postgres.yaml: deployment and service configuration for Postgres DB
- web-app-config.yaml: contains configuration variables for Spring Boot application (e.g. Spring active profiles)
- web-app.yaml: deployment and service configuration for Spring Boot App
- web-ingress.yaml: external K8 integrated Load Balancer which responsibility is to route traffic to internal services
For running the apps on Kubernetes first make sure to start the Minikube local K8 cluster by executing the command:
minikube start
After starting the Minikube, using the kubectl
command you should apply the following configuration files:
- cd deployment/
- kubectl apply -f postgres-secret.yaml
- kubectl apply -f postgres-config.yaml
- kubectl apply -f postgres-init.yaml
- kubectl apply -f postgres.yaml
- cd ../
- docker build -t spring-app:1.0 .
- cd deployment/
- kubectl apply -f web-app-config.yaml
- kubectl apply -f web-app.yaml
For checking the status of your pods run the following command:
kubectl get all
Good luck!
If someone is interested in contribution or have some suggestions please contact me on email hedzaprog@gmail.com.
Heril Muratović
Software Engineer
Mobile: +38269657962
E-mail: hedzaprog@gmail.com
Skype: hedza06
Twitter: hedzakirk
LinkedIn: https://www.linkedin.com/in/heril-muratovi%C4%87-021097132/
StackOverflow: https://stackoverflow.com/users/4078505/heril-muratovic