java-tutorials/kubernetes-modules/kubernetes-spring
Harry9656 acce5c0a91
JAVA-32437: Remove mvnw, mvnw.cmd and files under .mvn/wrapper (#16413)
2024-04-18 13:22:59 +03:00
..
src JAVA-16561: Fix references to parents (#13222) 2023-01-10 01:29:14 +05:30
.gitignore kong-k8s-springboot cleuton.sampaio (#13001) 2022-11-09 14:14:27 -08:00
README.md Update README.md 2022-11-15 10:04:29 +08:00
clusterIp.yaml kong-k8s-springboot cleuton.sampaio (#13001) 2022-11-09 14:14:27 -08:00
ingress-rule.yaml kong-k8s-springboot cleuton.sampaio (#13001) 2022-11-09 14:14:27 -08:00
pom.xml [JAVA-26730] Upgraded io.projectreactor to latest version (#15234) 2023-12-11 08:58:51 +01:00
rate-limiter.yaml kong-k8s-springboot cleuton.sampaio (#13001) 2022-11-09 14:14:27 -08:00
serviceDeployment.yaml kong-k8s-springboot cleuton.sampaio (#13001) 2022-11-09 14:14:27 -08:00

README.md

Kong Ingress Controller with Spring Boot

This project was generated from Spring Initializer Website (https://start.spring.io/):

Maven version Java latest:

curl https://start.spring.io/starter.tgz -d dependencies=webflux,actuator -d type=maven-project | tar -xzvf -

Maven version Java 11:

curl https://start.spring.io/starter.tgz -d dependencies=webflux,actuator -d type=maven-project -d javaVersion=11 | tar -xzvf -

Steps to run the demonstration:

  1. Install minikube: https://www.baeldung.com/spring-boot-minikube

  2. Install Kong Ingress Controller on minikube: https://docs.konghq.com/kubernetes-ingress-controller/latest/deployment/minikube/

  • Test wich echo-server
  • Create environment variable: export PROXY_IP=$(minikube service -n kong kong-proxy --url | head -1)
  1. build that Spring boot service:
  • Run ./mvnw install
  • Run jar: java -jar target/*.jar
  1. Create a Docker image: If using minikube and don't want to push image to a repository, then point your local Docker client to Minikube's implementation: eval $(minikube -p minikube docker-env) --- use the same shell.
  • Run: ./mvnw spring-boot:build-image
  1. Deploy the application, create a service and an ingress rule:
kubectl apply -f serviceDeployment.yaml
kubectl apply -f clusterIp.yaml
kubectl apply -f ingress-rule.yaml
  1. Test access using the proxy IP:
curl -i $PROXY_IP/actuator/health

Setting up a rate limiter on your api

  1. Create a plugin:

kubectl apply -f rate-limiter.yaml

  1. Now test resource. Try more than 5 times a minute:
curl -i $PROXY_IP/actuator/health

Relevant Articles