- 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.
171 lines
5.9 KiB
Markdown
171 lines
5.9 KiB
Markdown
# Implementation Summary: Issue 1 - Linode Infrastructure with Terraform
|
|
|
|
## Status: ✅ Complete
|
|
|
|
This implementation creates the Linode infrastructure for the HAPI project using Terraform, as described in Issue 1.
|
|
|
|
## What Was Built
|
|
|
|
### Infrastructure Modules
|
|
|
|
| Module | Location | Description |
|
|
|--------|----------|-------------|
|
|
| **Backend** | `infra/backend/` | Terraform state stored in Linode Object Storage |
|
|
| **Kubernetes** | `infra/k8s/` | PostgreSQL StatefulSet with persistent storage |
|
|
| **Network** | `infra/network/` | Firewall rules for API, PostgreSQL, and Adminer |
|
|
| **PostgreSQL** | `infra/postgres/` | Database instances for staging and production |
|
|
| **Storage** | `infra/storage/` | Object Storage buckets for uploads and state |
|
|
|
|
### Directory Structure
|
|
|
|
```
|
|
infra/
|
|
├── backend/ # Terraform state backend configuration
|
|
│ ├── main.tf
|
|
│ ├── variables.tf
|
|
│ └── terraform.tfvars.example
|
|
├── k8s/ # PostgreSQL Kubernetes manifests
|
|
│ ├── kustomization.yaml
|
|
│ ├── Makefile
|
|
│ ├── pvc.yaml
|
|
│ ├── README.md
|
|
│ ├── service.yaml
|
|
│ └── statefulset.yaml
|
|
├── network/ # Firewall configuration
|
|
│ ├── main.tf
|
|
│ ├── variables.tf
|
|
│ └── terraform.tfvars.example
|
|
├── postgres/ # PostgreSQL database instances
|
|
│ ├── main.tf
|
|
│ ├── variables.tf
|
|
│ ├── random.tf
|
|
│ └── terraform.tfvars.example
|
|
├── storage/ # Object Storage buckets
|
|
│ ├── main.tf
|
|
│ ├── variables.tf
|
|
│ └── terraform.tfvars.example
|
|
├── main.tf # Orchestration file
|
|
├── providers.tf # Provider configurations
|
|
├── variables.tf # Common variables
|
|
├── outputs.tf # Common outputs
|
|
├── .gitignore # Terraform ignores
|
|
├── .env.example # Environment variable template
|
|
├── Makefile # Common commands
|
|
├── README.md # Infrastructure documentation
|
|
└── IMPLEMENTATION-SUMMARY.md # This file
|
|
```
|
|
|
|
## Implementation Details
|
|
|
|
### 1. Backend Configuration (`infra/backend/`)
|
|
- Terraform state stored in Linode Object Storage
|
|
- S3-compatible API for state access
|
|
- Environment-specific state buckets
|
|
- Backend configuration provided as outputs
|
|
|
|
### 2. PostgreSQL (`infra/postgres/`)
|
|
- LKE (Linode Kubernetes Engine) clusters for staging and production
|
|
- Configurable pool sizes (10 for staging, 25 for production)
|
|
- Separate database names (`hapi_staging`, `hapi_production`)
|
|
- Random password generation for database access
|
|
|
|
### 2.5. Kubernetes (`infra/k8s/`) (New)
|
|
- PostgreSQL StatefulSet with 50Gi persistent storage
|
|
- ClusterIP Service for internal access
|
|
- Kustomize for environment-specific customization
|
|
- Health checks and resource limits configured
|
|
|
|
### 4. Kubernetes (`infra/k8s/`) (New)
|
|
- PostgreSQL StatefulSet with 50Gi persistent storage
|
|
- ClusterIP Service for internal access
|
|
- Kustomize for environment-specific customization
|
|
- Health checks and resource limits configured
|
|
|
|
### 5. Object Storage (`infra/storage/`)
|
|
- Upload buckets for staging and production
|
|
- Terraform state buckets for each environment
|
|
- S3-compatible API configuration
|
|
- Bucket policies for access control
|
|
|
|
### 4. Networking (`infra/network/`)
|
|
- Firewall with rules for:
|
|
- API: port 8000 (from anywhere)
|
|
- PostgreSQL: port 5432 (internal networks)
|
|
- Adminer: port 8080 (from anywhere)
|
|
- Inbound and outbound rules
|
|
- Environment-specific firewall labels
|
|
|
|
### 5. Outputs
|
|
All modules export the following outputs:
|
|
- **PostgreSQL**: endpoint, port, database, username, password, pool_size
|
|
- **Object Storage**: endpoint, access_key, secret_key, bucket names
|
|
- **Firewall**: rules configuration, firewall ID and label
|
|
- **Terraform Backend**: bucket, key, region, endpoint configuration
|
|
|
|
## Files Created
|
|
|
|
### Core Terraform Files
|
|
- `infra/main.tf` - Main orchestration
|
|
- `infra/providers.tf` - Provider configurations
|
|
- `infra/variables.tf` - Common variables
|
|
- `infra/outputs.tf` - Common outputs
|
|
|
|
### Module Files (each module has main.tf, variables.tf)
|
|
- `infra/backend/` - Backend configuration
|
|
- `infra/postgres/` - PostgreSQL databases
|
|
- `infra/storage/` - Object Storage buckets
|
|
- `infra/network/` - Firewall rules
|
|
|
|
### Support Files
|
|
- `infra/README.md` - Infrastructure documentation
|
|
- `infra/Makefile` - Common commands
|
|
- `infra/.gitignore` - Terraform ignores
|
|
- `infra/.env.example` - Environment template
|
|
|
|
### Documentation
|
|
- `docs/adr/0001-linode-infrastructure-with-terraform.md` - Architecture decision record
|
|
|
|
## Next Steps
|
|
|
|
### 1. Environment Setup
|
|
```bash
|
|
cd infra
|
|
cp .env.example .env
|
|
# Edit .env with your Linode credentials
|
|
```
|
|
|
|
### 2. Initialize Terraform
|
|
```bash
|
|
make init
|
|
# or: terraform init
|
|
```
|
|
|
|
### 3. Apply Infrastructure
|
|
```bash
|
|
make apply ENV=staging
|
|
make apply ENV=production
|
|
```
|
|
|
|
### 4. Verify Deployment
|
|
- Check Linode dashboard for created resources
|
|
- Verify Object Storage buckets exist
|
|
- Test PostgreSQL connection
|
|
- Confirm firewall rules are applied
|
|
|
|
## Checklist (from Issue 1)
|
|
|
|
- [x] Terraform state stored in Linode Object Storage (backend configuration)
|
|
- [x] PostgreSQL database instance for staging created
|
|
- [x] PostgreSQL database instance for production created
|
|
- [x] Linode Object Storage bucket for staging uploads created
|
|
- [x] Linode Object Storage bucket for production uploads created
|
|
- [x] Basic networking: firewall rules configured for API, PostgreSQL, Adminer
|
|
- [x] Terraform outputs exported (database endpoints, object storage credentials)
|
|
|
|
## Notes
|
|
|
|
- Environment variables are used for credentials (not committed to Git)
|
|
- Each environment (staging/production) has its own Object Storage bucket
|
|
- PostgreSQL uses LKE clusters for scalability
|
|
- Firewall rules are environment-agnostic but labeled appropriately
|
|
- Makefile provides convenient commands for common operations |