Skip to content

Commit 2400661

Browse files
authored
Merge pull request #1 from ClassConnect-org/init
Init
2 parents c9c233c + 17e290a commit 2400661

5 files changed

Lines changed: 117 additions & 0 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Deploy Kong API Gateway
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy-kong:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout Repo
14+
uses: actions/checkout@v3
15+
16+
- name: Set Kubeconfig as Environment Variable
17+
run: |
18+
mkdir -p $HOME/.kube
19+
printf "%s" "${{ secrets.KUBE_CONFIG }}" | base64 --decode > $HOME/.kube/config
20+
export KUBECONFIG=$HOME/.kube/config
21+
chmod 600 $HOME/.kube/config
22+
echo "KUBECONFIG set."
23+
24+
- name: Add Kong Helm Repo
25+
run: |
26+
helm repo add kong https://charts.konghq.com
27+
helm repo update
28+
29+
- name: Deploy Kong with Helm
30+
run: |
31+
helm upgrade --install kong kong/kong \
32+
--namespace kong \
33+
--create-namespace \
34+
--values helm/values.yaml
35+
36+
- name: Wait for Kong to be Ready
37+
run: |
38+
kubectl rollout status deployment/kong -n kong --timeout=180s
39+
40+
- name: Apply Kong Plugin and Ingress Resources
41+
run: |
42+
kubectl apply -f k8s/
43+

helm/values.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ingressController:
2+
enabled: true
3+
installCRDs: true
4+
5+
proxy:
6+
type: LoadBalancer
7+
8+
env:
9+
KONG_LOG_LEVEL: debug
10+
KONG_PLUGINS: bundled,pre-function

k8s/ingress-administration.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
name: admin-ingress
5+
namespace: default
6+
annotations:
7+
konghq.com/strip-path: "true"
8+
konghq.com/plugins: check-user-auth
9+
spec:
10+
ingressClassName: kong
11+
rules:
12+
- http:
13+
paths:
14+
- path: /admin
15+
pathType: Prefix
16+
backend:
17+
service:
18+
name: administration-microservice
19+
port:
20+
number: 8080

k8s/ingress-users.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
name: users-ingress
5+
namespace: default
6+
annotations:
7+
konghq.com/strip-path: "true"
8+
spec:
9+
ingressClassName: kong
10+
rules:
11+
- http:
12+
paths:
13+
- path: /users
14+
pathType: Prefix
15+
backend:
16+
service:
17+
name: users-microservice
18+
port:
19+
number: 8080

k8s/kong-plugin-auth.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: configuration.konghq.com/v1
2+
kind: KongPlugin
3+
metadata:
4+
name: check-user-auth
5+
namespace: default
6+
config:
7+
access:
8+
- |
9+
local http = require "resty.http"
10+
local req = kong.request
11+
local user_id = req.get_header("X-User-ID")
12+
if not user_id then
13+
return kong.response.exit(400, "Missing user ID")
14+
end
15+
16+
local httpc = http.new()
17+
local res, err = httpc:request_uri("http://users-microservice.default.svc.cluster.local:8080/users/" .. user_id, {
18+
method = "GET"
19+
})
20+
21+
if not res or res.status ~= 200 then
22+
return kong.response.exit(403, "Access denied")
23+
end
24+
plugin: pre-function
25+

0 commit comments

Comments
 (0)