ashutoshsahoo / spring-boot-kubernetes

Running a spring boot application in Kubernetes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spring Boot Kubernetes

Sample project to use spring boot application in kubernetes with jkube maven plugin.

  • Build application
mvn clean package

Docker image with layered architecture

For docker image with layered architecture, refer Jenkinsfile and Dockerfile directory.

  • Open shell in project directory and run following command to build docker image.
docker build -f deploy/Dockerfile --build-arg VERSION=7.2.0 -t ashutoshsahoo/spring-boot-kubernetes:7.2.0 .

Kubernetes deployment

  • Deploy to kubernetes
kubectl apply -f deploy/kubernetes.yml
  • Check pod and service status
kubectl get po,svc
  • Verify application status
curl --location --request GET 'http://localhost:31000/api/v5/hello'
  • Delete Kubernetes deployment
kubectl delete -f deploy/kubernetes.yml

Kubernetes Istio service mesh deployment

This is a demonstration of running two different versions of same application and redirecting traffic based on path prefix.

Please follow the instructions here to configure istio inside docker desktop.

  • Deploy app
kubectl apply -f deploy/istio
  • Check application status
kubelet get all
  • Verify application status
curl --location --request GET 'http://localhost/api/v5/hello'
  • Run following command to put some traffic into system.
for i in $(seq 1 100); do curl -s -o /dev/null "http://localhost/api/v5/hello"; done
for i in $(seq 1 100); do curl -s -o /dev/null "http://localhost/api/v6/hello"; done

Open kiali dashboard to view application metrics.

  • Delete deployment
kubectl delete -f deploy/istio
  • Clean up istio configuration

Refer the documentation here to clean up.

Deploy application using jkube maven plugin

  • Application deployment
mvn -Pk8s k8s:build k8s:resource k8s:deploy
  • Verify application
kubectl exec -it deployments.apps/spring-boot-kubernetes -- bash
curl --location --request GET 'http://localhost:8080/api/v5/hello'
  • UnDeploy application
mvn -Pk8s k8s:undeploy