Skip to content

Commit f7ef00c

Browse files
authored
Add VPC Native subnets in GCP (#311)
More details: https://cloud.google.com/kubernetes-engine/docs/concepts/alias-ips In order to do VPC peering and support a direct pod to pod communications VPC native clusters are required
1 parent fd3a7d2 commit f7ef00c

File tree

6 files changed

+25
-8
lines changed

6 files changed

+25
-8
lines changed

infra/aws/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ variable "name_prefix" {
1515
variable "cidr" {
1616
type = string
1717
description = "cidr"
18-
default = "172.20.0.0/16"
18+
default = "172.16.0.0/12"
1919
}
2020

2121
variable "tsb_image_sync_username" {

infra/azure/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ variable "name_prefix" {
1616
variable "cidr" {
1717
type = string
1818
description = "cidr"
19-
default = "172.20.0.0/16"
19+
default = "172.16.0.0/12"
2020
}
2121

2222
variable "tsb_image_sync_username" {

infra/gcp/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ variable "name_prefix" {
1616
variable "cidr" {
1717
type = string
1818
description = "cidr"
19-
default = "172.20.0.0/16"
19+
default = "172.16.0.0/12"
2020
}
2121

2222
variable "tsb_image_sync_username" {

modules/gcp/base/main.tf

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,24 @@ data "google_compute_zones" "available" {
4848
}
4949

5050
resource "google_compute_subnetwork" "tsb" {
51-
count = min(var.min_az_count, var.max_az_count)
51+
count = 1
5252
name = "${var.name_prefix}-subnet${data.google_compute_zones.available.names[count.index]}"
5353

5454
project = var.project_id
5555
region = var.region
5656
network = google_compute_network.tsb.self_link
5757

58-
ip_cidr_range = cidrsubnet(var.cidr, 4, count.index)
58+
ip_cidr_range = cidrsubnet(var.cidr, 2, count.index)
59+
60+
secondary_ip_range {
61+
range_name = "pods"
62+
ip_cidr_range = cidrsubnet(var.cidr, 2, count.index + 1)
63+
}
64+
65+
secondary_ip_range {
66+
range_name = "services"
67+
ip_cidr_range = cidrsubnet(var.cidr, 2, count.index + 2)
68+
}
5969
}
6070

6171
resource "google_compute_router_nat" "tsb" {

modules/gcp/k8s/main.tf

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ resource "google_container_cluster" "tsb" {
1414
min_master_version = var.k8s_version
1515
network = var.vpc_id
1616
subnetwork = var.vpc_subnet
17+
networking_mode = "VPC_NATIVE"
18+
datapath_provider = "ADVANCED_DATAPATH"
1719

1820
# We can't create a cluster with no node pool defined, but we want to only use
1921
# separately managed node pools. So we create the smallest possible default
@@ -22,9 +24,14 @@ resource "google_container_cluster" "tsb" {
2224
initial_node_count = 1
2325

2426
resource_labels = merge(var.tags, {
25-
name = "${var.cluster_name}_tsb_sandbox_blue"
27+
name = "${var.cluster_name}_tsb_sandbox_blue"
2628
})
2729

30+
ip_allocation_policy {
31+
cluster_secondary_range_name = "pods"
32+
services_secondary_range_name = "services"
33+
}
34+
2835
depends_on = [
2936
google_project_service.container
3037
]
@@ -39,7 +46,7 @@ resource "google_container_node_pool" "primary_nodes" {
3946

4047
node_config {
4148
preemptible = var.preemptible_nodes
42-
machine_type = "e2-standard-4"
49+
machine_type = "e2-standard-8"
4350

4451
# Google recommends custom service accounts that have cloud-platform scope and permissions granted via IAM Roles.
4552
service_account = data.google_compute_default_service_account.default.email

modules/gcp/k8s/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ variable "output_path" {
2828
}
2929

3030
variable "tags" {
31-
type = map
31+
type = map(any)
3232
}

0 commit comments

Comments
 (0)