This repository contains the Terraform infrastructure-as-code for deploying a complete Kubernetes-based gaming platform on AWS. The platform uses EKS (Elastic Kubernetes Service) and provides a comprehensive set of DevOps tools for continuous delivery, monitoring, and backup.
The infrastructure consists of the following major components:
- ๐ AWS Networking: VPC with public and private subnets across multiple availability zones
- โธ๏ธ EKS Cluster: Managed Kubernetes with autoscaling node groups
- ๐ข GitOps with ArgoCD: Continuous delivery of Kubernetes applications
- ๐ Monitoring Stack: Prometheus and Grafana for observability
- ๐ Ingress Controller: NGINX for exposing services
- ๐ Certificate Management: Automatic TLS certificate provisioning
- ๐พ Backup Solution: Velero for Kubernetes backup and restore capabilities
- Creates a VPC with public and private subnets across multiple availability zones
- Provisions NAT gateways for private subnet connectivity
- Sets up security groups for public and private resources
- Adds proper tagging for Kubernetes load balancer integration
- Deploys an EKS cluster with managed node groups
- Configures AWS EBS CSI driver for persistent storage
- Sets up IAM roles for service accounts (IRSA)
- Creates a default
gp3storage class - Configures AWS Auth mapping for cluster access
- Deploys cert-manager for automatic TLS certificate management
- Configures Let's Encrypt as the certificate issuer
- Supports automatic certificate renewal
- Deploys NGINX Ingress Controller as a DaemonSet
- Configures an Network Load Balancer for incoming traffic
- Supports TCP services for game server connectivity
- Deploys Prometheus for metrics collection
- Configures Grafana for dashboards and visualization
- Sets up AlertManager with Slack integration
- Provisions ingress for web access to Grafana
- Deploys ArgoCD for GitOps-based application deployment
- Configures application projects and repositories
- Sets up synchronization for database and core applications
- Provisions ingress for web access to ArgoCD UI
- Deploys Velero for Kubernetes backup and disaster recovery
- Creates S3 bucket for backup storage
- Configures scheduled backups with retention policies
- Sets up IAM roles for S3 and EBS snapshot access
- Configures S3 backend for Terraform state storage
- Uses DynamoDB for state locking
- Provides better reliability for the infrastructure initialization
- Repository: GitHub-hosted container image
- Architecture: Stateless deployment with 2 replicas
- Configuration:
- Runs on port 10300 with TCP ingress
- Connects to database via secure connection string
- Customisable environment variables via the configmap
- Ready to use: OpenDAoC Database Dump bootstraped into a MariaDB docker image
- Database: MariaDB-based stateful set with 3 replicas
- Storage: Persistent volumes using EBS gp3 storage class to enable the snapshot capability
- TO-DO:
- MariaDB replication to the secondary Statefulset pods for a full HA DB
ArgoCD manages both database and game server applications:
- Application definitions stored in Git (version controlled)
- Automatic synchronization from Git to cluster
- Sequential deployment (database before game server)
- Secrets injected at runtime from Terraform variables
The following security best practices are implemented:
-
๐งฑ Network Segmentation:
- Workloads run in private subnets
- Public subnets only used for load balancers
- Security groups limit traffic between components
-
๐ก๏ธ Least Privilege IAM:
- Service-specific IAM roles with minimal permissions
- IAM roles for service accounts to avoid instance profiles
- No use of AWS access keys in pods
-
๐ Secret Management:
- Sensitive variables marked with
sensitive = true - Secrets templating for GitOps workflows
- Avoidance of hardcoded credentials
- Base64 encoding for sensitive configuration values
- Sensitive variables marked with
-
๐ TLS Everywhere:
- Automatic TLS certificate provisioning
- SSL passthrough for sensitive services
- Force SSL redirection
-
โ๏ธ Kubernetes Security:
- Private API endpoint with controlled access
- AWS Auth configmap for IAM-based access control
- Default EBS volume encryption
-
๐ Backup and Disaster Recovery:
- Automated daily backups with Velero
- 30-day backup retention policy
- Volume snapshots for stateful workloads
-
๐ก Monitoring and Alerting:
- Comprehensive metrics collection with Prometheus
- Visual dashboards with Grafana
- Slack notifications for critical alerts
-
๐ Continuous Delivery:
- GitOps workflow with ArgoCD
- Application configuration as code
- Automated synchronization with git repositories
-
๐ Infrastructure as Code:
- Complete infrastructure defined in Terraform
- Modular design for reusability
- Version controlled infrastructure changes
The repository includes the following CI/CD workflows:
-
๐ Deploy Infrastructure (deploy-infra.yaml):
- Security scanning with tfsec and checkov
- Terraform state initialization
- Infrastructure deployment
- Updates DNS records for all services
- Points to the Load Balancer endpoint
- Supports manual and automated execution
-
๐งน Destroy Infrastructure (destroy-infra.yaml):
- Safe destruction with confirmation checks
- Cleanup of Kubernetes resources
- State infrastructure cleanup
- AWS Account with appropriate permissions
- Domain name for services (Grafana, ArgoCD, Game Server)
- GitHub repository for application code
- Terraform 1.5.7 or later
- AWS CLI configured with appropriate credentials
Clone the repository and navigate to the terraform directory:
git clone https://github.com/gz-42/devops-opendaoc.git
cd terraformInitialize the S3 backend for state storage:
cd tfstate-init
terraform init
terraform applyNote the output values for bucket name and DynamoDB table.
Create a secret file with your configuration values or set them as GitHub repository secrets for CI/CD.
You can also put your own values in the main terraform variables.yaml file. If you do so, i recommend to do it in a private repo or localy to not expose sensitive informations.
If you want to deploy it on a local cluster you can use the manifests in the repo or adapt the helm charts to your needs.
Either deploy using the GitHub Actions workflow or manually:
terraform init \
-backend-config="bucket=YOUR_STATE_BUCKET" \
-backend-config="key=terraform.tfstate" \
-backend-config="region=YOUR_REGION" \
-backend-config="dynamodb_table=YOUR_DYNAMODB_TABLE"
terraform plan -out=tfplan
terraform apply tfplanAfter deployment, you can access the services at:
- ArgoCD: https://argocd.yourdomain.com
- Grafana: https://grafana.yourdomain.com
- Game Server: your-game-server.yourdomain.com (port 10300)
To access the gameserver, you will need to download the OpenDAoC Client and follow the instructions on the official website
https://www.opendaoc.com/docs/client/-
๐ฆ Modular Structure:
- Each component is a separate Terraform module
- Clear inputs and outputs for modules
- Reusable infrastructure components
-
๐ท๏ธ Resource Tagging:
- Consistent tagging strategy
- Environment, project, and terraform-managed tags
- Proper Kubernetes tags for auto-discovery
-
๐ Version Pinning:
- Terraform providers have version constraints
- Helm charts use specific versions
- AWS module versions are pinned
-
โ Variable Validation:
- Variables have descriptions
- Sensitive data is marked
- Default values where appropriate
-
๐ฆ State Management:
- Remote state with locking
- State separation for critical components
- CI/CD integration
-
๐ ๏ธ Error Handling:
- Graceful destruction hooks
- Dependencies clearly defined
- Timeout configurations for long-running operations
-
๐ Secret Management:
- Template-based secret injection
- No plain text secrets in code
- Secret rotation support
-
๐ High Availability:
- Multi-AZ deployment
- Redundant NAT gateways
- Autoscaling node groups
- TO-DO:
- Database replication with 3-node MariaDB cluster
- Fork the repository
- Create a feature branch
- Make your changes
- Run security scans
- Submit a pull request
DevOps-OpenDAoC and OpenDAoC are licensed under the GNU General Public License (GPL) v3 to serve the DAoC community and promote open-source development. See the LICENSE file for more details.