Skip to content

tasnimmizaoui/production-platform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Production Platform - AWS Free Tier

A production-grade platform built on AWS completely free using cost-optimization strategies and infrastructure best practices.

Terraform AWS K3s Cost


🎯 Project Goals

Build a real production platform for learning, demonstrating:

  • βœ… Infrastructure as Code (Terraform)
  • βœ… Cost Optimization ($0/month vs $505/year standard AWS)
  • βœ… Kubernetes Orchestration (K3s cluster)
  • βœ… Networking Best Practices (VPC, NAT, security groups)
  • βœ… Security Hardening (private subnets, Session Manager, flow logs)
  • βœ… Microservices Architecture (Go API, Worker, Redis)
  • βœ… CI/CD Pipeline (Docker, automated deployments)
  • βœ… Monitoring & Observability (Prometheus, Grafana, Loki)

Perfect for:

  • πŸ“š Learning DevOps/SRE practices
  • πŸš€ Small production workloads

πŸ“Š Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ AWS VPC (10.0.0.0/16)                               β”‚
β”‚                                                      β”‚
β”‚  Public Subnet                Private Subnet        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚
β”‚  β”‚ NAT Instance│──────────────→│ K3s Master  β”‚      β”‚
β”‚  β”‚ (t2.micro)  β”‚              β”‚ (t3.micro)  β”‚      β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜              β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜      β”‚
β”‚         β”‚                             β”‚             β”‚
β”‚         β”‚                     β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”      β”‚
β”‚         β”‚                     β”‚ K3s Worker   β”‚      β”‚
β”‚         β”‚                     β”‚ (t3.micro)   β”‚      β”‚
β”‚         β”‚                     β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚
β”‚         β”‚                            β”‚              β”‚
β”‚         β”‚                            β–Ό              β”‚
β”‚         β”‚                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚
β”‚         β”‚                   β”‚ Pods:          β”‚      β”‚
β”‚         β”‚                   β”‚ β€’ API Service  β”‚      β”‚
β”‚         β”‚                   β”‚ β€’ Worker       β”‚      β”‚
β”‚         β”‚                   β”‚ β€’ Redis        β”‚      β”‚
β”‚         β”‚                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚
β”‚         β–Ό                                           β”‚
β”‚   Internet Gateway                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
    Internet

πŸ’° Cost Breakdown

Traditional AWS Setup

Component Monthly Cost
NAT Gateway $32.85
Bastion Host (t2.micro) $8.47
K3s Master (t3.micro) $7.59
K3s Worker (t3.micro) $7.59
EBS Storage (40GB) $4.00
TOTAL $60.50/month

This Project (Free Tier Optimized)

Component Monthly Cost
NAT Instance (t2.micro) $0 (free tier)
Session Manager $0 (no bastion)
K3s Master (t3.micro) $0 (free tier)
K3s Worker (t3.micro) $0 (free tier)
EBS Storage (30GB) $0 (free tier)
TOTAL $0/month βœ…

Annual Savings: $726 πŸ’Έ


πŸš€ Quick Start

Prerequisites

# Required tools
terraform >= 1.0
aws-cli >= 2.0
kubectl >= 1.24

# AWS credentials configured
aws configure

Deploy Infrastructure

# Clone repository
git clone https://github.com/tasnimmizaoui/production-platform
cd production-platform

# Configure variables
cp infra/terraform/terraform.tfvars.example infra/terraform/terraform.tfvars
# Edit terraform.tfvars with your IP address

# Get your IP
curl ifconfig.me

# Deploy
cd infra/terraform
terraform init
terraform plan
terraform apply

Deployment time: ~15-20 minutes ⏱️

Access Your Cluster

# Get kubeconfig
terraform output kubeconfig_command | bash > ~/.kube/config

# Verify cluster
kubectl get nodes
kubectl get pods -A

# Access K3s master
aws ssm start-session --target $(terraform output -raw k3s_master_id)

πŸ“ Project Structure

production-platform/
β”œβ”€β”€ app/                          # Application code
β”‚   β”œβ”€β”€ api-service/             # Go REST API
β”‚   β”œβ”€β”€ worker-service/          # Background workers
β”‚   └── frontend/                # not set up yet
β”‚
β”œβ”€β”€ infra/                       # Infrastructure as Code
β”‚   └── terraform/
β”‚       β”œβ”€β”€ main.tf              # Root configuration
β”‚       β”œβ”€β”€ modules/
β”‚       β”‚   β”œβ”€β”€ vpc/             # VPC + NAT instance
β”‚       β”‚   └── k3s/             # K3s cluster
β”‚       └── terraform.tfvars     # Your variables
β”‚
β”œβ”€β”€ k8s/                         # Kubernetes manifests
β”‚   β”œβ”€β”€ base/                    # Base configs
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ worker/
β”‚   β”‚   └── redis/
β”‚   └── overlays/                # Environment overlays
β”‚       β”œβ”€β”€ dev/
β”‚       └── prod/
β”‚
β”œβ”€β”€ monitoring/                  # Observability stack
β”‚   β”œβ”€β”€ prometheus/
β”‚   β”œβ”€β”€ grafana/
β”‚   └── loki/
β”‚
β”‚
β”œβ”€β”€ docs/                       # Documentation
β”‚   
β”‚
└── scripts/                    # Helper scripts
    β”œβ”€β”€ deploy.sh
    └── test-deployment.sh

πŸ—οΈ Infrastructure Components

Phase 1: Networking βœ… COMPLETE

  • VPC (10.0.0.0/16)
  • Public & Private subnets
  • Internet Gateway
  • NAT Instance (free alternative to NAT Gateway)
  • VPC Flow Logs (S3)
  • S3 VPC Endpoint
  • Verified: All connectivity tests passing

