Skip to content

Commit

Permalink
feat: Cron backups + consistent labels
Browse files Browse the repository at this point in the history
  • Loading branch information
andreroggeri committed Apr 21, 2024
1 parent 5c8d9e4 commit 8a1a384
Show file tree
Hide file tree
Showing 24 changed files with 187 additions and 26 deletions.
6 changes: 3 additions & 3 deletions backend/deployment/app/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: schedule-app
labels:
app: schedul
env: staging
spec:
replicas: 1
selector:
Expand All @@ -11,8 +14,6 @@ spec:
metadata:
labels:
app: schedule-app
app_context: schedule
env: staging
spec:
containers:
- name: schedule-app
Expand Down Expand Up @@ -42,4 +43,3 @@ spec:
key: schedule-rabbitmq-url
- name: DJANGO_SETTINGS_MODULE
value: app.settings.staging # TODO: Use a single config file

3 changes: 3 additions & 0 deletions backend/deployment/app/ingress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ metadata:
spec.ingressClassName: traefik
cert-manager.io/cluster-issuer: letsencrypt-prod
traefik.ingress.kubernetes.io/router.middlewares: default-redirect-https@kubernetescrd
labels:
app: schedule
env: staging
spec:
rules:
- host: schedule.staging.agendaodonto.com # Updated in CI/CD pipeline
Expand Down
3 changes: 3 additions & 0 deletions backend/deployment/app/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apiVersion: v1
kind: Service
metadata:
name: schedule-app
labels:
app: schedule
env: staging
spec:
selector:
app: schedule-app
Expand Down
36 changes: 36 additions & 0 deletions backend/deployment/postgres/cron-backup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: schedule-postgres-backup
labels:
app: schedule
app_context: schedule
env: staging
spec:
schedule: "0 0 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: db-backup
image: postgres:16
command:
- /bin/sh
- -c
- pg_dump -h schedule-postgres.default.svc.cluster.local -U postgres -d schedule -f /backup/schedule-db-backup-$(date +'%s').sql
env:
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: schedule-secrets
key: schedule-db-password
volumeMounts:
- name: schedule-postgres-backup-volume
mountPath: /backup
volumes:
- name: schedule-postgres-backup-volume
persistentVolumeClaim:
claimName: schedule-postgres-backup-volume-claim

restartPolicy: Never
5 changes: 3 additions & 2 deletions backend/deployment/postgres/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: schedule-postgres
labels:
app: schedule
env: staging
spec:
selector:
matchLabels:
Expand All @@ -10,8 +13,6 @@ spec:
metadata:
labels:
app: schedule-postgres
app_context: schedule
env: staging
spec:
containers:
- name: schedule-postgres
Expand Down
16 changes: 16 additions & 0 deletions backend/deployment/postgres/pv-claim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,19 @@ spec:
resources:
requests:
storage: 10Gi

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: schedule-postgres-backup-volume-claim
labels:
app: schedule
env: staging
spec:
storageClassName: manual
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
22 changes: 20 additions & 2 deletions backend/deployment/postgres/pv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ metadata:
name: schedule-postgres-volume
labels:
type: local
app: schedule-postgres
app_context: schedule
app: schedule
env: staging
spec:
storageClassName: manual
Expand All @@ -15,3 +14,22 @@ spec:
- ReadWriteMany
hostPath:
path: /data/schedule-postgresql

