This commit is contained in:
tusuii
2026-02-19 19:34:26 +05:30
commit 4b26a49776
8 changed files with 495 additions and 0 deletions

109
05-backend.yaml Normal file
View File

@@ -0,0 +1,109 @@
# Backend — Deployment + NodePort Service
#
# BEFORE APPLYING:
# Set the image to your built image, e.g.:
# youruser/ecommerce-backend:latest (Docker Hub)
# registry.local:5000/ecommerce-backend:latest (local registry)
#
# The init containers:
# 1. wait-for-postgres — polls until PostgreSQL is accepting connections
# 2. run-migrations — runs "prisma migrate deploy" once postgres is up
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: ecommerce-app
namespace: ecommerce
labels:
app: ecommerce-app
spec:
replicas: 1
selector:
matchLabels:
app: ecommerce-app
template:
metadata:
labels:
app: ecommerce-app
spec:
initContainers:
# Waits until PostgreSQL is ready before running migrations
- name: wait-for-postgres
image: postgres:15-alpine
imagePullPolicy: IfNotPresent
command:
- sh
- -c
- |
until pg_isready -h postgres -p 5432 -U vaishnavi; do
echo "Waiting for PostgreSQL..."; sleep 3
done
echo "PostgreSQL is ready."
# Runs Prisma migrations — uses the same backend image
- name: run-migrations
image: ecommerce-backend:latest # <-- same image as the main container
imagePullPolicy: IfNotPresent
command: ["sh", "-c", "npx prisma migrate deploy"]
envFrom:
- secretRef:
name: backend-secret
env:
- name: NODE_ENV
value: "production"
containers:
- name: ecommerce-app
image: ecommerce-backend:latest # <-- replace with your registry image
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
name: http
envFrom:
- configMapRef:
name: backend-config
- secretRef:
name: backend-secret
volumeMounts:
- name: uploads
mountPath: /app/uploads
resources:
requests:
cpu: "250m"
memory: "256Mi"
limits:
cpu: "500m"
memory: "512Mi"
readinessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 15
periodSeconds: 10
failureThreshold: 3
livenessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 30
periodSeconds: 20
failureThreshold: 3
volumes:
- name: uploads
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: ecommerce-app
namespace: ecommerce
spec:
type: NodePort
selector:
app: ecommerce-app
ports:
- name: http
port: 3000
targetPort: 3000
nodePort: 30300 # Access via http://<NODE_IP>:30300