Skip to content

Commit

Permalink
kong-k8s-springboot cleuton.sampaio (eugenp#13001)
Browse files Browse the repository at this point in the history
Co-authored-by: cleutonsampaio <cleutonsampaio@cloud.upwork.com>
  • Loading branch information
cleuton and cleutonsampaio committed Nov 9, 2022
1 parent 61da4cb commit 95f93aa
Show file tree
Hide file tree
Showing 14 changed files with 742 additions and 0 deletions.
33 changes: 33 additions & 0 deletions kubernetes-modules/kubernetes-spring/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
54 changes: 54 additions & 0 deletions kubernetes-modules/kubernetes-spring/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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)

3. build that Spring boot service:
- Run ./mvnw install
- Run jar: java -jar target/*.jar

4. 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

5. 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
```

6. Test access using the proxy IP:
```
curl -i $PROXY_IP/actuator/health
```

## Setting up a rate limiter on your api

7. Create a plugin:

kubectl apply -f rate-limiter.yaml

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


18 changes: 18 additions & 0 deletions kubernetes-modules/kubernetes-spring/clusterIp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: demo
name: demo
spec:
ports:
- name: 8080-8080
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: demo
type: ClusterIP
status:
loadBalancer: {}
16 changes: 16 additions & 0 deletions kubernetes-modules/kubernetes-spring/ingress-rule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: demo
spec:
ingressClassName: kong
rules:
- http:
paths:
- path: /actuator/health
pathType: ImplementationSpecific
backend:
service:
name: demo
port:
number: 8080
Loading

0 comments on commit 95f93aa

Please sign in to comment.