2025-11-30 09:12:40 +01:00
|
|
|
apiVersion: apps/v1
|
|
|
|
|
kind: Deployment
|
|
|
|
|
metadata:
|
|
|
|
|
name: distribution-service
|
|
|
|
|
namespace: bakery-ia
|
|
|
|
|
labels:
|
|
|
|
|
app.kubernetes.io/name: distribution-service
|
|
|
|
|
app.kubernetes.io/component: microservice
|
|
|
|
|
app.kubernetes.io/part-of: bakery-ia
|
|
|
|
|
spec:
|
|
|
|
|
replicas: 2
|
|
|
|
|
selector:
|
|
|
|
|
matchLabels:
|
|
|
|
|
app.kubernetes.io/name: distribution-service
|
|
|
|
|
app.kubernetes.io/component: microservice
|
|
|
|
|
template:
|
|
|
|
|
metadata:
|
|
|
|
|
labels:
|
|
|
|
|
app.kubernetes.io/name: distribution-service
|
|
|
|
|
app.kubernetes.io/component: microservice
|
|
|
|
|
spec:
|
|
|
|
|
initContainers:
|
|
|
|
|
# Wait for Redis to be ready
|
|
|
|
|
- name: wait-for-redis
|
|
|
|
|
image: redis:7.4-alpine
|
|
|
|
|
command:
|
|
|
|
|
- sh
|
|
|
|
|
- -c
|
|
|
|
|
- |
|
|
|
|
|
echo "Waiting for Redis to be ready..."
|
|
|
|
|
until redis-cli -h $REDIS_HOST -p $REDIS_PORT --tls --cert /tls/redis-cert.pem --key /tls/redis-key.pem --cacert /tls/ca-cert.pem -a "$REDIS_PASSWORD" ping | grep -q PONG; do
|
|
|
|
|
echo "Redis not ready yet, waiting..."
|
|
|
|
|
sleep 2
|
|
|
|
|
done
|
|
|
|
|
echo "Redis is ready!"
|
|
|
|
|
env:
|
|
|
|
|
- name: REDIS_HOST
|
|
|
|
|
valueFrom:
|
|
|
|
|
configMapKeyRef:
|
|
|
|
|
name: bakery-config
|
|
|
|
|
key: REDIS_HOST
|
|
|
|
|
- name: REDIS_PORT
|
|
|
|
|
valueFrom:
|
|
|
|
|
configMapKeyRef:
|
|
|
|
|
name: bakery-config
|
|
|
|
|
key: REDIS_PORT
|
|
|
|
|
- name: REDIS_PASSWORD
|
|
|
|
|
valueFrom:
|
|
|
|
|
secretKeyRef:
|
|
|
|
|
name: redis-secrets
|
|
|
|
|
key: REDIS_PASSWORD
|
|
|
|
|
volumeMounts:
|
|
|
|
|
- name: redis-tls
|
|
|
|
|
mountPath: /tls
|
|
|
|
|
readOnly: true
|
2026-01-19 11:55:17 +01:00
|
|
|
# Wait for database migration to complete
|
2025-11-30 09:12:40 +01:00
|
|
|
- name: wait-for-migration
|
|
|
|
|
image: postgres:17-alpine
|
|
|
|
|
command:
|
|
|
|
|
- sh
|
|
|
|
|
- -c
|
|
|
|
|
- |
|
|
|
|
|
echo "Waiting for distribution database and migrations to be ready..."
|
|
|
|
|
# Wait for database to be accessible
|
|
|
|
|
until pg_isready -h $DISTRIBUTION_DB_HOST -p $DISTRIBUTION_DB_PORT -U $DISTRIBUTION_DB_USER; do
|
|
|
|
|
echo "Database not ready yet, waiting..."
|
|
|
|
|
sleep 2
|
|
|
|
|
done
|
|
|
|
|
echo "Database is ready!"
|
2026-01-19 11:55:17 +01:00
|
|
|
|
|
|
|
|
# Verify that migrations have completed by checking for the alembic_version table
|
|
|
|
|
ATTEMPTS=30
|
|
|
|
|
COUNT=0
|
|
|
|
|
until [ $COUNT -ge $ATTEMPTS ]; do
|
|
|
|
|
if PGPASSWORD="$DISTRIBUTION_DB_PASSWORD" psql -h "$DISTRIBUTION_DB_HOST" -p "$DISTRIBUTION_DB_PORT" -U "$DISTRIBUTION_DB_USER" -d "$DISTRIBUTION_DB_NAME" -c "\dt alembic_version" > /dev/null 2>&1; then
|
|
|
|
|
echo "Migrations are complete - alembic_version table exists"
|
|
|
|
|
exit 0
|
|
|
|
|
else
|
|
|
|
|
echo "Migrations not complete yet, waiting... ($((COUNT + 1))/$ATTEMPTS)"
|
|
|
|
|
sleep 10
|
|
|
|
|
fi
|
|
|
|
|
COUNT=$((COUNT + 1))
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
echo "Timeout waiting for migrations to complete"
|
|
|
|
|
exit 1
|
2025-11-30 09:12:40 +01:00
|
|
|
env:
|
|
|
|
|
- name: DISTRIBUTION_DB_HOST
|
|
|
|
|
valueFrom:
|
|
|
|
|
configMapKeyRef:
|
|
|
|
|
name: bakery-config
|
|
|
|
|
key: DISTRIBUTION_DB_HOST
|
|
|
|
|
- name: DISTRIBUTION_DB_PORT
|
|
|
|
|
valueFrom:
|
|
|
|
|
configMapKeyRef:
|
|
|
|
|
name: bakery-config
|
|
|
|
|
key: DB_PORT
|
|
|
|
|
- name: DISTRIBUTION_DB_USER
|
|
|
|
|
valueFrom:
|
|
|
|
|
secretKeyRef:
|
|
|
|
|
name: database-secrets
|
|
|
|
|
key: DISTRIBUTION_DB_USER
|
2026-01-19 11:55:17 +01:00
|
|
|
- name: DISTRIBUTION_DB_PASSWORD
|
|
|
|
|
valueFrom:
|
|
|
|
|
secretKeyRef:
|
|
|
|
|
name: database-secrets
|
|
|
|
|
key: DISTRIBUTION_DB_PASSWORD
|
|
|
|
|
- name: DISTRIBUTION_DB_NAME
|
|
|
|
|
value: "distribution_db"
|
2025-11-30 09:12:40 +01:00
|
|
|
containers:
|
|
|
|
|
- name: distribution-service
|
|
|
|
|
image: bakery/distribution-service:latest
|
|
|
|
|
imagePullPolicy: IfNotPresent
|
|
|
|
|
ports:
|
|
|
|
|
- containerPort: 8000
|
|
|
|
|
name: http
|
2026-01-19 11:55:17 +01:00
|
|
|
env:
|
|
|
|
|
# OpenTelemetry Configuration
|
|
|
|
|
- name: OTEL_COLLECTOR_ENDPOINT
|
|
|
|
|
value: "http://signoz-otel-collector.bakery-ia.svc.cluster.local:4318"
|
|
|
|
|
- name: OTEL_EXPORTER_OTLP_ENDPOINT
|
|
|
|
|
valueFrom:
|
|
|
|
|
configMapKeyRef:
|
|
|
|
|
name: bakery-config
|
|
|
|
|
key: OTEL_EXPORTER_OTLP_ENDPOINT
|
|
|
|
|
- name: OTEL_SERVICE_NAME
|
|
|
|
|
value: "distribution-service"
|
|
|
|
|
- name: ENABLE_TRACING
|
|
|
|
|
value: "true"
|
|
|
|
|
# Logging Configuration
|
|
|
|
|
- name: OTEL_LOGS_EXPORTER
|
|
|
|
|
value: "otlp"
|
|
|
|
|
- name: OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED
|
|
|
|
|
value: "true"
|
2025-11-30 09:12:40 +01:00
|
|
|
envFrom:
|
|
|
|
|
- configMapRef:
|
|
|
|
|
name: bakery-config
|
|
|
|
|
- secretRef:
|
|
|
|
|
name: database-secrets
|
|
|
|
|
- secretRef:
|
|
|
|
|
name: redis-secrets
|
|
|
|
|
- secretRef:
|
|
|
|
|
name: rabbitmq-secrets
|
|
|
|
|
- secretRef:
|
|
|
|
|
name: jwt-secrets
|
2026-01-19 11:55:17 +01:00
|
|
|
resources:
|
|
|
|
|
requests:
|
|
|
|
|
memory: "256Mi"
|
|
|
|
|
cpu: "100m"
|
|
|
|
|
limits:
|
|
|
|
|
memory: "512Mi"
|
|
|
|
|
cpu: "500m"
|
2025-11-30 09:12:40 +01:00
|
|
|
livenessProbe:
|
|
|
|
|
httpGet:
|
2026-01-19 11:55:17 +01:00
|
|
|
path: /health/live
|
2025-11-30 09:12:40 +01:00
|
|
|
port: 8000
|
|
|
|
|
initialDelaySeconds: 30
|
|
|
|
|
timeoutSeconds: 5
|
2026-01-19 11:55:17 +01:00
|
|
|
periodSeconds: 10
|
|
|
|
|
failureThreshold: 3
|
2025-11-30 09:12:40 +01:00
|
|
|
readinessProbe:
|
|
|
|
|
httpGet:
|
2026-01-19 11:55:17 +01:00
|
|
|
path: /health/ready
|
2025-11-30 09:12:40 +01:00
|
|
|
port: 8000
|
2026-01-19 11:55:17 +01:00
|
|
|
initialDelaySeconds: 15
|
2025-11-30 09:12:40 +01:00
|
|
|
timeoutSeconds: 3
|
2026-01-19 11:55:17 +01:00
|
|
|
periodSeconds: 5
|
|
|
|
|
failureThreshold: 5
|
2025-12-17 20:50:22 +01:00
|
|
|
securityContext:
|
|
|
|
|
runAsUser: 1000
|
|
|
|
|
runAsGroup: 1000
|
|
|
|
|
allowPrivilegeEscalation: false
|
|
|
|
|
readOnlyRootFilesystem: false
|
2025-11-30 09:12:40 +01:00
|
|
|
volumeMounts:
|
|
|
|
|
- name: redis-tls
|
|
|
|
|
mountPath: /tls
|
|
|
|
|
readOnly: true
|
|
|
|
|
volumes:
|
|
|
|
|
- name: redis-tls
|
|
|
|
|
secret:
|
|
|
|
|
secretName: redis-tls-secret
|
2026-01-19 11:55:17 +01:00
|
|
|
defaultMode: 0400
|
|
|
|
|
|
2025-11-30 09:12:40 +01:00
|
|
|
---
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: Service
|
|
|
|
|
metadata:
|
|
|
|
|
name: distribution-service
|
|
|
|
|
namespace: bakery-ia
|
|
|
|
|
labels:
|
|
|
|
|
app.kubernetes.io/name: distribution-service
|
|
|
|
|
app.kubernetes.io/component: microservice
|
|
|
|
|
app.kubernetes.io/part-of: bakery-ia
|
|
|
|
|
spec:
|
2026-01-19 11:55:17 +01:00
|
|
|
type: ClusterIP
|
|
|
|
|
ports:
|
|
|
|
|
- port: 8000
|
|
|
|
|
targetPort: 8000
|
|
|
|
|
protocol: TCP
|
|
|
|
|
name: http
|
2025-11-30 09:12:40 +01:00
|
|
|
selector:
|
|
|
|
|
app.kubernetes.io/name: distribution-service
|
|
|
|
|
app.kubernetes.io/component: microservice
|