64 lines
1.8 KiB
YAML
64 lines
1.8 KiB
YAML
apiVersion: apps/v1
|
|
kind: Deployment
|
|
metadata:
|
|
name: pg-demo
|
|
namespace: cnpg
|
|
spec:
|
|
replicas: 1
|
|
selector:
|
|
matchLabels:
|
|
app: pg-demo
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: pg-demo
|
|
spec:
|
|
containers:
|
|
- name: pg-demo
|
|
image: postgres:17
|
|
env:
|
|
- name: PGHOST
|
|
value: shared-postgres-rw
|
|
- name: PGPORT
|
|
value: "5432"
|
|
- name: PGUSER
|
|
value: app
|
|
- name: PGDATABASE
|
|
value: app
|
|
- name: PGPASSWORD
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: shared-postgres-app
|
|
key: password
|
|
command:
|
|
- /bin/bash
|
|
- -c
|
|
- |
|
|
echo "=== CNPG Demo App ==="
|
|
echo "Connecting to $PGHOST:$PGPORT/$PGDATABASE as $PGUSER..."
|
|
|
|
until pg_isready -h "$PGHOST" -p "$PGPORT" -U app -q; do
|
|
echo "Waiting for PostgreSQL..."
|
|
sleep 2
|
|
done
|
|
|
|
echo "Connected! Creating test table..."
|
|
psql -c "
|
|
CREATE TABLE IF NOT EXISTS visits (
|
|
id SERIAL PRIMARY KEY,
|
|
visited_at TIMESTAMP DEFAULT NOW(),
|
|
source TEXT DEFAULT 'pg-demo'
|
|
);
|
|
"
|
|
|
|
echo "Inserting visit..."
|
|
psql -c "INSERT INTO visits (source) VALUES ('pg-demo');"
|
|
|
|
echo ""
|
|
echo "Recent visits:"
|
|
psql -c "SELECT * FROM visits ORDER BY id DESC LIMIT 5;"
|
|
|
|
echo ""
|
|
echo "=== Keeping alive. Press Ctrl+C to stop. ==="
|
|
echo "Connection is working! Check with: kubectl logs -f deployment/pg-demo -n cnpg"
|
|
sleep infinity |