Source Code : https://github.com/pradz13/K8S/tree/main/SpringBootCrudRest
K8S Scripts :
https://github.com/pradz13/K8S/tree/main/SpringBootCrudRest-scripts
Following are the steps to deploy Spring Boot Crud Application with MySQL Database in K8S Minikube cluster :
Create a Spring Boot Crud project with MySQL DB and test it locally.
Create the DB Deployment YML file. Please refer - https://github.com/pradz13/K8S/blob/main/SpringBootCrudRest-scripts/db-deployment.yaml
Persistent Volume Claim is created for providing storage space for the database. Deployment and Service concepts we have already discussed in the previous tutorial.
Start the Minikube - minikube start
Check Minikube status - minikube status
Allow Kubernetes to read our local Docker repository - eval $(minikube docker-env)
Deploy the MySQL Deployment created above in Minikube with the command - kubectl apply -f db-deployment.yaml
Get the MySQL running POD with the command - kubectl get pods
Connect to the Node inside the cluster using the following command - kubectl exec -it bash
Then use the following command to connect to MySQL Server : mysql -h mysql -u root -p
Use the command to see all databases :
show databases;
It should have created a database mentioned in our db-deployment.yaml file(mysql in this example). Change the database with the following command :
use database_name;
Build the Docker image of the Spring Boot application :
docker build -t springbootcrudrest:1.0 .
Check if the image has been build or not with the command : docker images
Write the Deployment and Service for Spring Boot application -
https://github.com/pradz13/K8S/blob/main/SpringBootCrudRest-scripts/app-deployment.yaml
Deploy the Spring Boot Deployment created in Minikube with the command - kubectl apply -f app-deployment.yaml
Top comments (0)