feat: Add PostgreSQL Kubernetes deployment with Kustomize
- 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.
This commit is contained in:
1 parent
9568d4ca6e
commit
88235fc824
26 files changed
+1407
-14
No files matched your search
@@ -0,0 +1,66 @@
|
||||
# Makefile for PostgreSQL Kubernetes deployment
|
||||
# Provides convenient commands for deploying and managing PostgreSQL
|
||||
|
||||
SHELL := /bin/bash
|
||||
ENVIRONMENT ?= staging
|
||||
POSTGRES_DB ?= hapi_$(ENVIRONMENT)
|
||||
|
||||
# Colors for output
|
||||
GREEN := \033[0;32m
|
||||
YELLOW := \033[0;33m
|
||||
RED := \033[0;31m
|
||||
NC := \033[0m
|
||||
|
||||
NAMESPACE ?= postgres
|
||||
|
||||
.PHONY: all apply delete status logs test psql
|
||||
|
||||
all: apply
|
||||
|
||||
## Apply the Kubernetes configuration
|
||||
apply:
|
||||
@echo "$(GREEN)Applying PostgreSQL configuration for $(ENVIRONMENT)...$(NC)"
|
||||
kubectl apply -k . --namespace=$(NAMESPACE) --context=$(CLUSTER_CONTEXT)
|
||||
|
||||
## Delete the PostgreSQL deployment
|
||||
delete:
|
||||
@echo "$(RED)Deleting PostgreSQL deployment for $(ENVIRONMENT)...$(NC)"
|
||||
kubectl delete -k . --namespace=$(NAMESPACE) --context=$(CLUSTER_CONTEXT)
|
||||
|
||||
## Show current status of all resources
|
||||
status:
|
||||
@echo "$(YELLOW)PostgreSQL Status for $(ENVIRONMENT):$(NC)"
|
||||
@echo "StatefulSet:"
|
||||
kubectl get statefulset postgres-statefulset --namespace=$(NAMESPACE)
|
||||
@echo ""
|
||||
@echo "Pods:"
|
||||
kubectl get pod -l app=postgres --namespace=$(NAMESPACE)
|
||||
@echo ""
|
||||
@echo "PVC:"
|
||||
kubectl get pvc postgres-pvc --namespace=$(NAMESPACE)
|
||||
@echo ""
|
||||
@echo "Service:"
|
||||
kubectl get service postgres-service --namespace=$(NAMESPACE)
|
||||
|
||||
## Show PostgreSQL logs
|
||||
logs:
|
||||
@echo "$(YELLOW)PostgreSQL Logs for $(ENVIRONMENT):$(NC)"
|
||||
kubectl logs -l app=postgres --namespace=$(NAMESPACE) --tail=100
|
||||
|
||||
## Test PostgreSQL connectivity
|
||||
test:
|
||||
@echo "$(GREEN)Testing PostgreSQL connectivity...$(NC)"
|
||||
POD_NAME=$$(kubectl get pod -l app=postgres -n $(NAMESPACE) -o jsonpath='{.items[0].metadata.name}') && \
|
||||
kubectl exec -it $${POD_NAME} -n $(NAMESPACE) -- pg_isready -U postgres -d $(POSTGRES_DB)
|
||||
|
||||
## Run psql shell in PostgreSQL pod
|
||||
psql:
|
||||
@echo "$(YELLOW)Opening psql shell...$(NC)"
|
||||
kubectl exec -it -l app=postgres -n $(NAMESPACE) -- psql -U postgres -d $(POSTGRES_DB)
|
||||
|
||||
## Show help
|
||||
help:
|
||||
@echo "$(GREEN)PostgreSQL Kubernetes Deployment$(NC)"
|
||||
@echo ""
|
||||
@echo "Available targets:"
|
||||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(YELLOW)%-15s$(NC) %s\n", $$1, $$2}'
|
||||
Reference in new issue
Block a user