REFACTOR external service and improve websocket training
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
# infrastructure/kubernetes/base/components/external/external-service.yaml
|
||||
# External Data Service v2.0 - Optimized city-based architecture
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
@@ -7,8 +9,9 @@ metadata:
|
||||
app.kubernetes.io/name: external-service
|
||||
app.kubernetes.io/component: microservice
|
||||
app.kubernetes.io/part-of: bakery-ia
|
||||
version: "2.0"
|
||||
spec:
|
||||
replicas: 1
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/name: external-service
|
||||
@@ -18,41 +21,30 @@ spec:
|
||||
labels:
|
||||
app.kubernetes.io/name: external-service
|
||||
app.kubernetes.io/component: microservice
|
||||
version: "2.0"
|
||||
spec:
|
||||
initContainers:
|
||||
- name: wait-for-migration
|
||||
- name: check-data-initialized
|
||||
image: postgres:15-alpine
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
echo "Waiting for external database and migrations to be ready..."
|
||||
# Wait for database to be accessible
|
||||
until pg_isready -h $EXTERNAL_DB_HOST -p $EXTERNAL_DB_PORT -U $EXTERNAL_DB_USER; do
|
||||
echo "Database not ready yet, waiting..."
|
||||
sleep 2
|
||||
done
|
||||
echo "Database is ready!"
|
||||
# Give migrations extra time to complete after DB is ready
|
||||
echo "Waiting for migrations to complete..."
|
||||
sleep 10
|
||||
echo "Ready to start service"
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
echo "Checking if data initialization is complete..."
|
||||
# Convert asyncpg URL to psql-compatible format
|
||||
DB_URL=$(echo "$DATABASE_URL" | sed 's/postgresql+asyncpg:/postgresql:/')
|
||||
until psql "$DB_URL" -c "SELECT COUNT(*) FROM city_weather_data LIMIT 1;" > /dev/null 2>&1; do
|
||||
echo "Waiting for initial data load..."
|
||||
sleep 10
|
||||
done
|
||||
echo "Data is initialized"
|
||||
env:
|
||||
- name: EXTERNAL_DB_HOST
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: bakery-config
|
||||
key: EXTERNAL_DB_HOST
|
||||
- name: EXTERNAL_DB_PORT
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: bakery-config
|
||||
key: DB_PORT
|
||||
- name: EXTERNAL_DB_USER
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: database-secrets
|
||||
key: EXTERNAL_DB_USER
|
||||
- name: DATABASE_URL
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: database-secrets
|
||||
key: EXTERNAL_DATABASE_URL
|
||||
|
||||
containers:
|
||||
- name: external-service
|
||||
image: bakery/external-service:latest
|
||||
|
||||
@@ -82,6 +82,10 @@ spec:
|
||||
name: pos-integration-secrets
|
||||
- secretRef:
|
||||
name: whatsapp-secrets
|
||||
volumeMounts:
|
||||
- name: model-storage
|
||||
mountPath: /app/models
|
||||
readOnly: true # Forecasting only reads models
|
||||
resources:
|
||||
requests:
|
||||
memory: "256Mi"
|
||||
@@ -105,6 +109,11 @@ spec:
|
||||
timeoutSeconds: 3
|
||||
periodSeconds: 5
|
||||
failureThreshold: 5
|
||||
volumes:
|
||||
- name: model-storage
|
||||
persistentVolumeClaim:
|
||||
claimName: model-storage
|
||||
readOnly: true # Forecasting only reads models
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
|
||||
@@ -85,6 +85,8 @@ spec:
|
||||
volumeMounts:
|
||||
- name: tmp-storage
|
||||
mountPath: /tmp
|
||||
- name: model-storage
|
||||
mountPath: /app/models
|
||||
resources:
|
||||
requests:
|
||||
memory: "512Mi"
|
||||
@@ -112,6 +114,9 @@ spec:
|
||||
- name: tmp-storage
|
||||
emptyDir:
|
||||
sizeLimit: 2Gi
|
||||
- name: model-storage
|
||||
persistentVolumeClaim:
|
||||
claimName: model-storage
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: model-storage
|
||||
namespace: bakery-ia
|
||||
labels:
|
||||
app.kubernetes.io/name: model-storage
|
||||
app.kubernetes.io/component: storage
|
||||
app.kubernetes.io/part-of: bakery-ia
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce # Single node access (works with local Kubernetes)
|
||||
resources:
|
||||
requests:
|
||||
storage: 10Gi # Adjust based on your needs
|
||||
storageClassName: standard # Use default local-path provisioner
|
||||
Reference in New Issue
Block a user