Skip to content

Commit 71b2638

Browse files
committed
copy of gke standard cluster
1 parent 75d5547 commit 71b2638

File tree

5 files changed

+290
-0
lines changed

5 files changed

+290
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# GKE Standard Cluster and Node Pool
2+
3+
This example creates a GKE private cluster and Node Pool with beta features.
4+
For a full example see [simple_regional_private_beta](../simple_regional_private_beta/README.md) example.
5+
6+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
7+
## Inputs
8+
9+
| Name | Description | Type | Default | Required |
10+
|------|-------------|------|---------|:--------:|
11+
| cluster\_name\_suffix | A suffix to append to the default cluster name | `string` | `""` | no |
12+
| dns\_cache | Boolean to enable / disable NodeLocal DNSCache | `bool` | `false` | no |
13+
| gce\_pd\_csi\_driver | (Beta) Whether this cluster should enable the Google Compute Engine Persistent Disk Container Storage Interface (CSI) Driver. | `bool` | `false` | no |
14+
| ip\_range\_pods | The secondary ip range to use for pods | `any` | n/a | yes |
15+
| ip\_range\_services | The secondary ip range to use for services | `any` | n/a | yes |
16+
| network | The VPC network to host the cluster in | `any` | n/a | yes |
17+
| project\_id | The project ID to host the cluster in | `any` | n/a | yes |
18+
| region | The region to host the cluster in | `any` | n/a | yes |
19+
| service\_account | Service account to associate to the nodes in the cluster | `any` | n/a | yes |
20+
| subnetwork | The subnetwork to host the cluster in | `any` | n/a | yes |
21+
22+
## Outputs
23+
24+
| Name | Description |
25+
|------|-------------|
26+
| addons\_config | The configuration for addons supported by GKE Autopilot. |
27+
| ca\_certificate | The cluster ca certificate (base64 encoded) |
28+
| cluster\_name | Cluster name |
29+
| endpoint | The cluster endpoint |
30+
| location | Cluster location |
31+
| master\_version | The master Kubernetes version |
32+
| node\_locations | Cluster node locations |
33+
| project\_id | The project ID the cluster is in |
34+
35+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
36+
37+
To provision this example, run the following from within this directory:
38+
- `terraform init` to get the plugins
39+
- `terraform plan` to see the infrastructure plan
40+
- `terraform apply` to apply the infrastructure build
41+
- `terraform destroy` to destroy the built infrastructure
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
locals {
18+
cluster_type = "gke-standard"
19+
default_workload_pool = "${var.project_id}.svc.id.goog"
20+
}
21+
22+
data "google_client_config" "default" {}
23+
24+
provider "kubernetes" {
25+
host = "https://${module.gke.endpoint}"
26+
token = data.google_client_config.default.access_token
27+
cluster_ca_certificate = base64decode(module.gke.ca_certificate)
28+
}
29+
30+
data "google_compute_subnetwork" "subnetwork" {
31+
name = var.subnetwork
32+
project = var.project_id
33+
region = var.region
34+
}
35+
36+
module "gke" {
37+
source = "terraform-google-modules/kubernetes-engine/google//modules/gke-standard-cluster"
38+
version = "~> 38.0"
39+
40+
project_id = var.project_id
41+
name = "${local.cluster_type}-cluster${var.cluster_name_suffix}"
42+
location = var.region
43+
network = var.network
44+
subnetwork = var.subnetwork
45+
46+
ip_allocation_policy = {
47+
cluster_secondary_range_name = var.ip_range_pods
48+
services_secondary_range_name = var.ip_range_services
49+
}
50+
51+
private_cluster_config = {
52+
enable_private_endpoint = true
53+
enable_private_nodes = true
54+
master_ipv4_cidr_block = "172.16.0.0/28"
55+
master_global_access_config = {
56+
enabled = true
57+
}
58+
}
59+
60+
deletion_protection = false
61+
remove_default_node_pool = true
62+
initial_node_count = 1
63+
64+
workload_identity_config = {
65+
workload_pool = local.default_workload_pool
66+
}
67+
68+
master_authorized_networks_config = {
69+
cidr_blocks = [{
70+
cidr_block = data.google_compute_subnetwork.subnetwork.ip_cidr_range
71+
display_name = "VPC"
72+
}]
73+
}
74+
75+
addons_config = {
76+
dns_cache_config = {
77+
enabled = var.dns_cache
78+
}
79+
80+
gce_persistent_disk_csi_driver_config = {
81+
enabled = var.gce_pd_csi_driver
82+
}
83+
}
84+
}
85+
86+
module "node_pool" {
87+
source = "terraform-google-modules/kubernetes-engine/google//modules/gke-node-pool"
88+
version = "~> 38.0"
89+
90+
project_id = var.project_id
91+
location = var.region
92+
cluster = module.gke.cluster_name
93+
node_config = {
94+
disk_size_gb = 100
95+
disk_type = "pd-standard"
96+
image_type = "COS_CONTAINERD"
97+
machine_type = "e2-medium"
98+
service_account = var.service_account
99+
workload_metadata_config = {
100+
mode = "GKE_METADATA"
101+
}
102+
}
103+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "endpoint" {
18+
sensitive = true
19+
description = "The cluster endpoint"
20+
value = module.gke.endpoint
21+
}
22+
23+
output "ca_certificate" {
24+
sensitive = true
25+
description = "The cluster ca certificate (base64 encoded)"
26+
value = module.gke.ca_certificate
27+
}
28+
29+
output "project_id" {
30+
description = "The project ID the cluster is in"
31+
value = var.project_id
32+
}
33+
34+
output "location" {
35+
description = "Cluster location"
36+
value = module.gke.location
37+
}
38+
39+
output "node_locations" {
40+
description = "Cluster node locations"
41+
value = module.gke.node_locations
42+
}
43+
44+
output "addons_config" {
45+
description = "The configuration for addons supported by GKE Autopilot."
46+
value = module.gke.addons_config
47+
}
48+
49+
output "cluster_name" {
50+
description = "Cluster name"
51+
value = module.gke.cluster_name
52+
}
53+
54+
output "master_version" {
55+
description = "The master Kubernetes version"
56+
value = module.gke.master_version
57+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
variable "project_id" {
18+
description = "The project ID to host the cluster in"
19+
}
20+
21+
variable "cluster_name_suffix" {
22+
description = "A suffix to append to the default cluster name"
23+
default = ""
24+
}
25+
26+
variable "region" {
27+
description = "The region to host the cluster in"
28+
}
29+
30+
variable "network" {
31+
description = "The VPC network to host the cluster in"
32+
}
33+
34+
variable "subnetwork" {
35+
description = "The subnetwork to host the cluster in"
36+
}
37+
38+
variable "ip_range_pods" {
39+
description = "The secondary ip range to use for pods"
40+
}
41+
42+
variable "ip_range_services" {
43+
description = "The secondary ip range to use for services"
44+
}
45+
46+
variable "service_account" {
47+
description = "Service account to associate to the nodes in the cluster"
48+
}
49+
50+
variable "dns_cache" {
51+
description = "Boolean to enable / disable NodeLocal DNSCache "
52+
default = false
53+
}
54+
55+
variable "gce_pd_csi_driver" {
56+
type = bool
57+
description = "(Beta) Whether this cluster should enable the Google Compute Engine Persistent Disk Container Storage Interface (CSI) Driver."
58+
default = false
59+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
terraform {
18+
required_version = ">= 1.3"
19+
required_providers {
20+
google = {
21+
source = "hashicorp/google"
22+
}
23+
google-beta = {
24+
source = "hashicorp/google-beta"
25+
}
26+
kubernetes = {
27+
source = "hashicorp/kubernetes"
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)