# Example Infrastructure Template\n\nThis is a complete, ready-to-deploy example of a simple web application stack.\n\n## What's Included\n\n- **2 Web servers** - Load-balanced frontend\n- **1 Database server** - Backend database\n- **Complete configuration** - Ready to deploy with minimal changes\n- **Usage instructions** - Step-by-step deployment guide\n\n## Architecture\n\n```\n┌─────────────────────────────────────────┐\n│         Internet / Load Balancer        │\n└─────────────┬───────────────────────────┘\n              │\n      ┌───────┴───────┐\n      │               │\n┌─────▼─────┐   ┌────▼──────┐\n│ demo-web-01│   │demo-web-02│\n│  (Public)  │   │  (Public) │\n└─────┬──────┘   └────┬──────┘\n      │               │\n      └───────┬───────┘\n              │\n              │ Private Network\n              │\n        ┌─────▼──────┐\n        │ demo-db-01 │\n        │  (Private) │\n        └────────────┘\n```\n\n## Quick Start\n\n### 1. Load Required Provider\n\n```\ncd infra/<your-infra-name>\n\n# Load your cloud provider\nprovisioning mod load providers . upcloud\n# OR\nprovisioning mod load providers . aws\n```\n\n### 2. Configure Provider Settings\n\nEdit `servers.k` and uncomment provider-specific settings:\n\n**UpCloud example:**\n\n```\nplan = "1xCPU-2GB"      # Web servers\n# plan = "2xCPU-4GB"    # Database server (larger)\nstorage_size = 25        # Disk size in GB\n```\n\n**AWS example:**\n\n```\ninstance_type = "t3.small"  # Web servers\n# instance_type = "t3.medium" # Database server\nstorage_size = 25\n```\n\n### 3. Load Optional Task Services\n\n```\n# For container support\nprovisioning mod load taskservs . containerd\n\n# For additional services\nprovisioning mod load taskservs . docker redis nginx\n```\n\n### 4. Deploy\n\n```\n# Test configuration first\nkcl run servers.k\n\n# Dry-run to see what will be created\nprovisioning s create --infra <name> --check\n\n# Deploy the infrastructure\nprovisioning s create --infra <name>\n\n# Monitor deployment\nwatch provisioning s list --infra <name>\n```\n\n### 5. Verify Deployment\n\n```\n# List all servers\nprovisioning s list --infra <name>\n\n# SSH into web server\nprovisioning s ssh demo-web-01\n\n# Check database server\nprovisioning s ssh demo-db-01\n```\n\n## Configuration Details\n\n### Web Servers (demo-web-01, demo-web-02)\n\n- **Networking**: Public IPv4 + Private IPv4\n- **Purpose**: Frontend application servers\n- **Load balancing**: Configure externally\n- **Resources**: Minimal (1-2 CPU, 2-4GB RAM)\n\n### Database Server (demo-db-01)\n\n- **Networking**: Private IPv4 only (no public access)\n- **Purpose**: Backend database\n- **Security**: Isolated on private network\n- **Resources**: Medium (2-4 CPU, 4-8GB RAM)\n\n## Next Steps\n\n### Application Deployment\n\n1. **Deploy application code** - Use SSH or CI/CD\n2. **Configure web servers** - Set up Nginx/Apache\n3. **Set up database** - Install PostgreSQL/MySQL\n4. **Configure connectivity** - Connect web servers to database\n\n### Security Hardening\n\n1. **Firewall rules** - Lock down server access\n2. **SSH keys** - Disable password auth\n3. **Database access** - Restrict to web servers only\n4. **SSL certificates** - Set up HTTPS\n\n### Monitoring & Backup\n\n1. **Monitoring** - Set up metrics collection\n2. **Logging** - Configure centralized logging\n3. **Backups** - Set up database backups\n4. **Alerts** - Configure alerting\n\n### Scaling\n\n1. **Add more web servers** - Copy web-02 definition\n2. **Database replication** - Add read replicas\n3. **Load balancer** - Configure external LB\n4. **Auto-scaling** - Set up scaling policies\n\n## Customization\n\n### Change Server Count\n\n```\n# Add more web servers\n{\n    hostname = "demo-web-03"\n    # ... copy configuration from web-01\n}\n```\n\n### Change Resource Sizes\n\n```\n# Web servers\nplan = "2xCPU-4GB"      # Increase resources\n\n# Database\nplan = "4xCPU-8GB"      # More resources for DB\nstorage_size = 100       # Larger disk\n```\n\n### Add Task Services\n\n```\ntaskservs = [\n    { name = "containerd", profile = "default" }\n    { name = "docker", profile = "default" }\n    { name = "redis", profile = "default" }\n]\n```\n\n## Common Issues\n\n### Deployment Fails\n\n- Check provider credentials\n- Verify network configuration\n- Check resource quotas\n\n### Can't SSH\n\n- Verify SSH key is loaded\n- Check firewall rules\n- Ensure server is running\n\n### Database Connection\n\n- Verify private network\n- Check firewall rules between web and DB\n- Test connectivity from web servers\n\n## Template Characteristics\n\n- **Complexity**: Medium\n- **Servers**: 3 (2 web + 1 database)\n- **Pre-configured modules**: Provider only\n- **Best for**: Quick demos, learning deployments, testing infrastructure code
