This generator creates a Kubernetes Service and Deployment Resource to deploy a Spring Boot application. It also can create the Kubernetes resources for deploying a MySQL database or a small Kafka cluster, should the application need it.
If you used the starter service, then the generator has already been executed and you can deploy it's required services and then build and deploy the application.
If your application needs services such as a database or message broker, this section shows you how to deploy these services to Kubernetes
Step 1: Create a secret:
kubectl create secret generic mysql \
--from-literal=mysql-root-password=$(echo $RANDOM) \
--from-literal=mysql-password=$(echo $RANDOM)
Step 2: Deploy the database:
kubectl apply -f kubernetes/services/mysql
To recreate the secret, first delete the existing secret:
kubectl delete secret mysql
To delete the database storage, delete the persistent volume:
kubectl delete pvc mysql
To delete the MySQL service and deployment in addition to the persistent volume:
kubectl delete deployment,services,pvc -l app=mysql
Deploy the cluster:
kubectl apply -f kubernetes/services/kafka
To delete the Kafka cluster and Zookeeper:
kubectl delete deployment,services -l app=kafka
This generator relies on using the new buildpack
support added in Spring Boot version 2.3 to create a container image.
If you are using Minikube you should configure your terminal to use the same Docker environment:
eval $(minikube docker-env)
Step 1: Build the project and create the container image:
./mvnw -DskipTests clean package spring-boot:build-image
Step 2: Deploy the app to Kubernetes
kubectl apply -f kubernetes/app
Use kubectl get all
to verify that the resources created.
Accessing the application's endpoint varies based on the type of Kubernetes cluster you are using. For example, if minikube is being used, look for the endpoint to access using the command minikube service list
. For othetr Kubernetes clusters, you can use port-forwarding to access the service. Run kubectl port-forward service/<name-of-service> 8080:80
to forward the service port to localhost:8080
.
The README.md file from the code repository for the appliation should include a few curl
commands to exercise the application.
This generator creates the Kubernetes service
and deploymnet
resources files to deploy a Spring Boot application using kubectl
To use the generator you will need to install the following command line tool:
These commands use the tss
CLI.
tss k8s-simple new
creates
- A
kubernetes
directory with aservice.yaml
anddeployment.yaml
tss k8s-simple new-services
creates
- A
kubernetes/services/<service-name>
directory with Kubernetes resource files for various services. Currently onlymysql
service name is supported.
tss generator install --go-getter-url=github.com/markpollack/generator-k8s-simple
To use the install command you need to install go-getter CLI.