- Create infrastructure for PostgreSQL StatefulSet in Kubernetes - Implement environment-specific configurations (staging/production) - Add Kustomize overlays for deterministic deployments - Document deployment process in AGENTS.md and infra/k8s/README.md - Include Makefile and helper scripts for easy management New directories: - infra/k8s/base/ - Shared resources (StatefulSet, Service, PVC, Namespace) - infra/k8s/staging/ - Staging environment overlay - infra/k8s/production/ - Production environment overlay Key files: - infra/k8s/base/kustomization.yaml - infra/k8s/staging/kustomization.yaml - infra/k8s/production/kustomization.yaml - infra/k8s/README.md Resources are prefixed by environment (staging-, production-) and deployed to the postgres namespace.
54 lines
1.4 KiB
Bash
Executable File
54 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# Quickstart script for testing PostgreSQL k8s deployment
|
|
# Usage: ./quickstart.sh [environment]
|
|
|
|
set -e
|
|
|
|
ENVIRONMENT="${1:-staging}"
|
|
NAMESPACE="postgres"
|
|
|
|
echo "🚀 Starting PostgreSQL k8s deployment for $ENVIRONMENT..."
|
|
|
|
# Set environment variable
|
|
export ENVIRONMENT
|
|
export NAMESPACE
|
|
|
|
# Create namespace if not exists
|
|
echo "📝 Creating namespace $NAMESPACE..."
|
|
kubectl create namespace "$NAMESPACE" --dry-run=client -o yaml | kubectl apply -f -
|
|
|
|
# Apply Kustomize configuration
|
|
echo "🛠 Applying Kustomize configuration..."
|
|
kubectl apply -k .
|
|
|
|
# Wait for StatefulSet
|
|
echo "⏳ Waiting for StatefulSet to be ready..."
|
|
kubectl wait --for=condition=Ready pod -l app=postgres -n "$NAMESPACE" --timeout=300s
|
|
|
|
# Show status
|
|
echo "📊 Deployment status:"
|
|
echo ""
|
|
echo "StatefulSet:"
|
|
kubectl get statefulset postgres-statefulset -n "$NAMESPACE"
|
|
echo ""
|
|
echo "Pods:"
|
|
kubectl get pod -l app=postgres -n "$NAMESPACE"
|
|
echo ""
|
|
echo "PVC:"
|
|
kubectl get pvc -n "$NAMESPACE"
|
|
echo ""
|
|
echo "Service:"
|
|
kubectl get service postgres-service -n "$NAMESPACE"
|
|
|
|
# Test connectivity
|
|
echo ""
|
|
echo "🔌 Testing PostgreSQL connectivity..."
|
|
POD_NAME=$(kubectl get pod -l app=postgres -n "$NAMESPACE" -o jsonpath='{.items[0].metadata.name}')
|
|
kubectl exec -n "$NAMESPACE" "$POD_NAME" -- pg_isready -U postgres
|
|
|
|
echo ""
|
|
echo "✅ PostgreSQL deployment complete!"
|
|
echo ""
|
|
echo "To connect to PostgreSQL:"
|
|
echo " kubectl exec -n $NAMESPACE -l app=postgres -- psql -U postgres"
|