summaryrefslogtreecommitdiff
path: root/yaml/backend.yaml
blob: 9967ddb1aa2d19d2e4b7d8214a9a7713343625ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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-backend-secret
                  key: JWT_SECRET
            - name: EXPO_ACCESS_TOKEN
              valueFrom:
                secretKeyRef:
                  name: cas-backend-secret
                  key: EXPO_ACCESS_TOKEN
            - name: UNREALSPEECH_TOKEN
              valueFrom:
                secretKeyRef:
                  name: cas-backend-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