summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2025-01-17 11:41:55 +0100
committerSanto Cariotti <santo@dcariotti.me>2025-01-17 11:41:55 +0100
commit6cfd0194f65d7730fedcf4ac100f0c3aa28ad06d (patch)
tree51ef1435683788985a83f1bef00e35532735d045
parenta8a948998cd12c5bfbb24a1fcf123901c70cb1c0 (diff)
Use only three files
-rwxr-xr-xrun.sh15
-rw-r--r--yaml/backend.yaml143
-rw-r--r--yaml/configs/cas.yaml9
-rw-r--r--yaml/configs/frontend.yaml6
-rw-r--r--yaml/deployments/cas.yaml73
-rw-r--r--yaml/frontend.yaml (renamed from yaml/deployments/frontend.yaml)29
-rw-r--r--yaml/kind-cluster.yaml (renamed from yaml/cluster/kind-cluster-config.yaml)0
-rw-r--r--yaml/networking/balance.yaml37
-rw-r--r--yaml/policies/network.yaml18
-rw-r--r--yaml/postgres.yaml (renamed from yaml/deployments/postgres.yaml)42
-rw-r--r--yaml/pvcs/pgdata.yaml10
-rw-r--r--yaml/secrets/cas.yaml9
-rw-r--r--yaml/services/cas.yaml11
-rw-r--r--yaml/services/frontend.yaml11
-rw-r--r--yaml/services/postgres.yaml11
15 files changed, 210 insertions, 214 deletions
diff --git a/run.sh b/run.sh
index d9a203f..12d9114 100755
--- a/run.sh
+++ b/run.sh
@@ -18,20 +18,7 @@ fi
K8S_FOLDER="./yaml"
-YAML_FILES=(
- "configs/cas.yaml"
- "configs/frontend.yaml"
- "deployments/cas.yaml"
- "deployments/frontend.yaml"
- "secrets/cas.yaml"
- "services/cas.yaml"
- "policies/network.yaml"
- "pvcs/pgdata.yaml"
- "deployments/postgres.yaml"
- "services/postgres.yaml"
- "deployments/frontend.yaml"
- "networking/balance.yaml"
-)
+YAML_FILES=( "postgres.yaml" "backend.yaml" "frontend.yaml" )
for file in "${YAML_FILES[@]}"; do
file="$K8S_FOLDER/$file"
diff --git a/yaml/backend.yaml b/yaml/backend.yaml
new file mode 100644
index 0000000..d157a07
--- /dev/null
+++ b/yaml/backend.yaml
@@ -0,0 +1,143 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: cas-backend-config
+data:
+ RUST_LOG: ${RUST_LOG}
+ DATABASE_URL: "postgres://postgres:password@postgres-service:5432/gis"
+ ALLOWED_HOST: "0.0.0.0:8000"
+ AUDIO_PATH: "./assets"
+---
+apiVersion: v1
+kind: Secret
+metadata:
+ name: cas-backend-secret
+type: Opaque
+data:
+ JWT_SECRET: ${JWT_SECRET}
+ EXPO_ACCESS_TOKEN: ${EXPO_ACCESS_TOKEN}
+ UNREALSPEECH_TOKEN: ${UNREALSPEECH_TOKEN}
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: cas-backend-deployment
+ labels:
+ app: cas-backend
+spec:
+ replicas: 2
+ selector:
+ matchLabels:
+ app: cas-backend
+ template:
+ metadata:
+ labels:
+ app: cas-backend
+ spec:
+ affinity:
+ podAntiAffinity:
+ requiredDuringSchedulingIgnoredDuringExecution:
+ - labelSelector:
+ matchLabels:
+ app: cas-backend
+ topologyKey: "kubernetes.io/hostname"
+ resources:
+ requests:
+ cpu: "200m"
+ memory: "500Mi"
+ limits:
+ cpu: "500m"
+ memory: "1Gi"
+ containers:
+ - name: cas
+ image: ghcr.io/cas-4/backend:latest
+ imagePullPolicy: Always
+ env:
+ - name: RUST_LOG
+ valueFrom:
+ configMapKeyRef:
+ name: cas-backend-config
+ key: RUST_LOG
+ - name: DATABASE_URL
+ valueFrom:
+ configMapKeyRef:
+ name: cas-backend-config
+ key: DATABASE_URL
+ - name: JWT_SECRET
+ valueFrom:
+ secretKeyRef:
+ name: cas-secret
+ key: JWT_SECRET
+ - name: EXPO_ACCESS_TOKEN
+ valueFrom:
+ secretKeyRef:
+ name: cas-secret
+ key: EXPO_ACCESS_TOKEN
+ - name: UNREALSPEECH_TOKEN
+ valueFrom:
+ secretKeyRef:
+ name: cas-secret
+ key: UNREALSPEECH_TOKEN
+ - name: ALLOWED_HOST
+ valueFrom:
+ configMapKeyRef:
+ name: cas-backend-config
+ key: ALLOWED_HOST
+ - name: AUDIO_PATH
+ valueFrom:
+ configMapKeyRef:
+ name: cas-backend-config
+ key: AUDIO_PATH
+ ports:
+ - containerPort: 8000
+ restartPolicy: Always
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: cas-backend-service
+spec:
+ ports:
+ - port: 80
+ targetPort: 8000
+ selector:
+ app: cas-backend
+ type: LoadBalancer
+---
+apiVersion: autoscaling/v2
+kind: HorizontalPodAutoscaler
+metadata:
+ name: cas-backend-hpa
+spec:
+ scaleTargetRef:
+ apiVersion: apps/v1
+ kind: Deployment
+ name: cas-backend-deployment
+ minReplicas: 1
+ maxReplicas: 10
+ metrics:
+ - type: Resource
+ resource:
+ name: cpu
+ target:
+ type: Utilization
+ averageUtilization: 70
+ - type: Resource
+ resource:
+ name: memory
+ target:
+ type: Utilization
+ averageUtilization: 70
+ behavior:
+ scaleUp:
+ stabilizationWindowSeconds: 60
+ policies:
+ - type: Percent
+ value: 100
+ periodSeconds: 15
+ scaleDown:
+ stabilizationWindowSeconds: 300
+ policies:
+ - type: Percent
+ value: 100
+ periodSeconds: 15
diff --git a/yaml/configs/cas.yaml b/yaml/configs/cas.yaml
deleted file mode 100644
index 34d5d58..0000000
--- a/yaml/configs/cas.yaml
+++ /dev/null
@@ -1,9 +0,0 @@
-apiVersion: v1
-kind: ConfigMap
-metadata:
- name: cas-config
-data:
- RUST_LOG: ${RUST_LOG}
- DATABASE_URL: "postgres://postgres:password@postgres-service:5432/gis"
- ALLOWED_HOST: "0.0.0.0:8000"
- AUDIO_PATH: "./assets"
diff --git a/yaml/configs/frontend.yaml b/yaml/configs/frontend.yaml
deleted file mode 100644
index f80a790..0000000
--- a/yaml/configs/frontend.yaml
+++ /dev/null
@@ -1,6 +0,0 @@
-apiVersion: v1
-kind: ConfigMap
-metadata:
- name: frontend-config
-data:
- VITE_API_URL: ${VITE_API_URL}
diff --git a/yaml/deployments/cas.yaml b/yaml/deployments/cas.yaml
deleted file mode 100644
index 1b106ad..0000000
--- a/yaml/deployments/cas.yaml
+++ /dev/null
@@ -1,73 +0,0 @@
-apiVersion: apps/v1
-kind: Deployment
-metadata:
- name: cas-deployment
- labels:
- app: cas-app
-spec:
- replicas: 2
- selector:
- matchLabels:
- app: cas-app
- template:
- metadata:
- labels:
- app: cas-app
- spec:
- affinity:
- podAntiAffinity:
- requiredDuringSchedulingIgnoredDuringExecution:
- - labelSelector:
- matchLabels:
- app: cas-app
- topologyKey: "kubernetes.io/hostname"
- resources:
- requests:
- cpu: "200m"
- memory: "500Mi"
- limits:
- cpu: "500m"
- memory: "1Gi"
- containers:
- - name: cas
- image: ghcr.io/cas-4/backend:latest
- imagePullPolicy: Always
- env:
- - name: RUST_LOG
- valueFrom:
- configMapKeyRef:
- name: cas-config
- key: RUST_LOG
- - name: DATABASE_URL
- valueFrom:
- configMapKeyRef:
- name: cas-config
- key: DATABASE_URL
- - name: JWT_SECRET
- valueFrom:
- secretKeyRef:
- name: cas-secret
- key: JWT_SECRET
- - name: EXPO_ACCESS_TOKEN
- valueFrom:
- secretKeyRef:
- name: cas-secret
- key: EXPO_ACCESS_TOKEN
- - name: UNREALSPEECH_TOKEN
- valueFrom:
- secretKeyRef:
- name: cas-secret
- key: UNREALSPEECH_TOKEN
- - name: ALLOWED_HOST
- valueFrom:
- configMapKeyRef:
- name: cas-config
- key: ALLOWED_HOST
- - name: AUDIO_PATH
- valueFrom:
- configMapKeyRef:
- name: cas-config
- key: AUDIO_PATH
- ports:
- - containerPort: 8000
- restartPolicy: Always
diff --git a/yaml/deployments/frontend.yaml b/yaml/frontend.yaml
index 781bf87..94766a8 100644
--- a/yaml/deployments/frontend.yaml
+++ b/yaml/frontend.yaml
@@ -1,17 +1,24 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: cas-frontend-config
+data:
+ VITE_API_URL: ${VITE_API_URL}
+---
apiVersion: apps/v1
kind: Deployment
metadata:
- name: frontend-deployment
+ name: cas-frontend-deployment
labels:
- app: frontend-app
+ app: cas-frontend-app
spec:
selector:
matchLabels:
- app: frontend-app
+ app: cas-frontend-app
template:
metadata:
labels:
- app: frontend-app
+ app: cas-frontend-app
spec:
containers:
- name: frontend
@@ -23,6 +30,18 @@ spec:
- name: VITE_API_URL
valueFrom:
configMapKeyRef:
- name: frontend-config
+ name: cas-frontend-config
key: VITE_API_URL
restartPolicy: Always
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: cas-frontend-service
+spec:
+ ports:
+ - port: 80
+ targetPort: 80
+ selector:
+ app: cas-frontend-app
+ type: ClusterIP
diff --git a/yaml/cluster/kind-cluster-config.yaml b/yaml/kind-cluster.yaml
index 6f0e32d..6f0e32d 100644
--- a/yaml/cluster/kind-cluster-config.yaml
+++ b/yaml/kind-cluster.yaml
diff --git a/yaml/networking/balance.yaml b/yaml/networking/balance.yaml
deleted file mode 100644
index a2367e7..0000000
--- a/yaml/networking/balance.yaml
+++ /dev/null
@@ -1,37 +0,0 @@
-apiVersion: autoscaling/v2
-kind: HorizontalPodAutoscaler
-metadata:
- name: cas-hpa
-spec:
- scaleTargetRef:
- apiVersion: apps/v1
- kind: Deployment
- name: cas-deployment
- minReplicas: 1
- maxReplicas: 10
- metrics:
- - type: Resource
- resource:
- name: cpu
- target:
- type: Utilization
- averageUtilization: 70
- - type: Resource
- resource:
- name: memory
- target:
- type: Utilization
- averageUtilization: 70
- behavior:
- scaleUp:
- stabilizationWindowSeconds: 60
- policies:
- - type: Percent
- value: 100
- periodSeconds: 15
- scaleDown:
- stabilizationWindowSeconds: 300
- policies:
- - type: Percent
- value: 100
- periodSeconds: 15
diff --git a/yaml/policies/network.yaml b/yaml/policies/network.yaml
deleted file mode 100644
index 2af8a27..0000000
--- a/yaml/policies/network.yaml
+++ /dev/null
@@ -1,18 +0,0 @@
-apiVersion: networking.k8s.io/v1
-kind: NetworkPolicy
-metadata:
- name: allow-cas-postgres
-spec:
- podSelector:
- matchLabels:
- app: cas
- policyTypes:
- - Ingress
- ingress:
- - from:
- - podSelector:
- matchLabels:
- app: postgres
- ports:
- - protocol: TCP
- port: 5432
diff --git a/yaml/deployments/postgres.yaml b/yaml/postgres.yaml
index fd9945f..1306581 100644
--- a/yaml/deployments/postgres.yaml
+++ b/yaml/postgres.yaml
@@ -36,3 +36,45 @@ spec:
- name: schema
hostPath:
path: ${PGDATA}
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: postgres-service
+spec:
+ ports:
+ - port: 5432
+ targetPort: 5432
+ selector:
+ app: postgres
+ type: ClusterIP
+---
+apiVersion: networking.k8s.io/v1
+kind: NetworkPolicy
+metadata:
+ name: allow-cas-postgres
+spec:
+ podSelector:
+ matchLabels:
+ app: cas
+ policyTypes:
+ - Ingress
+ ingress:
+ - from:
+ - podSelector:
+ matchLabels:
+ app: postgres
+ ports:
+ - protocol: TCP
+ port: 5432
+---
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+ name: pgdata-pvc
+spec:
+ accessModes:
+ - ReadWriteOnce
+ resources:
+ requests:
+ storage: 1Gi
diff --git a/yaml/pvcs/pgdata.yaml b/yaml/pvcs/pgdata.yaml
deleted file mode 100644
index 7580530..0000000
--- a/yaml/pvcs/pgdata.yaml
+++ /dev/null
@@ -1,10 +0,0 @@
-apiVersion: v1
-kind: PersistentVolumeClaim
-metadata:
- name: pgdata-pvc
-spec:
- accessModes:
- - ReadWriteOnce
- resources:
- requests:
- storage: 1Gi
diff --git a/yaml/secrets/cas.yaml b/yaml/secrets/cas.yaml
deleted file mode 100644
index a2fc3e3..0000000
--- a/yaml/secrets/cas.yaml
+++ /dev/null
@@ -1,9 +0,0 @@
-apiVersion: v1
-kind: Secret
-metadata:
- name: cas-secret
-type: Opaque
-data:
- JWT_SECRET: ${JWT_SECRET}
- EXPO_ACCESS_TOKEN: ${EXPO_ACCESS_TOKEN}
- UNREALSPEECH_TOKEN: ${UNREALSPEECH_TOKEN}
diff --git a/yaml/services/cas.yaml b/yaml/services/cas.yaml
deleted file mode 100644
index 0942e33..0000000
--- a/yaml/services/cas.yaml
+++ /dev/null
@@ -1,11 +0,0 @@
-apiVersion: v1
-kind: Service
-metadata:
- name: cas-service
-spec:
- ports:
- - port: 80
- targetPort: 8000
- selector:
- app: cas-app
- type: LoadBalancer
diff --git a/yaml/services/frontend.yaml b/yaml/services/frontend.yaml
deleted file mode 100644
index f5580ae..0000000
--- a/yaml/services/frontend.yaml
+++ /dev/null
@@ -1,11 +0,0 @@
-apiVersion: v1
-kind: Service
-metadata:
- name: frontend-service
-spec:
- ports:
- - port: 80
- targetPort: 80
- selector:
- app: frontend-app
- type: ClusterIP
diff --git a/yaml/services/postgres.yaml b/yaml/services/postgres.yaml
deleted file mode 100644
index ad3b969..0000000
--- a/yaml/services/postgres.yaml
+++ /dev/null
@@ -1,11 +0,0 @@
-apiVersion: v1
-kind: Service
-metadata:
- name: postgres-service
-spec:
- ports:
- - port: 5432
- targetPort: 5432
- selector:
- app: postgres
- type: ClusterIP