Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: install keda using tf #2

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4dbf7e0
feat: install spin
alexis-langlet Apr 17, 2024
bf5b4d0
feat: setup ingress
alexis-langlet Apr 24, 2024
1fde804
feat: deploy whoami app
alexis-langlet Apr 24, 2024
066eebc
feat: use flux
alexis-langlet Apr 25, 2024
d775e22
refacto: split tf in multiple files
alexis-langlet Apr 25, 2024
23089fa
feat: add keda http add on
alexis-langlet Apr 25, 2024
f74778a
#q
alexis-langlet Apr 25, 2024
2c1c2b1
feat: Add Terraform deployment and Flux configuration for whoami app …
alexis-langlet May 14, 2024
681d354
feat: Update Flux configuration for whoami app with CPU scaling
alexis-langlet May 15, 2024
ee2f0ea
feat: Update ingress config
alexis-langlet May 15, 2024
7fdd4a7
chore: Update Flux configuration for whoami app with HTTP scaling
alexis-langlet May 15, 2024
8da01d5
chore: Update HTTP scaling configuration for whoami app
alexis-langlet May 15, 2024
8fe12fa
feat: Add ingress support for whoami app with Traefik
alexis-langlet May 15, 2024
3bb374d
chore: Update HTTP scaling configuration for whoami app
alexis-langlet May 15, 2024
e9fc02a
feat: add rabbitmq
alexis-langlet May 17, 2024
3a06327
remove amqp scaling
alexis-langlet May 17, 2024
7dafc1a
fix: fix request rate
alexis-langlet May 17, 2024
3403bae
feat: add queued app with scaling
alexis-langlet May 17, 2024
73b5cf9
fix: correct typo in folder name
alexis-langlet May 17, 2024
ef6105d
fix: set keda-rabbitmq secret namespace
alexis-langlet May 17, 2024
d39af8c
doc: add testing process to readme
alexis-langlet May 17, 2024
5aaf155
feat: use spin shim executor
alexis-langlet May 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# terraform
deployment/terraform/.terraform
deployment/terraform/.terraform.lock.hcl
deployment/terraform/terraform.tfstate
deployment/terraform/terraform.tfstate.backup
deployment/terraform/.terraform.tfstate.lock.info
54 changes: 53 additions & 1 deletion Readme.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,53 @@
# Spinkube demo
# Spinkube demo

## Deploy

```bash
cd deployment/terraform
terraform init
terraform apply -auto-approve
```

Then wait a bit for the cluster to be ready and for flux to deploy the applications.

## Test the deployment


### Test the queue scaling
From the rabbitmq pod:
Create a queue
```bash
curl -u user:password -XPUT -H "content-type:application/json" \
http://localhost:15672/api/queues/%2F/testqueue \
-d'{"durable":true}'
```

Send a message
```bash
curl -u user:password -XPOST -H "content-type:application/json" \
http://localhost:15672/api/exchanges/%2F/amq.default/publish \
-d'{"properties":{},"routing_key":"testqueue","payload":"Hello, World!","payload_encoding":"string"}'
```

Empty the queue
```bash
curl -u user:password -XDELETE -H "content-type:application/json" \
http://localhost:15672/api/queues/%2F/testqueue/contents
```

### Test the http scaling
From localhost:
Get the external ip of the service
```bash
kubectl get svc --namespace traefik
```

put cluster ip in /etc/hosts
```bash
echo "<EXTERNAL_IP> whoami.example.com" | sudo tee -a /etc/hosts
```

