Initial commit.
This commit is contained in:
1
postgres/README.md
Normal file
1
postgres/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# Postgress app
|
||||
54
postgres/deployment.yaml
Normal file
54
postgres/deployment.yaml
Normal file
@@ -0,0 +1,54 @@
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: postgres-deployment
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: postgres
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: postgres
|
||||
spec:
|
||||
containers:
|
||||
- name: postgres
|
||||
image: "{{ .apps.postgres.image }}"
|
||||
args:
|
||||
[
|
||||
"-c",
|
||||
"tcp_keepalives_idle=600",
|
||||
"-c",
|
||||
"tcp_keepalives_interval=30",
|
||||
"-c",
|
||||
"tcp_keepalives_count=3",
|
||||
"-c",
|
||||
"statement_timeout=300000",
|
||||
"-c",
|
||||
"idle_in_transaction_session_timeout=600000",
|
||||
]
|
||||
ports:
|
||||
- containerPort: 5432
|
||||
env:
|
||||
- name: PGDATA
|
||||
value: /var/lib/postgresql/data/pgdata
|
||||
- name: TZ
|
||||
value: "{{ .apps.postgres.timezone }}"
|
||||
- name: POSTGRES_DB
|
||||
value: "{{ .apps.postgres.database }}"
|
||||
- name: POSTGRES_USER
|
||||
value: "{{ .apps.postgres.user }}"
|
||||
- name: POSTGRES_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: postgres-secrets
|
||||
key: apps.postgres.password
|
||||
volumeMounts:
|
||||
- name: postgres-data
|
||||
mountPath: /var/lib/postgresql/data
|
||||
volumes:
|
||||
- name: postgres-data
|
||||
persistentVolumeClaim:
|
||||
claimName: postgres-pvc
|
||||
11
postgres/doctor/kustomization.yaml
Normal file
11
postgres/doctor/kustomization.yaml
Normal file
@@ -0,0 +1,11 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
namespace: postgres
|
||||
resources:
|
||||
- test-job.yaml
|
||||
labels:
|
||||
- includeSelectors: true
|
||||
pairs:
|
||||
app: postgres-doctor
|
||||
managedBy: kustomize
|
||||
partOf: wild-cloud
|
||||
77
postgres/doctor/test-job.yaml
Normal file
77
postgres/doctor/test-job.yaml
Normal file
@@ -0,0 +1,77 @@
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: postgres-doctor
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: postgres-doctor
|
||||
image: pgvector/pgvector:pg15
|
||||
command: ["/bin/bash", "-c"]
|
||||
args:
|
||||
- |
|
||||
echo "=== Postgres Doctor - Starting Tests ==="
|
||||
echo "Timestamp: $(date)"
|
||||
echo "Password from env: [${POSTGRES_PASSWORD}]"
|
||||
echo "Job pod IP: $(hostname -i)"
|
||||
echo "Postgres service resolves to: $(getent hosts postgres.postgres.svc.cluster.local | awk '{print $1}')"
|
||||
echo
|
||||
|
||||
# Test 1: Local connection (trust auth)
|
||||
echo "TEST 1: Local connection with trust authentication"
|
||||
if psql -h localhost -U postgres -c "SELECT 'Local connection: SUCCESS' as test_result;" 2>&1; then
|
||||
echo "✓ Local connection: SUCCESS"
|
||||
else
|
||||
echo "✗ Local connection: FAILED"
|
||||
fi
|
||||
echo
|
||||
|
||||
# Test 2: Remote connection with password
|
||||
echo "TEST 2: Remote connection with password authentication"
|
||||
if PGPASSWORD="${POSTGRES_PASSWORD}" psql -h postgres.postgres.svc.cluster.local -U postgres -c "SELECT 'Remote connection: SUCCESS' as test_result;" 2>&1; then
|
||||
echo "✓ Remote connection: SUCCESS"
|
||||
else
|
||||
echo "✗ Remote connection: FAILED"
|
||||
fi
|
||||
echo
|
||||
|
||||
# Test 3: Check postgres version and extensions
|
||||
echo "TEST 3: Check postgres version and available extensions"
|
||||
PGPASSWORD="${POSTGRES_PASSWORD}" psql -h postgres.postgres.svc.cluster.local -U postgres -c "SELECT version();"
|
||||
PGPASSWORD="${POSTGRES_PASSWORD}" psql -h postgres.postgres.svc.cluster.local -U postgres -c "SELECT name FROM pg_available_extensions WHERE name IN ('vector', 'cube', 'earthdistance') ORDER BY name;"
|
||||
echo
|
||||
|
||||
# Test 4: List all databases
|
||||
echo "TEST 4: List all databases"
|
||||
PGPASSWORD="${POSTGRES_PASSWORD}" psql -h postgres.postgres.svc.cluster.local -U postgres -c "\l"
|
||||
echo
|
||||
|
||||
# Test 5: List all users
|
||||
echo "TEST 5: List all users and their attributes"
|
||||
PGPASSWORD="${POSTGRES_PASSWORD}" psql -h postgres.postgres.svc.cluster.local -U postgres -c "\du"
|
||||
echo
|
||||
|
||||
# Test 6: Check authentication configuration
|
||||
echo "TEST 6: Check pg_hba.conf authentication rules"
|
||||
PGPASSWORD="${POSTGRES_PASSWORD}" psql -h postgres.postgres.svc.cluster.local -U postgres -c "SELECT type, database, user_name, address, auth_method FROM pg_hba_file_rules WHERE auth_method IS NOT NULL ORDER BY line_number;"
|
||||
echo
|
||||
|
||||
# Test 7: Check active connections
|
||||
echo "TEST 7: Check active database connections"
|
||||
PGPASSWORD="${POSTGRES_PASSWORD}" psql -h postgres.postgres.svc.cluster.local -U postgres -c "SELECT datname, usename, client_addr, state, query_start FROM pg_stat_activity WHERE state IS NOT NULL ORDER BY query_start DESC;"
|
||||
echo
|
||||
|
||||
# Test 9: Check for long-running queries
|
||||
echo "TEST 9: Check for long-running queries (> 30 seconds)"
|
||||
PGPASSWORD="${POSTGRES_PASSWORD}" psql -h postgres.postgres.svc.cluster.local -U postgres -c "SELECT pid, now() - pg_stat_activity.query_start AS duration, query FROM pg_stat_activity WHERE query_start IS NOT NULL AND now() - pg_stat_activity.query_start > interval '30 seconds' ORDER BY duration DESC;"
|
||||
echo
|
||||
|
||||
echo "=== Postgres Doctor - Tests Complete ==="
|
||||
env:
|
||||
- name: POSTGRES_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: postgres-secrets
|
||||
key: apps.postgres.password
|
||||
restartPolicy: Never
|
||||
14
postgres/kustomization.yaml
Normal file
14
postgres/kustomization.yaml
Normal file
@@ -0,0 +1,14 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
namespace: postgres
|
||||
labels:
|
||||
- includeSelectors: true
|
||||
pairs:
|
||||
app: postgres
|
||||
managedBy: kustomize
|
||||
partOf: wild-cloud
|
||||
resources:
|
||||
- deployment.yaml
|
||||
- namespace.yaml
|
||||
- service.yaml
|
||||
- pvc.yaml
|
||||
13
postgres/manifest.yaml
Normal file
13
postgres/manifest.yaml
Normal file
@@ -0,0 +1,13 @@
|
||||
name: postgres
|
||||
install: true
|
||||
description: PostgreSQL is a powerful, open source object-relational database system.
|
||||
version: 1.0.0
|
||||
icon: https://www.postgresql.org/media/img/about/press/elephant.png
|
||||
defaultConfig:
|
||||
database: postgres
|
||||
user: postgres
|
||||
storage: 10Gi
|
||||
image: pgvector/pgvector:pg15
|
||||
timezone: UTC
|
||||
requiredSecrets:
|
||||
- apps.postgres.password
|
||||
4
postgres/namespace.yaml
Normal file
4
postgres/namespace.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: postgres
|
||||
12
postgres/pvc.yaml
Normal file
12
postgres/pvc.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: postgres-pvc
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
storageClassName: longhorn
|
||||
resources:
|
||||
requests:
|
||||
storage: {{ .apps.postgres.storage | default "10Gi" }}
|
||||
10
postgres/service.yaml
Normal file
10
postgres/service.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: postgres
|
||||
spec:
|
||||
ports:
|
||||
- port: 5432
|
||||
selector:
|
||||
app: postgres
|
||||
Reference in New Issue
Block a user