Spring boot deploy k8s example
Java 17
Docker / Docker-compose
Minikube
- Init sample application
- Deploy sample application k8s
- CRUD app sample
- Deploy Postgres k8s
Install minikube
brew install minikube
Show minikube dashboard
minikube dashboard
Build docker image
./mvnw spring-boot:build-image
Tag docker image
docker tag demo:0.0.1-SNAPSHOT uuhnaut69/spring-demo
Push image
docker push uuhnaut69/spring-demo
Make directory to store all yaml files
mkdir deployment
Generate deployment yaml
kubectl create deployment spring-boot-app --image uuhnaut69/spring-demo -o yaml --dry-run=client > deployment/app-deployment.yaml
Generate service yaml
kubectl create service clusterip spring-boot-app --tcp 80:8080 -o yaml --dry-run=client > deployment/app-service.yaml
Apply deployment
kubectl apply -f ./deployment
Config port forward
kubectl port-forward svc/spring-boot-k8s 9090:80
Test
curl http://localhost:9090/greeter; echo