Test the service
```bash
curl whoami.example.com
```
Empty file modified app-whoami/.gitignore
100644 → 100755
Empty file.
Empty file modified app-whoami/Cargo.lock
100644 → 100755
Empty file.
Empty file modified app-whoami/Cargo.toml
100644 → 100755
Empty file.
Empty file modified app-whoami/README.md
100644 → 100755
Empty file.
Empty file modified app-whoami/deploy.yml
100644 → 100755
Empty file.
Empty file modified app-whoami/spin.toml
100644 → 100755
Empty file.
Empty file modified app-whoami/src/lib.rs
100644 → 100755
Empty file.
Empty file removed deployment/.keep
Empty file.
12 changes: 12 additions & 0 deletions deployment/flux/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- whoami/app.yaml
- whoami/http-scale.yaml
- whoami/ingress.yaml
- metallb/ip-pool.yaml
- metallb/l2-advertisement.yaml
- queued-whoami/app.yaml
- queued-whoami/amqp-scale.yaml
- spin/spin-shim-executor.yaml
8 changes: 8 additions & 0 deletions deployment/flux/metallb/ip-pool.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: default
namespace: metallb-system
spec:
addresses:
- 192.168.207.200-192.168.207.250
5 changes: 5 additions & 0 deletions deployment/flux/metallb/l2-advertisement.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: default
namespace: metallb-system
38 changes: 38 additions & 0 deletions deployment/flux/queued-whoami/amqp-scale.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: v1
kind: Secret
metadata:
name: keda-rabbitmq-secret
namespace: default
data:
host: YW1xcDovL3VzZXI6cGFzc3dvcmRAcmFiYml0bXEucmFiYml0bXEuc3ZjLmNsdXN0ZXIubG9jYWw6NTY3Mg== # base64 encoded value of format amqp://user:[email protected]:5672
---
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
name: keda-trigger-auth-rabbitmq-conn
namespace: default
spec:
secretTargetRef:
- parameter: host
name: keda-rabbitmq-secret
key: host
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: rabbitmq-scaledobject
namespace: default
spec:
scaleTargetRef:
name: queued-whoami-app
cooldownPeriod: 20
pollingInterval: 10
triggers:
- type: rabbitmq
metadata:
protocol: amqp
queueName: testqueue
mode: QueueLength # could also be MessageRate
value: "5"
authenticationRef:
name: keda-trigger-auth-rabbitmq-conn
41 changes: 41 additions & 0 deletions deployment/flux/queued-whoami/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: core.spinoperator.dev/v1alpha1
kind: SpinApp
metadata:
name: queued-whoami-app
namespace: default
spec:
image: index.docker.io/sautax/variable-explorer:v1
executor: containerd-shim-spin
enableAutoscaling: true
resources:
limits:
cpu: 500m
memory: 500Mi
requests:
cpu: 100m
memory: 400Mi
variables:
- name: pod_name
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: pod_namespace
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: pod_uid
valueFrom:
fieldRef:
fieldPath: metadata.uid
- name: pod_ip
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: node_name
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: host_ip
valueFrom:
fieldRef:
fieldPath: status.hostIP
8 changes: 8 additions & 0 deletions deployment/flux/spin/spin-shim-executor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: core.spinoperator.dev/v1alpha1
kind: SpinAppExecutor
metadata:
name: containerd-shim-spin
spec:
createDeployment: true
deploymentConfig:
runtimeClassName: wasmtime-spin-v2
41 changes: 41 additions & 0 deletions deployment/flux/whoami/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: core.spinoperator.dev/v1alpha1
kind: SpinApp
metadata:
name: whoami-app
namespace: default
spec:
image: index.docker.io/sautax/variable-explorer:v1
executor: containerd-shim-spin
enableAutoscaling: true
resources:
limits:
cpu: 500m
memory: 500Mi
requests:
cpu: 100m
memory: 400Mi
variables:
- name: pod_name
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: pod_namespace
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: pod_uid
valueFrom:
fieldRef:
fieldPath: metadata.uid
- name: pod_ip
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: node_name
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: host_ip
valueFrom:
fieldRef:
fieldPath: status.hostIP
15 changes: 15 additions & 0 deletions deployment/flux/whoami/cpu-scale.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: cpu-scaling
namespace: default
spec:
scaleTargetRef:
name: whoami-app
minReplicaCount: 1
maxReplicaCount: 50
triggers:
- type: cpu
metricType: Utilization
metadata:
value: "50"
26 changes: 26 additions & 0 deletions deployment/flux/whoami/http-scale.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: http.keda.sh/v1alpha1
kind: HTTPScaledObject
metadata:
name: http-scaling
namespace: default

spec:
hosts:
- "whoami.example.com"
replicas:
min: 0
max: 10
scaleTargetRef:
deployment: whoami-app
service: whoami-app
port: 80
scaledownPeriod: 1
scalingMetric:
concurrency:
targetValue: 100
requestRate:
granularity: 1s
targetValue: 10 # default 100
window: 10s # default: 1m


19 changes: 19 additions & 0 deletions deployment/flux/whoami/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: whoami-app
namespace: keda

spec:
ingressClassName: traefik
rules:
- host: whoami.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: keda-add-ons-http-interceptor-proxy
port:
number: 8080
12 changes: 12 additions & 0 deletions deployment/terraform/flux2.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module "flux-bootstrap" {
source = "./modules/flux-bootstrap"
depends_on = [helm_release.keda]
}

module "flux-sync" {
source = "./modules/flux-sync"
name = "cluster-keda"
path = "deployment/flux"
service_account_name = "kustomize-controller"
depends_on = [module.flux-bootstrap]
}
16 changes: 16 additions & 0 deletions deployment/terraform/keda.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
resource "helm_release" "keda" {
name = "keda"
namespace = "keda"
create_namespace = true
repository = "https://kedacore.github.io/charts"
chart = "keda"
}

resource "helm_release" "keda_add_on_http" {
name = "keda-http-add-on"
namespace = "keda"
create_namespace = true
repository = "https://kedacore.github.io/charts"
chart = "keda-add-ons-http"
depends_on = [helm_release.keda]
}
Loading