-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add gke island cluster anywhere in GCP design (#1967)
- Loading branch information
1 parent
329c08f
commit 6dd46d1
Showing
9 changed files
with
650 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# GKE island cluster anywhere in GCP design | ||
|
||
This example provisions a cluster in an island VPC allowing reuse of the IP address space for multiple clusters across different GCP organizations. | ||
|
||
## Deploy | ||
|
||
1. Create NCC hub. | ||
2. Update `ncc_hub_project_id`, `ncc_hub_name`, `network_name` and gke spokes in `terraform.tfvars`. | ||
3. Run `terraform apply`. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| gke\_spokes | n/a | `any` | n/a | yes | | ||
| ingress\_ip\_addrs\_subnet\_cidr | Subnet to use for reserving internal ip addresses for the ILBs. | `string` | n/a | yes | | ||
| master\_authorized\_networks | List of master authorized networks. If none are provided, disallow external access (except the cluster node IPs, which GKE automatically whitelists). | `list(object({ cidr_block = string, display_name = string }))` | n/a | yes | | ||
| ncc\_hub\_name | n/a | `string` | n/a | yes | | ||
| ncc\_hub\_project\_id | n/a | `string` | n/a | yes | | ||
| net\_attachment\_subnet\_cidr | Subnet for the router PSC interface network attachment in island network. | `string` | n/a | yes | | ||
| node\_locations | n/a | `list(string)` | n/a | yes | | ||
| primary\_net\_name | Primary VPC network name. | `string` | n/a | yes | | ||
| primary\_subnet | Subnet to use in primary network to deploy the router. | `string` | n/a | yes | | ||
| proxy\_subnet\_cidr | CIDR for the regional managed proxy subnet. | `string` | n/a | yes | | ||
| region | n/a | `string` | n/a | yes | | ||
| router\_machine\_type | n/a | `string` | n/a | yes | | ||
| secondary\_ranges | n/a | `map(string)` | n/a | yes | | ||
| subnet\_cidr | Primary subnet CIDR used by the cluster. | `string` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| cluster\_ids | n/a | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
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,93 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
resource "random_id" "rand" { | ||
byte_length = 4 | ||
} | ||
|
||
resource "google_service_account" "gke-sa" { | ||
for_each = { for k, v in var.gke_spokes : k => v } | ||
|
||
account_id = "gke-sa-${random_id.rand.hex}" | ||
project = each.value["project_id"] | ||
} | ||
|
||
module "gke" { | ||
source = "terraform-google-modules/kubernetes-engine/google//modules/beta-private-cluster" | ||
version = "~> 31.0" | ||
|
||
for_each = { for k, v in var.gke_spokes : k => v } | ||
|
||
name = each.value["cluster_name"] | ||
project_id = each.value["project_id"] | ||
region = var.region | ||
release_channel = "RAPID" | ||
zones = var.node_locations | ||
network = module.net[each.key].network_name | ||
subnetwork = "${each.value["cluster_name"]}-${var.region}-snet" | ||
ip_range_pods = "${each.value["cluster_name"]}-${var.region}-snet-pods" | ||
ip_range_services = "${each.value["cluster_name"]}-${var.region}-snet-services" | ||
enable_private_endpoint = true | ||
enable_private_nodes = true | ||
datapath_provider = "ADVANCED_DATAPATH" | ||
monitoring_enable_managed_prometheus = false | ||
enable_shielded_nodes = true | ||
master_global_access_enabled = false | ||
master_ipv4_cidr_block = var.secondary_ranges["master_cidr"] | ||
master_authorized_networks = var.master_authorized_networks | ||
deletion_protection = false | ||
remove_default_node_pool = true | ||
disable_default_snat = true | ||
gateway_api_channel = "CHANNEL_STANDARD" | ||
|
||
node_pools = [ | ||
{ | ||
name = "default" | ||
machine_type = "e2-highcpu-2" | ||
min_count = 1 | ||
max_count = 100 | ||
local_ssd_count = 0 | ||
spot = true | ||
local_ssd_ephemeral_count = 0 | ||
disk_size_gb = 100 | ||
disk_type = "pd-standard" | ||
image_type = "COS_CONTAINERD" | ||
logging_variant = "DEFAULT" | ||
auto_repair = true | ||
auto_upgrade = true | ||
service_account = google_service_account.gke-sa[each.key].email | ||
initial_node_count = 1 | ||
enable_secure_boot = true | ||
}, | ||
] | ||
|
||
node_pools_tags = { | ||
all = ["gke-${random_id.rand.hex}"] | ||
} | ||
|
||
node_pools_oauth_scopes = { | ||
all = [ | ||
"https://www.googleapis.com/auth/logging.write", | ||
"https://www.googleapis.com/auth/monitoring", | ||
] | ||
} | ||
|
||
timeouts = { | ||
create = "15m" | ||
update = "15m" | ||
delete = "15m" | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
examples/island_cluster_anywhere_in_gcp_design/manifests/k8s.yaml
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,88 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: whereami | ||
spec: | ||
replicas: 3 | ||
selector: | ||
matchLabels: | ||
app: whereami | ||
template: | ||
metadata: | ||
labels: | ||
app: whereami | ||
spec: | ||
containers: | ||
- name: whereami | ||
image: us-docker.pkg.dev/google-samples/containers/gke/whereami:v1.2.19 | ||
ports: | ||
- name: http | ||
containerPort: 8080 | ||
resources: | ||
requests: | ||
cpu: "50m" | ||
memory: 128Mi | ||
limits: | ||
cpu: "100m" | ||
memory: 256Mi | ||
readinessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: 8080 | ||
scheme: HTTP | ||
initialDelaySeconds: 5 | ||
timeoutSeconds: 1 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: whereami | ||
spec: | ||
type: ClusterIP | ||
selector: | ||
app: whereami | ||
ports: | ||
- port: 80 | ||
targetPort: 8080 | ||
protocol: TCP | ||
--- | ||
kind: Gateway | ||
apiVersion: gateway.networking.k8s.io/v1beta1 | ||
metadata: | ||
name: l7-ilb | ||
spec: | ||
gatewayClassName: gke-l7-rilb | ||
listeners: | ||
- name: http | ||
protocol: HTTP | ||
port: 80 | ||
addresses: | ||
- type: NamedAddress | ||
value: gke-spoke-1-l7-rilb-ip | ||
--- | ||
kind: HTTPRoute | ||
apiVersion: gateway.networking.k8s.io/v1beta1 | ||
metadata: | ||
name: whereami | ||
spec: | ||
parentRefs: | ||
- kind: Gateway | ||
name: l7-ilb | ||
rules: | ||
- backendRefs: | ||
- name: whereami | ||
port: 80 |
Oops, something went wrong.