Files
hapi/infra
Bobby 88235fc824 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.
2026-11-18 15:29:00 -05:00
..
2026-11-18 09:23:11 -05:00
2026-11-18 09:23:11 -05:00
2026-11-17 14:39:40 -05:00
2026-11-18 09:23:11 -05:00
2026-11-18 09:23:11 -05:00
2026-11-17 14:39:40 -05:00
2026-11-18 09:23:11 -05:00

HAPI Infrastructure with Terraform

This directory contains Terraform configurations for provisioning HAPI infrastructure on Linode.

Provider Version

This repository uses Linode Terraform Provider v2.0+ (~> 2.0). See docs/adr/0002-linode-provider-v2-migration.md for details on the migration from v1 to v2.

Key differences in v2:

  • Object Storage: cluster → region attribute
  • Firewall rules: Updated format with action, ipv4, ipv6
  • LKE: pools → pool block
  • Tags: Converted to set format (key=value strings)

Directory Structure

infra/
├── backend/          # Terraform state backend (Object Storage S3-compatible)
├── k8s/              # Kubernetes manifests for PostgreSQL StatefulSet
├── network/          # Firewall rules
├── postgres/         # PostgreSQL database instances (LKE clusters)
├── storage/          # Object Storage buckets
├── main.tf           # Main orchestration file
├── providers.tf      # Provider configurations
├── variables.tf      # Common variables
├── outputs.tf        # Common outputs
└── README.md         # This file

Directory Structure

infra/
├── backend/          # Terraform state backend configuration
├── postgres/         # PostgreSQL database instances
├── storage/          # Object Storage buckets
├── network/          # Firewall rules
├── main.tf           # Main orchestration file
├── variables.tf      # Common variables
├── outputs.tf        # Common outputs
└── README.md         # This file

Prerequisites

  • Linode account with API access
  • Linode CLI (linode-cli) or direct API access for Object Storage credentials
  • Terraform 1.9.0 or higher
  • Linode Terraform Provider v2.0+

Setup

1. Configure Linode API Token

export LINODE_TOKEN="your-linode-api-token"
export LINODE_REGION="us-east"

2. Create Object Storage Credentials

# Create access keys
linode-object-storage keys create

# Set environment variables
export OBJECT_STORAGE_ACCESS_KEY="your-access-key"
export OBJECT_STORAGE_SECRET_KEY="your-secret-key"

3. Initialize Terraform

cd infra
terraform init

4. Apply Infrastructure

# For staging
terraform apply -var="environment=staging"

# For production
terraform apply -var="environment=production"

Resources Provisioned

Kubernetes (New)

  • StatefulSet for PostgreSQL with persistent storage
  • PersistentVolumeClaim for 50Gi of block storage
  • Service for internal cluster access
  • Kustomize for environment-specific customization

Kubernetes (New)

  • StatefulSet for PostgreSQL with persistent storage
  • PersistentVolumeClaim for 50Gi of block storage
  • Service for internal cluster access
  • Kustomize for environment-specific customization

PostgreSQL

  • LKE (Linode Kubernetes Engine) cluster for staging and production
  • Database instances within clusters (hapi_staging, hapi_production)
  • Connection pooling configuration
  • Automated backups

Object Storage

  • Upload buckets for staging and production
  • Terraform state storage
  • S3-compatible API
  • Object Storage cluster configuration

Networking

  • Firewall rules for:
    • API (port 8000)
    • PostgreSQL (port 5432)
    • Adminer (port 8080)
  • Inbound and outbound rules with DROP policy by default
  • Environment-specific firewall labels

Outputs

  • PostgreSQL endpoint (Kubernetes API endpoint), port, database name, credentials
  • Object Storage endpoint, access keys
  • Firewall configuration (rules, ID, and label)
  • Terraform backend configuration

Environment-Specific Configuration

See backend/example.tfvars for example configuration values.

Deployment

Staging

  • Deployed automatically on main branch pushes
  • Uses staging Object Storage bucket
  • Lower resource allocation

Production

  • Deployed on version tags
  • Uses production Object Storage bucket
  • Higher resource allocation and HA configuration

Maintenance

Updating Terraform State

Terraform state is automatically stored in Linode Object Storage under the configured bucket and key path.

Adding New Resources

Add modules to main.tf and create corresponding directories under infra/ following the established pattern.

Provider v2 Migration Notes

The infrastructure has been migrated to Linode Provider v2. Key considerations:

  • Object Storage: Use region instead of cluster for bucket configuration
  • Firewall Rules: New format with action (ACCEPT/DROP), ipv4, and ipv6 instead of cidrs
  • Tags: Converted from map to set of key=value strings
  • LKE Pools: Block renamed from pools to pool

See docs/adr/0002-linode-provider-v2-migration.md for complete details.