-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Google Cloud Kubernetes cluster + AWS Firewall Rules #9915
Merged
+261
−12
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
35bc67b
working base cluster configuration
stevenplatt 14f1474
added gcloud project var
stevenplatt cfd7095
updated node types ad eks fw policy
stevenplatt d2b27a1
updated terraform outputs
stevenplatt af5efab
comment consistency
stevenplatt 97e74b2
updated machine types in gke cluster
stevenplatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we also need to allow the node port (8080) and the ethereum port (8545) ?