This repository contains a sample CRUD (Create, Read, Update, Delete) application built with Spring Boot and MySQL that is ready to be deployed to Kubernetes. The app allows you to manage User entities by creating, reading, updating, and deleting them through a RESTful API.
To run this app locally, you need to have the following installed:
- Docker
- Kubernetes
- Minikube (optional, for running a local Kubernetes cluster)
- Clone the repository:
git clone https://github.com/JasonShuyinta/k8s-demo.git
- Change directory to the app:
cd k8s-demo
- Build the Docker image:
docker build -t jason9722/k8s-demo .
- Start Minikube (if you haven't already):
minikube start
- Change directory to k8s
cd k8s
- Deploy the app to Kubernetes:
kubectl apply -f kubernetes/deployment.yaml
- Get the URL to access the app:
minikube service k8s-spring-boot-mysql-crud --url
- Open the URL in your browser to access the app.
The following endpoints are available for managing User entities:
GET /users
: Get all usersGET /users/{id}
: Get a user by IDPOST /users
: Create a new userPUT /users/{id}
: Update an existing userDELETE /users/{id}
: Delete a user by ID
All requests and responses are in JSON format.
This app uses the following technologies:
- Spring Boot: A Java framework for building web applications.
- MySQL: A popular open-source relational database.
- Kubernetes: An open-source container orchestration platform.
- Docker: An open source platform that enables developers to build, deploy, run, update and manage containers
(You need Docker Desktop up and running)
To start Kubernetes run this command
minikube start --driver docker
To create a pod with the configuration file named: app-deployment.yaml
kubectl apply -f app-deployment.yaml
To view your services, deployments and pods:
kubectl get svc
kubectl get deployment
kubectl get pod
To get more information about a pod you can run
kubectl describe pod [POD_NAME]
To view logs for a specific pod
kubectl logs [POD_NAME]
To run a specific pod in your terminal, for example a mysql terminal, get the pod name (mysql-123) and run:
kubectl exec -it [POD_NAME] bin/bash
You can use namespaces to group resources together
kubectl get namespaces
kubectl get ns
kubectl delete namespace [NAMESPACE]
After you successfull enter into integrated mode in the mysql pod, to access your database run:
mysql -h <db_host> -u <user> -p <password>
To view the running app on your browser, giving that the app is running on service service-123, run the command:
minikube service [SERVICE_NAME] --url
To enable the minikube dashboard run:
minikube dashboard