This repository contains the infrastructure code for deploying a Discord bot on Google Kubernetes Engine (GKE) with Redis caching.
- GKE Cluster: Runs the Discord bot and Redis
- Redis: In-cluster caching using StatefulSet
- Persistent Storage: For bot recordings and Redis data
- Monitoring: GCP monitoring with email alerts
- Backup: GCS bucket for backups
- Google Cloud SDK installed and configured
- Terraform installed
- kubectl installed
- Required GCP APIs enabled (handled by Terraform)
- Required environment variables:
- DISCORD_TOKEN
- OPENAI_API_KEY
- DISCORD_CLIENT_ID
- DISCORD_GUILD_ID
- DISCORD_BOT_IMAGE
- REDIS_PASSWORD
-
Initialize and Apply Terraform:
cd terraform/environments/prod cp terraform.tfvars.example terraform.tfvars # Edit terraform.tfvars with your values terraform init terraform apply
-
Configure kubectl:
gcloud container clusters get-credentials $(terraform output -raw cluster_name) \ --region $(terraform output -raw region) \ --project $(terraform output -raw project_id)
-
Deploy Kubernetes Resources:
cd ../../../k8s chmod +x deploy.sh ./deploy.sh
The following metrics are monitored:
- GKE Node CPU Usage
- GKE Node Memory Usage
- Discord Bot Pod Status
- Redis Pod Status
- Custom Log Metric for Bot Errors
Alerts will be sent to the configured email address.
Backups are stored in the configured GCS bucket. The backup schedule and retention policy can be configured in the Terraform variables.
.
├── terraform/
│ ├── environments/
│ │ └── prod/
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ └── terraform.tfvars
│ └── modules/
│ ├── apis/
│ ├── gke/
│ ├── monitoring/
│ ├── networking/
│ └── storage/
└── k8s/
├── discord-bot.yaml
├── redis.yaml
└── deploy.sh
- Scaling: Adjust
min_node_countandmax_node_countin terraform.tfvars - Monitoring: Configure alert thresholds in the monitoring module
- Backup: Adjust backup retention policy in the storage module
-
Pod Issues:
kubectl get pods kubectl describe pod <pod-name> kubectl logs <pod-name>
-
Redis Issues:
kubectl exec -it redis-0 -- redis-cli -a $REDIS_PASSWORD
-
Node Issues:
kubectl get nodes kubectl describe node <node-name>