add alembic and store metrics at db

This commit is contained in:
2026-02-10 16:19:56 +04:00
parent f2a9520410
commit 3ff4b61492
17 changed files with 532 additions and 34 deletions

View File

@@ -18,7 +18,38 @@ spec:
ports:
- name: web
containerPort: 8000
readinessProbe:
exec:
command: ["alembic", "check"]
timeoutSeconds: 5
periodSeconds: 5
env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: db-secrets
key: url
---
apiVersion: batch/v1
kind: Job
metadata:
name: fastapi-app-db-migration
spec:
template:
spec:
containers:
- name: fastapi-app-db-migration
image: igit.danilkolesnikov.ru/danil/playground_app
command: ["alembic", "upgrade", "head"]
env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: db-secrets
key: url
restartPolicy: OnFailure
backoffLimit: 5
ttlSecondsAfterFinished: 1
---
apiVersion: v1
kind: Service

43
k8s/cnpg.yaml Normal file
View File

@@ -0,0 +1,43 @@
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: fastapi-pg
spec:
instances: 1
superuserSecret:
name: cluster-example-superuser
bootstrap:
initdb:
database: app
owner: app
secret:
name: cluster-example-app-user
storage:
size: 1Gi
---
apiVersion: v1
data:
password: cGFzc3dvcmQxMjMK
username: cG9zdGdyZXM=
kind: Secret
metadata:
name: cluster-example-superuser
type: kubernetes.io/basic-auth
---
apiVersion: v1
data:
password: VHhWZVE0bk44MlNTaVlIb3N3cU9VUlp2UURhTDRLcE5FbHNDRUVlOWJ3RHhNZDczS2NrSWVYelM1Y1U2TGlDMg==
username: YXBw
kind: Secret
metadata:
name: cluster-example-app-user
type: kubernetes.io/basic-auth
---
apiVersion: v1
kind: Secret
metadata:
name: db-secrets
type: Opaque
data:
url: cG9zdGdyZXNxbCtwc3ljb3BnMjovL2FwcDpUeFZlUTRuTjgyU1NpWUhvc3dxT1VSWnZRRGFMNEtwTkVsc0NFRWU5YndEeE1kNzNLY2tJZVh6UzVjVTZMaUMyQGZhc3RhcGktcGctcncvYXBw

View File

@@ -1,24 +0,0 @@
apiVersion: helm.cattle.io/v1
kind: HelmChart
metadata:
name: prometheus
namespace: kube-system
spec:
chart: kube-prometheus-stack
repo: https://prometheus-community.github.io/helm-charts
targetNamespace: monitoring
createNamespace: true
valuesContent: |-
prometheus:
prometheusSpec:
# Monitor all namespaces for ServiceMonitors
serviceMonitorSelectorNilUsesHelmValues: false
serviceMonitorNamespaceSelector: {}
# Monitor all namespaces for PodMonitors
podMonitorSelectorNilUsesHelmValues: false
podMonitorNamespaceSelector: {}
# Monitor all namespaces for PrometheusRules
ruleSelectorNilUsesHelmValues: false
ruleNamespaceSelector: {}