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
|
|
|
|
|
- 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!"
|
|
|
|
|
# Give migrations extra time to complete after DB is ready
|
|
|
|
|
echo "Waiting for migrations to complete..."
|
|
|
|
|
sleep 10
|
|
|
|
|
echo "Ready to start service"
|
|
|
|
|
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
|
|
|
|
|
containers:
|
|
|
|
|
- name: distribution-service
|
|
|
|
|
image: bakery/distribution-service:latest
|
|
|
|
|
imagePullPolicy: IfNotPresent
|
|
|
|
|
ports:
|
|
|
|
|
- containerPort: 8000
|
|
|
|
|
name: http
|
|
|
|
|
envFrom:
|
|
|
|
|
- configMapRef:
|
|
|
|
|
name: bakery-config
|
|
|
|
|
- secretRef:
|
|
|
|
|
name: database-secrets
|
|
|
|
|
- secretRef:
|
|
|
|
|
name: redis-secrets
|
|
|
|
|
- secretRef:
|
|
|
|
|
name: rabbitmq-secrets
|
|
|
|
|
- secretRef:
|
|
|
|
|
name: jwt-secrets
|
|
|
|
|
livenessProbe:
|
|
|
|
|
httpGet:
|
|
|
|
|
path: /health
|
|
|
|
|
port: 8000
|
|
|
|
|
initialDelaySeconds: 30
|
|
|
|
|
periodSeconds: 10
|
|
|
|
|
timeoutSeconds: 5
|
|
|
|
|
readinessProbe:
|
|
|
|
|
httpGet:
|
|
|
|
|
path: /health
|
|
|
|
|
port: 8000
|
|
|
|
|
initialDelaySeconds: 5
|
|
|
|
|
periodSeconds: 5
|
|
|
|
|
timeoutSeconds: 3
|
|
|
|
|
resources:
|
|
|
|
|
requests:
|
|
|
|
|
memory: "256Mi"
|
|
|
|
|
cpu: "250m"
|
|
|
|
|
limits:
|
|
|
|
|
memory: "512Mi"
|
|
|
|
|
cpu: "500m"
|
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
|
|
|
|
|
---
|
|
|
|
|
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:
|
|
|
|
|
selector:
|
|
|
|
|
app.kubernetes.io/name: distribution-service
|
|
|
|
|
app.kubernetes.io/component: microservice
|
|
|
|
|
ports:
|
|
|
|
|
- protocol: TCP
|
|
|
|
|
port: 8000
|
|
|
|
|
targetPort: 8000
|
|
|
|
|
name: http
|
|
|
|
|
type: ClusterIP
|