zkt26/z2/k8s/deployment.yaml

83 lines
2.2 KiB
YAML

apiVersion: apps/v1
kind: Deployment
metadata:
name: todo-app
namespace: todo-app
labels:
app: todo-app
tier: frontend
spec:
replicas: 2
selector:
matchLabels:
app: todo-app
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
template:
metadata:
labels:
app: todo-app
tier: frontend
spec:
containers:
- name: todo-app
image: todo-app:latest
# Use local image built into minikube — never pull from registry
imagePullPolicy: Never
ports:
- containerPort: 5000
name: http
env:
- name: DB_HOST
value: "postgres-service.todo-app.svc.cluster.local"
- name: DB_NAME
value: "tododb"
- name: DB_USER
valueFrom:
secretKeyRef:
name: postgres-secret
key: POSTGRES_USER
- name: DB_PASS
valueFrom:
secretKeyRef:
name: postgres-secret
key: POSTGRES_PASSWORD
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "500m"
memory: "256Mi"
livenessProbe:
httpGet:
path: /health
port: 5000
initialDelaySeconds: 15
periodSeconds: 10
failureThreshold: 3
readinessProbe:
httpGet:
path: /health
port: 5000
initialDelaySeconds: 10
periodSeconds: 5
failureThreshold: 3
# Wait for postgres to be available before starting pods
initContainers:
- name: wait-for-postgres
image: busybox:1.36
command:
- sh
- -c
- |
echo "Waiting for PostgreSQL..."
until nc -z postgres-service.todo-app.svc.cluster.local 5432; do
echo "PostgreSQL not ready, sleeping 2s..."
sleep 2
done
echo "PostgreSQL is ready!"