Files
k8s/01-postgres.yaml
tusuii 4b26a49776 k8s
2026-02-19 19:34:26 +05:30

87 lines
2.2 KiB
YAML

# PostgreSQL — PersistentVolumeClaim + Deployment + Service
# Credentials match the env file: user=vaishnavi pass=admin db=vaishnavi_db
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-data
namespace: ecommerce
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
# If your cluster has no default StorageClass, add: storageClassName: "local-path"
# For k3s clusters this is already set to local-path by default.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
namespace: ecommerce
labels:
app: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:15-alpine
ports:
- containerPort: 5432
env:
- name: POSTGRES_DB
value: "vaishnavi_db"
- name: POSTGRES_USER
value: "vaishnavi"
- name: POSTGRES_PASSWORD
value: "admin"
- name: PGDATA
value: "/var/lib/postgresql/data/pgdata"
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
resources:
requests:
cpu: "100m"
memory: "256Mi"
limits:
cpu: "500m"
memory: "512Mi"
readinessProbe:
exec:
command: ["pg_isready", "-U", "vaishnavi", "-d", "vaishnavi_db"]
initialDelaySeconds: 10
periodSeconds: 5
failureThreshold: 6
livenessProbe:
exec:
command: ["pg_isready", "-U", "vaishnavi", "-d", "vaishnavi_db"]
initialDelaySeconds: 30
periodSeconds: 10
volumes:
- name: postgres-data
persistentVolumeClaim:
claimName: postgres-data
---
apiVersion: v1
kind: Service
metadata:
name: postgres
namespace: ecommerce
spec:
type: ClusterIP
selector:
app: postgres
ports:
- port: 5432
targetPort: 5432