-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
261 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
terraform { | ||
backend "s3" { | ||
bucket = "aztec-terraform" | ||
key = "spartan-gke-cluster/terraform.tfstate" | ||
region = "eu-west-2" | ||
} | ||
required_providers { | ||
google = { | ||
source = "hashicorp/google" | ||
version = "~> 5.0" | ||
} | ||
} | ||
} | ||
|
||
# Configure the Google Cloud provider | ||
provider "google" { | ||
project = var.project | ||
region = var.region | ||
} | ||
|
||
# Create the service account | ||
resource "google_service_account" "gke_sa" { | ||
account_id = "gke-nodes-sa" | ||
display_name = "GKE Nodes Service Account" | ||
description = "Service account for GKE nodes" | ||
} | ||
|
||
# Add IAM roles to the service account | ||
resource "google_project_iam_member" "gke_sa_roles" { | ||
for_each = toset([ | ||
"roles/logging.logWriter", | ||
"roles/monitoring.metricWriter", | ||
"roles/monitoring.viewer", | ||
"roles/artifactregistry.reader" | ||
]) | ||
|
||
project = var.project | ||
role = each.key | ||
member = "serviceAccount:${google_service_account.gke_sa.email}" | ||
} | ||
|
||
# Create ingress firewall rule for UDP | ||
resource "google_compute_firewall" "udp_ingress" { | ||
name = "allow-udp-ingress-40400-40499" | ||
network = "default" | ||
|
||
allow { | ||
protocol = "udp" | ||
ports = ["40400-40499"] | ||
} | ||
|
||
direction = "INGRESS" | ||
source_ranges = ["0.0.0.0/0"] | ||
target_tags = ["gke-node"] | ||
} | ||
|
||
# Create egress firewall rule for UDP | ||
resource "google_compute_firewall" "udp_egress" { | ||
name = "allow-udp-egress-40400-40499" | ||
network = "default" | ||
|
||
allow { | ||
protocol = "udp" | ||
ports = ["40400-40499"] | ||
} | ||
|
||
direction = "EGRESS" | ||
destination_ranges = ["0.0.0.0/0"] | ||
target_tags = ["gke-node"] | ||
} | ||
|
||
# Create a GKE cluster | ||
resource "google_container_cluster" "primary" { | ||
name = "spartan-gke" | ||
location = var.zone | ||
initial_node_count = 1 | ||
|
||
# Remove default node pool after cluster creation | ||
remove_default_node_pool = true | ||
|
||
# Kubernetes version | ||
min_master_version = "latest" | ||
|
||
# Network configuration | ||
network = "default" | ||
subnetwork = "default" | ||
|
||
# Master auth configuration | ||
master_auth { | ||
client_certificate_config { | ||
issue_client_certificate = false | ||
} | ||
} | ||
} | ||
|
||
# Create primary node pool with autoscaling | ||
resource "google_container_node_pool" "primary_nodes" { | ||
name = "primary-node-pool" | ||
location = var.zone | ||
cluster = google_container_cluster.primary.name | ||
|
||
# Enable autoscaling | ||
autoscaling { | ||
min_node_count = 1 | ||
max_node_count = 5 | ||
} | ||
|
||
# Node configuration | ||
node_config { | ||
machine_type = "t2d-standard-16" | ||
|
||
service_account = google_service_account.gke_sa.email | ||
oauth_scopes = [ | ||
"https://www.googleapis.com/auth/cloud-platform" | ||
] | ||
|
||
labels = { | ||
env = "production" | ||
} | ||
|
||
tags = ["gke-node"] | ||
} | ||
|
||
# Management configuration | ||
management { | ||
auto_repair = true | ||
auto_upgrade = true | ||
} | ||
} | ||
|
||
# Create spot instance node pool with autoscaling | ||
resource "google_container_node_pool" "spot_nodes" { | ||
name = "spot-node-pool" | ||
location = var.zone | ||
cluster = google_container_cluster.primary.name | ||
|
||
# Enable autoscaling | ||
autoscaling { | ||
min_node_count = 0 | ||
max_node_count = 10 | ||
} | ||
|
||
# Node configuration | ||
node_config { | ||
machine_type = "t2d-standard-16" | ||
spot = true | ||
|
||
service_account = google_service_account.gke_sa.email | ||
oauth_scopes = [ | ||
"https://www.googleapis.com/auth/cloud-platform" | ||
] | ||
|
||
labels = { | ||
env = "production" | ||
pool = "spot" | ||
} | ||
|
||
tags = ["gke-node", "spot"] | ||
|
||
# Spot instance termination handler | ||
taint { | ||
key = "cloud.google.com/gke-spot" | ||
value = "true" | ||
effect = "NO_SCHEDULE" | ||
} | ||
} | ||
|
||
# Management configuration | ||
management { | ||
auto_repair = true | ||
auto_upgrade = true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
output "cluster_endpoint" { | ||
value = google_container_cluster.primary.endpoint | ||
} | ||
|
||
output "service_account_email" { | ||
value = google_service_account.gke_sa.email | ||
} | ||
|
||
output "region" { | ||
description = "Google cloud region" | ||
value = var.region | ||
} | ||
|
||
output "kubernetes_cluster_name" { | ||
description = "GKE Cluster Name" | ||
value = google_container_cluster.primary.name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
variable "project" { | ||
default = "testnet-440309" | ||
} | ||
|
||
variable "region" { | ||
default = "us-east4" | ||
} | ||
|
||
variable "zone" { | ||
default = "us-east4-a" | ||
} |