Skip to content

Commit 4d220a2

Browse files
author
Aaron Lane
authored
Merge pull request #321 from alekhyal/master
Example to create private cluster with node pool specifications along…
2 parents 63c8b6f + 4f3df80 commit 4d220a2

File tree

6 files changed

+354
-0
lines changed

6 files changed

+354
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Regional Private Cluster with node pool and oauth scopes
2+
3+
This example illustrates how to create a private cluster with node pool specifications, oauth scopes along with required network and subnet creation.
4+
5+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6+
## Inputs
7+
8+
| Name | Description | Type | Default | Required |
9+
|------|-------------|:----:|:-----:|:-----:|
10+
| project\_id | The project ID to host the cluster in | string | n/a | yes |
11+
12+
## Outputs
13+
14+
| Name | Description |
15+
|------|-------------|
16+
| ca\_certificate | Cluster ca certificate (base64 encoded) |
17+
| cluster\_name | Cluster name |
18+
| endpoint | Cluster endpoint |
19+
| horizontal\_pod\_autoscaling\_enabled | Whether horizontal pod autoscaling enabled |
20+
| http\_load\_balancing\_enabled | Whether http load balancing enabled |
21+
| location | Cluster location (region if regional cluster, zone if zonal cluster) |
22+
| logging\_service | Logging service used |
23+
| master\_authorized\_networks\_config | Networks from which access to master is permitted |
24+
| master\_version | Current master kubernetes version |
25+
| min\_master\_version | Minimum master kubernetes version |
26+
| monitoring\_service | Monitoring service used |
27+
| network\_module | network module output |
28+
| network\_policy\_enabled | Whether network policy enabled |
29+
| node\_pools\_names | List of node pools names |
30+
| node\_pools\_versions | List of node pools versions |
31+
| region | Cluster region |
32+
| service\_account | The service account to default running nodes as if not overridden in `node_pools`. |
33+
| subnets\_ips | The IP and cidrs of the subnets being created |
34+
| subnets\_secondary\_ranges | The secondary ranges associated with these subnets |
35+
| type | Cluster type (regional / zonal) |
36+
| zones | List of zones in which the cluster resides |
37+
38+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
39+
40+
To provision this example, run the following from within this directory:
41+
- `terraform init` to get the plugins
42+
- `terraform plan` to see the infrastructure plan
43+
- `terraform apply` to apply the infrastructure build
44+
- `terraform destroy` to destroy the built infrastructure
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**
2+
* Copyright 2018 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+
module "gke" {
18+
source = "../../modules/private-cluster"
19+
project_id = var.project_id
20+
name = "random-test-cluster"
21+
region = "us-west1"
22+
regional = true
23+
network = module.gke-network.network_name
24+
subnetwork = module.gke-network.subnets_names[0]
25+
ip_range_pods = module.gke-network.subnets_secondary_ranges[0].*.range_name[0]
26+
ip_range_services = module.gke-network.subnets_secondary_ranges[0].*.range_name[1]
27+
enable_private_endpoint = true
28+
enable_private_nodes = true
29+
master_ipv4_cidr_block = "172.16.0.16/28"
30+
network_policy = true
31+
horizontal_pod_autoscaling = true
32+
service_account = "create"
33+
remove_default_node_pool = true
34+
disable_legacy_metadata_endpoints = true
35+
36+
master_authorized_networks_config = [
37+
{
38+
cidr_blocks = [
39+
{
40+
cidr_block = module.gke-network.subnets_ips[0]
41+
display_name = "VPC"
42+
},
43+
]
44+
},
45+
]
46+
47+
node_pools = [
48+
{
49+
name = "my-node-pool"
50+
machine_type = "n1-standard-1"
51+
min_count = 1
52+
max_count = 1
53+
disk_size_gb = 100
54+
disk_type = "pd-ssd"
55+
image_type = "COS"
56+
auto_repair = true
57+
auto_upgrade = false
58+
preemptible = false
59+
initial_node_count = 1
60+
},
61+
]
62+
63+
node_pools_oauth_scopes = {
64+
all = [
65+
"https://www.googleapis.com/auth/trace.append",
66+
"https://www.googleapis.com/auth/service.management.readonly",
67+
"https://www.googleapis.com/auth/monitoring",
68+
"https://www.googleapis.com/auth/devstorage.read_only",
69+
"https://www.googleapis.com/auth/servicecontrol",
70+
]
71+
72+
my-node-pool = [
73+
"https://www.googleapis.com/auth/trace.append",
74+
"https://www.googleapis.com/auth/service.management.readonly",
75+
"https://www.googleapis.com/auth/monitoring",
76+
"https://www.googleapis.com/auth/devstorage.read_only",
77+
"https://www.googleapis.com/auth/servicecontrol",
78+
]
79+
}
80+
81+
node_pools_labels = {
82+
83+
all = {
84+
85+
}
86+
my-node-pool = {
87+
88+
}
89+
}
90+
91+
node_pools_metadata = {
92+
all = {}
93+
94+
my-node-pool = {}
95+
96+
}
97+
98+
node_pools_tags = {
99+
all = []
100+
101+
my-node-pool = []
102+
103+
}
104+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright 2018 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+
module "gke-network" {
18+
source = "terraform-google-modules/network/google"
19+
version = "~> 1.5"
20+
project_id = var.project_id
21+
network_name = "random-gke-network"
22+
23+
subnets = [
24+
{
25+
subnet_name = "random-gke-subnet"
26+
subnet_ip = "10.0.0.0/24"
27+
subnet_region = "us-west1"
28+
},
29+
]
30+
31+
secondary_ranges = {
32+
"random-gke-subnet" = [
33+
{
34+
range_name = "random-ip-range-pods"
35+
ip_cidr_range = "10.1.0.0/16"
36+
},
37+
{
38+
range_name = "random-ip-range-services"
39+
ip_cidr_range = "10.2.0.0/20"
40+
},
41+
] }
42+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* Copyright 2018 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 "cluster_name" {
18+
description = "Cluster name"
19+
value = module.gke.name
20+
}
21+
22+
output "type" {
23+
description = "Cluster type (regional / zonal)"
24+
value = module.gke.type
25+
}
26+
27+
output "location" {
28+
description = "Cluster location (region if regional cluster, zone if zonal cluster)"
29+
value = module.gke.location
30+
}
31+
32+
output "region" {
33+
description = "Cluster region"
34+
value = module.gke.region
35+
}
36+
37+
output "zones" {
38+
description = "List of zones in which the cluster resides"
39+
value = module.gke.zones
40+
}
41+
42+
output "endpoint" {
43+
sensitive = true
44+
description = "Cluster endpoint"
45+
value = module.gke.endpoint
46+
}
47+
48+
output "min_master_version" {
49+
description = "Minimum master kubernetes version"
50+
value = module.gke.min_master_version
51+
}
52+
53+
output "logging_service" {
54+
description = "Logging service used"
55+
value = module.gke.logging_service
56+
}
57+
58+
output "monitoring_service" {
59+
description = "Monitoring service used"
60+
value = module.gke.monitoring_service
61+
}
62+
63+
output "master_authorized_networks_config" {
64+
description = "Networks from which access to master is permitted"
65+
value = module.gke.master_authorized_networks_config
66+
}
67+
68+
output "master_version" {
69+
description = "Current master kubernetes version"
70+
value = module.gke.master_version
71+
}
72+
73+
output "ca_certificate" {
74+
sensitive = true
75+
description = "Cluster ca certificate (base64 encoded)"
76+
value = module.gke.ca_certificate
77+
}
78+
79+
output "network_policy_enabled" {
80+
description = "Whether network policy enabled"
81+
value = module.gke.network_policy_enabled
82+
}
83+
84+
output "http_load_balancing_enabled" {
85+
description = "Whether http load balancing enabled"
86+
value = module.gke.http_load_balancing_enabled
87+
}
88+
89+
output "horizontal_pod_autoscaling_enabled" {
90+
description = "Whether horizontal pod autoscaling enabled"
91+
value = module.gke.horizontal_pod_autoscaling_enabled
92+
}
93+
94+
output "node_pools_names" {
95+
description = "List of node pools names"
96+
value = module.gke.node_pools_names
97+
}
98+
99+
output "node_pools_versions" {
100+
description = "List of node pools versions"
101+
value = module.gke.node_pools_versions
102+
}
103+
104+
output "service_account" {
105+
description = "The service account to default running nodes as if not overridden in `node_pools`."
106+
value = module.gke.service_account
107+
}
108+
109+
output "network_module" {
110+
description = "network module output"
111+
value = module.gke-network
112+
}
113+
114+
output "subnets_ips" {
115+
description = "The IP and cidrs of the subnets being created"
116+
value = module.gke-network.subnets_ips
117+
}
118+
119+
output "subnets_secondary_ranges" {
120+
description = "The secondary ranges associated with these subnets"
121+
value = module.gke-network.subnets_secondary_ranges
122+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright 2018 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+
provider "google" {
18+
version = "2.18.0"
19+
}
20+
21+
provider "google-beta" {
22+
version = "2.18.0"
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright 2018 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+
}

0 commit comments

Comments
 (0)