---
apiVersion: v1
kind: PersistentVolume
metadata:
name: schedule
labels:
type: local
app: schedule-postgres-backup
app_context: schedule
env: staging
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
hostPath:
path: /nfs_mount/schedule-postgresql-backup
3 changes: 1 addition & 2 deletions backend/deployment/postgres/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ kind: Service
metadata:
name: schedule-postgres
labels:
app: schedule-postgres
app_context: schedule
app: schedule
env: staging
spec:
ports:
Expand Down
5 changes: 3 additions & 2 deletions backend/deployment/rabbitmq/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: schedule-rabbitmq
labels:
app: schedule
env: staging
spec:
selector:
matchLabels:
Expand All @@ -10,8 +13,6 @@ spec:
metadata:
labels:
app: schedule-rabbitmq
app_context: schedule
env: staging
spec:
containers:
- name: schedule-rabbitmq
Expand Down
3 changes: 1 addition & 2 deletions backend/deployment/rabbitmq/pv-claim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ kind: PersistentVolumeClaim
metadata:
name: schedule-rabbitmq-volume-claim
labels:
app: schedule-rabbitmq
app_context: schedule
app: schedule
env: staging
spec:
storageClassName: manual
Expand Down
3 changes: 1 addition & 2 deletions backend/deployment/rabbitmq/pv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ metadata:
name: schedule-rabbitmq-volume
labels:
type: local
app: schedule-rabbitmq
app_context: schedule
app: schedule
env: staging
spec:
storageClassName: manual
Expand Down
3 changes: 1 addition & 2 deletions backend/deployment/rabbitmq/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ kind: Service
metadata:
name: schedule-rabbitmq
labels:
app: schedule-rabbitmq
app_context: schedule
app: schedule
env: staging
spec:
ports:
Expand Down
5 changes: 3 additions & 2 deletions backend/deployment/worker/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: schedule-worker
labels:
app: schedule
env: staging
spec:
replicas: 1
selector:
Expand All @@ -11,8 +14,6 @@ spec:
metadata:
labels:
app: schedule-worker
app_context: schedule
env: staging
spec:
containers:
- name: schedule-worker
Expand Down
3 changes: 3 additions & 0 deletions chatbot/deployment/app/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: messaging-app
labels:
app: messaging
env: staging
spec:
replicas: 1
selector:
Expand Down
4 changes: 3 additions & 1 deletion chatbot/deployment/app/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ apiVersion: v1
kind: Service
metadata:
name: messaging

labels:
app: messaging
env: staging
spec:
selector:
app: messaging-app
Expand Down
36 changes: 36 additions & 0 deletions chatbot/deployment/postgres/cron-backup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: messaging-postgres-backup
labels:
app: messaging
app_context: messaging
env: staging
spec:
schedule: "0 0 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: db-backup
image: postgres:16
command:
- /bin/sh
- -c
- pg_dump -h messaging-postgres.default.svc.cluster.local -U postgres -d messaging -f /backup/messaging-db-backup-$(date +'%s').sql
env:
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: messaging-secrets
key: messaging-db-password
volumeMounts:
- name: messaging-postgres-backup-volume
mountPath: /backup
volumes:
- name: messaging-postgres-backup-volume
persistentVolumeClaim:
claimName: messaging-postgres-backup-volume-claim

restartPolicy: Never
3 changes: 3 additions & 0 deletions chatbot/deployment/postgres/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: messaging-postgres
labels:
app: messaging
env: staging
spec:
selector:
matchLabels:
Expand Down
18 changes: 17 additions & 1 deletion chatbot/deployment/postgres/pv-claim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@ kind: PersistentVolumeClaim
metadata:
name: messaging-postgres-volume-claim
labels:
app: messaging-postgres
app: messaging
env: staging
spec:
storageClassName: manual
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: messaging-postgres-backup-volume-claim
labels:
app: messaging
env: staging
spec:
storageClassName: manual
accessModes:
Expand Down
21 changes: 20 additions & 1 deletion chatbot/deployment/postgres/pv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ metadata:
name: messaging-postgres-volume
labels:
type: local
app: messaging-postgres
app: messaging
env: staging
spec:
storageClassName: manual
capacity:
Expand All @@ -13,3 +14,21 @@ spec:
- ReadWriteMany
hostPath:
path: /data/messaging-postgresql
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: messaging
labels:
type: local
app: messaging-postgres-backup
app_context: messaging
env: staging
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
hostPath:
path: /nfs_mount/messaging-postgresql-backup
3 changes: 2 additions & 1 deletion chatbot/deployment/postgres/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ kind: Service
metadata:
name: messaging-postgres
labels:
app: messaging-postgres
app: messaging
env: staging
spec:
ports:
- port: 5432
Expand Down
3 changes: 3 additions & 0 deletions chatbot/deployment/redis/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: messaging-redis
labels:
app: messaging
env: staging
spec:
selector:
matchLabels:
Expand Down
3 changes: 2 additions & 1 deletion chatbot/deployment/redis/pv-claim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ kind: PersistentVolumeClaim
metadata:
name: messaging-redis-volume-claim
labels:
app: messaging-redis
app: messaging
env: staging
spec:
storageClassName: manual
accessModes:
Expand Down
3 changes: 2 additions & 1 deletion chatbot/deployment/redis/pv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ metadata:
name: messaging-redis-volume
labels:
type: local
app: messaging-redis
app: messaging
env: staging
spec:
storageClassName: manual
capacity:
Expand Down
Loading

0 comments on commit 8a1a384

Please sign in to comment.