Phase 2: Compute βœ… COMPLETE

  • K3s master node (t3.micro)
  • K3s worker node (t3.micro)
  • Redis (in-cluster pod)
  • IAM roles & instance profiles
  • Session Manager access
  • Verified: 2/2 nodes Ready, pods running

Phase 3: Applications πŸ“‹ NEXT

  • Deploy API service to K3s
  • Deploy worker service
  • Configure ingress
  • Test end-to-end workflow

Phase 4: CI/CD Pipeline πŸš€

  • GitHub Actions workflow
  • Automated testing (Go tests)
  • Docker image builds
  • Kind cluster validation
  • Automated deployments

Phase 5: VPC Endpoints + Docker Proxy (Enterprise) 🎯

  • S3-backed Docker registry mirror
  • Zero-egress network architecture
  • Air-gapped cluster security
  • Automated image synchronization

πŸ” Security Features

  • βœ… Private Subnets - No public IPs on workloads
  • βœ… NAT Instance - Controlled egress
  • βœ… Security Groups - Restrictive firewall rules
  • βœ… Network ACLs - Additional layer
  • βœ… VPC Flow Logs - Network monitoring
  • βœ… Session Manager - No SSH keys needed
  • βœ… Encrypted EBS - Data at rest encryption
  • βœ… IP Whitelisting - Access limited to your IP

πŸ“Š Key Innovations

1. NAT Instance ($32/month savings)

Instead of AWS NAT Gateway ($32.85/month), we use a t2.micro instance:

# IP forwarding + iptables
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Benefits:

  • $0 cost (free tier)
  • Full control & debugging access
  • Production-ready for small workloads
  • Learning opportunity for NAT mechanics

Trade-offs:

  • Single point of failure (no HA)
  • Manual scaling required
  • Limited throughput vs NAT Gateway

Real Implementation:

  • βœ… Verified working with K3s cluster
  • βœ… Internet access from private subnet confirmed
  • βœ… Health monitoring configured
  • βœ… $394/year savings vs NAT Gateway

Read Complete Implementation Guide β†’

2. Session Manager Access ($8/month savings)

No bastion host needed! Access instances via AWS Systems Manager:

aws ssm start-session --target i-0abc123def456

Benefits:

  • $0 cost
  • No SSH keys to manage
  • IAM-based authentication
  • Session logging

3. K3s Lightweight Kubernetes

Full Kubernetes experience with minimal overhead:

  • 512MB RAM vs 2GB (standard K8s)
  • Single binary installation
  • Built-in storage, networking
  • Perfect for learning & small workloads

πŸ“š Documentation


πŸ§ͺ Testing

# Verify NAT instance
aws ssm start-session --target $(terraform output -raw nat_instance_id)
cat /proc/sys/net/ipv4/ip_forward  # Should be: 1

# Test K3s cluster
kubectl get nodes
kubectl get pods -A

# Test connectivity from private subnet
aws ssm start-session --target $(terraform output -raw k3s_master_id)
curl -I https://google.com  # Should work via NAT

# Run deployment tests
./scripts/test-deployment.sh

πŸ› οΈ Troubleshooting

NAT Instance Not Working

# Check source/dest check (must be false)
aws ec2 describe-instances --instance-ids <nat-id> \
  --query 'Reservations[0].Instances[0].SourceDestCheck'

# Check iptables
aws ssm start-session --target <nat-id>
sudo iptables -t nat -L -n -v

K3s Pods Not Starting

kubectl describe pod <pod-name>
kubectl logs <pod-name>
kubectl get events --sort-by=.metadata.creationTimestamp

Can't Access Internet from Private Subnet

# From private instance
ip route  
traceroute 8.8.8.8  # S

# Check NAT instance
aws ssm start-session --target <nat-id>
cat /proc/sys/net/ipv4/ip_forward  # Must be: 1
sudo iptables -t nat -L POSTROUTING -n -v  # Must show MASQUERADE rule

Complete Troubleshooting Guide β†’


πŸŽ“ Learning Outcomes

Terraform Skills

  • Module development
  • State management
  • Dependency management
  • Count and conditionals

AWS Networking

  • VPC architecture
  • NAT functionality
  • Security groups vs NACLs
  • VPC endpoints

Kubernetes

  • Cluster setup
  • Pod networking
  • Service discovery
  • Storage management

Linux Systems

  • IP forwarding
  • iptables/netfilter
  • systemd services
  • Shell scripting

DevOps Practices

  • Infrastructure as Code
  • Cost optimization
  • Security hardening
  • Monitoring/observability

πŸ“ˆ Roadmap

  • Phase 1: VPC networking with NAT instance
  • Phase 2: K3s cluster deployment (2 nodes + Redis)
  • Phase 3: Application deployment (API + Worker services) on local cluster
  • Phase 4: CI/CD pipeline (GitHub Actions + Kind testing)
  • Phase 5: VPC endpoints + Docker proxy (enterprise security)
  • Phase 6: Monitoring stack (Prometheus, Grafana, Loki)
  • Phase 7: Service mesh (Linkerd)
  • Phase 8: Auto-scaling & high availability

Current Status: Infrastructure verified and working. Ready for application deployment! πŸš€


πŸ™ Acknowledgments

  • K3s - Lightweight Kubernetes by Rancher
  • Terraform - Infrastructure as Code by HashiCorp
  • AWS - Cloud infrastructure
  • Community - Best practices and inspiration

πŸ“„ License

MIT License - Feel free to use this project for learning and portfolio purposes.


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors