Skip to content
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

FAST: GKE multitenant infrastructure #700

Merged
merged 97 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
f3f9a4a
GKE multitenant
juliocc Feb 4, 2022
801a5ed
Add xpn admin to gke SAs on gke folders
juliocc Feb 5, 2022
740288e
Remove old test project
juliocc Feb 5, 2022
5ff2286
clusters creation improvement (#509)
danielmarzini Feb 6, 2022
46af8fa
Use new project-level robot bindings
juliocc Feb 9, 2022
a4c0b22
Move GKE example to dev
juliocc Feb 14, 2022
9fabfaf
Update gke stage to use contract setup
juliocc Feb 16, 2022
96b01cf
Fix networking-vpn tests
juliocc Feb 28, 2022
66f8790
Enable GKE resource metering
juliocc Mar 8, 2022
9bcae7b
Enable WIF issuer in gke-hub
juliocc Mar 8, 2022
d28dfc4
Enable GKE hub apis
juliocc Mar 8, 2022
110d940
Squashing relevant changes from fast-dev-gke-marzi
juliocc Apr 3, 2022
259afec
Leave MCS and MCI disabled
danielmarzini Apr 5, 2022
f9b808b
Fix permissions and update NVA and peering net stages for gke
juliocc May 27, 2022
666d8a4
Merge branch 'master' into fast/gke2
ludoo Jun 23, 2022
744417f
fix boilerplate
ludoo Jun 23, 2022
fb1d315
fix tfdoc
ludoo Jun 23, 2022
ed4b301
align subnets between vpn and peering network stages
ludoo Jun 23, 2022
dfb447a
Merge branch 'master' into fast/gke2
ludoo Jun 23, 2022
ee7a615
Merge remote-tracking branch 'origin/master' into fast/gke2
ludoo Jun 29, 2022
d6a81fb
wip
ludoo Jun 30, 2022
7786dd3
Merge branch 'master' into fast/gke2
ludoo Jun 30, 2022
7b5ced7
stage 01
ludoo Jun 30, 2022
9a3128e
wip
ludoo Jun 30, 2022
a3ea8be
wip
ludoo Jul 5, 2022
e7bc11e
Add gke SAs to outputs
juliocc Jul 12, 2022
25955b1
Merge branch 'master' into fast/gke2
juliocc Jul 12, 2022
1bc352b
Fix docs
juliocc Jul 12, 2022
93acd59
Merge branch 'master' into fast/gke2
juliocc Jul 12, 2022
07c5da4
Fix tests
juliocc Jul 12, 2022
1260db9
Update main.tf
ludoo Jul 29, 2022
366f28a
Merge remote-tracking branch 'origin/master' into fast/gke2
ludoo Jul 29, 2022
133fd07
unfinished gke hub IAM
ludoo Jul 29, 2022
c24e661
fleet mcs service accounts
ludoo Jul 29, 2022
7c23aea
implement dev, fix variables, add stub READMEs
ludoo Jul 29, 2022
f00b67a
linting
ludoo Jul 29, 2022
c9fa0fb
fixes
danielmarzini Jul 29, 2022
171d0d1
fix mci integration in the gke-hub
danielmarzini Jul 29, 2022
e4de73f
Revert "fix mci integration in the gke-hub"
danielmarzini Jul 30, 2022
4551704
Merge branch 'master' into fast/gke2
ludoo Jul 30, 2022
c51ba73
change to binary_authorization, add support for additional services
ludoo Jul 30, 2022
f51e40b
tfdoc
ludoo Jul 30, 2022
24f3545
add project-level iam variable
ludoo Jul 30, 2022
9b371a3
support GKE specific network roles in stages 01 and 02
ludoo Jul 31, 2022
b650b61
Merge branch 'master' into fast/gke2
ludoo Jul 31, 2022
cd3b446
align net stages
ludoo Jul 31, 2022
0c4e82e
Merge branch 'fast/gke2' of github.com:GoogleCloudPlatform/cloud-foun…
ludoo Jul 31, 2022
dedddbe
align net stages
ludoo Jul 31, 2022
6314afb
Fix gke-cluster enable_binary_authorization being deprecated
danielmarzini Aug 2, 2022
4572323
fix permissions and binauthz
danielmarzini Aug 2, 2022
170d585
fix permissions and binauthz
danielmarzini Aug 2, 2022
ce7e4bc
linting
ludoo Aug 2, 2022
0516c30
fix binauthz example
ludoo Aug 2, 2022
531acf3
Merge remote-tracking branch 'origin/master' into fast/gke2
ludoo Aug 2, 2022
1cf963b
added spot vm
danielmarzini Aug 2, 2022
b85b5e2
added spot vm
danielmarzini Aug 2, 2022
0bec03b
Merge remote-tracking branch 'origin/master' into fast/gke2
ludoo Aug 3, 2022
7374c82
Merge branch 'master' into fast/gke2
ludoo Aug 6, 2022
3745b28
remove support for preemptible nodes
ludoo Aug 6, 2022
34d5156
top-level README
ludoo Aug 6, 2022
dcc2700
Merge branch 'master' into fast/gke2
ludoo Aug 7, 2022
6af9953
Update README.md
danielmarzini Aug 8, 2022
a16cf9e
documentation WIP
ludoo Aug 8, 2022
86d73ee
Merge remote-tracking branch 'origin/master' into fast/gke2
ludoo Aug 9, 2022
af336f8
move gke fat module to examples
ludoo Aug 10, 2022
c2b0782
wip
ludoo Aug 10, 2022
ac57511
wip
ludoo Aug 10, 2022
ea72c5b
Merge branch 'master' into fast/gke2
ludoo Aug 10, 2022
ff1563e
Merge remote-tracking branch 'origin/master' into fast/gke2
ludoo Aug 11, 2022
00e8666
TODO: adjust external load balancer policy
danielmarzini Aug 11, 2022
5762d59
rename example folder, add diagram
ludoo Aug 12, 2022
95b12ac
rename example folder
ludoo Aug 12, 2022
a285569
Merge branch 'fast/gke2' of github.com:GoogleCloudPlatform/cloud-foun…
ludoo Aug 12, 2022
52e7e05
Merge branch 'master' into fast/gke2
juliocc Aug 24, 2022
d345cf8
Update gke multitenant README
juliocc Aug 24, 2022
9097390
Fix internal links
juliocc Aug 24, 2022
fa8990d
gke stage docs
juliocc Aug 24, 2022
c3e6a03
Allow fleet project to be specified by the user
juliocc Aug 25, 2022
a82ef75
Allow gke stage to write to automation bucket
juliocc Aug 25, 2022
cad3715
Fix dependencies in gke multitenant stage
juliocc Aug 25, 2022
fd06a84
Update gke multitenant README
juliocc Aug 25, 2022
0e65021
Merge remote-tracking branch 'origin/master' into fast/gke2
juliocc Aug 30, 2022
b1d9b27
Allow peering configuration to be passed as variable to fleet example.
juliocc Aug 30, 2022
2ddd68e
Fix comment exaplaining serviceProjectAdmin permissions
juliocc Aug 30, 2022
1e8ec71
multitenat fleet readme, first pass
juliocc Aug 30, 2022
d83e3ad
fleet example readme
juliocc Sep 2, 2022
a62fda5
Update gke docs
juliocc Sep 6, 2022
5e1974b
Merge branch 'master' into fast/gke2
juliocc Sep 7, 2022
fce4170
Add missing paren.
juliocc Sep 7, 2022
218b374
Update multitenant-fleet README
juliocc Sep 7, 2022
3ffdd0d
More examples for multitenant-fleet example
juliocc Sep 7, 2022
15e45cb
Multipe-cluster example for multitenant-fleet example
juliocc Sep 8, 2022
7d82143
Update README
juliocc Sep 8, 2022
444b370
README fixes
juliocc Sep 8, 2022
ff7e398
Finished readme of fast gke stage
juliocc Sep 8, 2022
a530620
Fixing typos
juliocc Sep 8, 2022
76e49d5
Merge remote-tracking branch 'origin/master' into fast/gke2
juliocc Sep 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/cloud-operations/binauthz/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ module "cluster" {
master_ipv4_cidr_block = var.master_cidr_block
master_global_access = false
}
enable_binary_authorization = true
workload_identity = true
workload_identity = true
}

module "cluster_nodepool" {
Expand Down
12 changes: 12 additions & 0 deletions examples/gke-serverless/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# GKE and Serverless examples

The examples in this folder show implement **end-to-end scenarios** for GKE or Serveless topologies that show how to automate common configurations or leverage specific products.

They are meant to be used as minimal but complete starting points to create actual infrastructure, and as playgrounds to experiment with Google Cloud features.

## Examples

### Multitenant GKE fleet

<a href="./multitenant-fleet/" title="GKE multitenant fleet"><img src="./multitenant-fleet/diagram.png" align="left" width="280px"></a> This [example](./multitenant-fleet/) allows simple centralized management of similar sets of GKE clusters and their nodepools in a single project, and optional fleet management via GKE Hub templated configurations.
<br clear="left">
359 changes: 359 additions & 0 deletions examples/gke-serverless/multitenant-fleet/README.md

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 116 additions & 0 deletions examples/gke-serverless/multitenant-fleet/gke-clusters.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* Copyright 2022 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.
*/

locals {
clusters = {
for name, config in var.clusters :
name => merge(config, {
overrides = coalesce(config.overrides, var.cluster_defaults)
})
}
}

module "gke-cluster" {
source = "../../../modules/gke-cluster"
for_each = local.clusters
name = each.key
project_id = module.gke-project-0.project_id
description = each.value.description
location = each.value.location
network = var.vpc_config.vpc_self_link
subnetwork = each.value.net.subnet
secondary_range_pods = each.value.net.pods
secondary_range_services = each.value.net.services
labels = each.value.labels
addons = {
cloudrun_config = each.value.overrides.cloudrun_config
dns_cache_config = true
http_load_balancing = true
gce_persistent_disk_csi_driver_config = true
horizontal_pod_autoscaling = true
config_connector_config = true
kalm_config = false
gcp_filestore_csi_driver_config = each.value.overrides.gcp_filestore_csi_driver_config
gke_backup_agent_config = false
# enable only if enable_dataplane_v2 is changed to false below
network_policy_config = false
istio_config = {
enabled = false
tls = false
}
}
# change these here for all clusters if absolutely needed
authenticator_security_group = var.authenticator_security_group
enable_dataplane_v2 = true
enable_l4_ilb_subsetting = false
enable_intranode_visibility = true
enable_shielded_nodes = true
workload_identity = true
private_cluster_config = {
enable_private_nodes = true
enable_private_endpoint = false
master_ipv4_cidr_block = each.value.net.master_range
master_global_access = true
}
dns_config = each.value.dns_domain == null ? null : {
cluster_dns = "CLOUD_DNS"
cluster_dns_scope = "VPC_SCOPE"
cluster_dns_domain = "${each.key}.${var.dns_domain}"
}
logging_config = ["SYSTEM_COMPONENTS", "WORKLOADS"]
monitoring_config = ["SYSTEM_COMPONENTS", "WORKLOADS"]

peering_config = var.peering_config == null ? null : {
export_routes = var.peering_config.export_routes
import_routes = var.peering_config.import_routes
project_id = var.vpc_config.host_project_id
}
resource_usage_export_config = {
enabled = true
dataset = module.gke-dataset-resource-usage.dataset_id
}
# TODO: the attributes below are "primed" from project-level defaults
# in locals, merge defaults with cluster-level stuff
# TODO(jccb): change fabric module
database_encryption = (
each.value.overrides.database_encryption_key == null
? {
enabled = false
state = null
key_name = null
}
: {
enabled = true
state = "ENCRYPTED"
key_name = each.value.overrides.database_encryption_key
}
)
default_max_pods_per_node = each.value.overrides.max_pods_per_node
master_authorized_ranges = each.value.overrides.master_authorized_ranges
pod_security_policy = each.value.overrides.pod_security_policy
release_channel = each.value.overrides.release_channel
vertical_pod_autoscaling = each.value.overrides.vertical_pod_autoscaling
# dynamic "cluster_autoscaling" {
# for_each = each.value.cluster_autoscaling == null ? {} : { 1 = 1 }
# content {
# enabled = true
# cpu_min = each.value.cluster_autoscaling.cpu_min
# cpu_max = each.value.cluster_autoscaling.cpu_max
# memory_min = each.value.cluster_autoscaling.memory_min
# memory_max = each.value.cluster_autoscaling.memory_max
# }
# }
}
44 changes: 44 additions & 0 deletions examples/gke-serverless/multitenant-fleet/gke-hub.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright 2022 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.
*/

locals {
fleet_enabled = (
var.fleet_features != null || var.fleet_workload_identity
)
fleet_mcs_enabled = (
try(var.fleet_features.multiclusterservicediscovery, false) == true
)
}

module "gke-hub" {
source = "../../../modules/gke-hub"
count = local.fleet_enabled ? 1 : 0
project_id = module.gke-project-0.project_id
clusters = {
for cluster_id in keys(var.clusters) :
cluster_id => module.gke-cluster[cluster_id].id
}
features = var.fleet_features
configmanagement_templates = var.fleet_configmanagement_templates
configmanagement_clusters = var.fleet_configmanagement_clusters
workload_identity_clusters = (
var.fleet_workload_identity ? keys(var.clusters) : []
)

depends_on = [
module.gke-nodepool
]
}
66 changes: 66 additions & 0 deletions examples/gke-serverless/multitenant-fleet/gke-nodepools.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Copyright 2022 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.
*/

locals {
nodepools = merge([
for cluster, nodepools in var.nodepools : {
for nodepool, config in nodepools :
"${cluster}/${nodepool}" => merge(config, {
name = nodepool
cluster = cluster
overrides = coalesce(config.overrides, var.nodepool_defaults)
})
}
]...)
}

module "gke-nodepool" {
source = "../../../modules/gke-nodepool"
for_each = local.nodepools
name = each.value.name
project_id = module.gke-project-0.project_id
cluster_name = module.gke-cluster[each.value.cluster].name
location = module.gke-cluster[each.value.cluster].location
initial_node_count = each.value.initial_node_count
node_machine_type = each.value.node_type
node_spot = each.value.spot

node_count = each.value.node_count
# node_count = (
# each.value.autoscaling_config == null ? each.value.node_count : null
# )
# dynamic "autoscaling_config" {
# for_each = each.value.autoscaling_config == null ? {} : { 1 = 1 }
# content {
# min_node_count = each.value.autoscaling_config.min_node_count
# max_node_count = each.value.autoscaling_config.max_node_count
# }
# }

# overrides
node_locations = each.value.overrides.node_locations
max_pods_per_node = each.value.overrides.max_pods_per_node
node_image_type = each.value.overrides.image_type
node_tags = each.value.overrides.node_tags
node_taints = each.value.overrides.node_taints

management_config = {
auto_repair = true
auto_upgrade = true
}

node_service_account_create = true
}
86 changes: 86 additions & 0 deletions examples/gke-serverless/multitenant-fleet/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Copyright 2022 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.
*/

module "gke-project-0" {
source = "../../../modules/project"
billing_account = var.billing_account_id
name = var.project_id
parent = var.folder_id
prefix = var.prefix
group_iam = var.group_iam
labels = var.labels
iam = merge(var.iam, {
"roles/gkehub.serviceAgent" = [
"serviceAccount:${module.gke-project-0.service_accounts.robots.fleet}"
] }
)
services = concat(
[
"anthos.googleapis.com",
"anthosconfigmanagement.googleapis.com",
"cloudresourcemanager.googleapis.com",
"container.googleapis.com",
"dns.googleapis.com",
"gkeconnect.googleapis.com",
"gkehub.googleapis.com",
"iam.googleapis.com",
"multiclusteringress.googleapis.com",
"multiclusterservicediscovery.googleapis.com",
"stackdriver.googleapis.com",
"trafficdirector.googleapis.com"
],
var.project_services
)
service_config = {
disable_on_destroy = false
disable_dependent_services = false
}
shared_vpc_service_config = {
attach = true
host_project = var.vpc_config.host_project_id
service_identity_iam = merge({
"roles/compute.networkUser" = [
"cloudservices", "container-engine"
]
"roles/container.hostServiceAgentUser" = [
"container-engine"
]
},
!local.fleet_mcs_enabled ? {} : {
"roles/multiclusterservicediscovery.serviceAgent" = ["gke-mcs"]
"roles/compute.networkViewer" = ["gke-mcs-importer"]
})
}
# specify project-level org policies here if you need them
# policy_boolean = {
# "constraints/compute.disableGuestAttributesAccess" = true
# }
# policy_list = {
# "constraints/compute.trustedImageProjects" = {
# inherit_from_parent = null
# suggested_value = null
# status = true
# values = ["projects/fl01-prod-iac-core-0"]
# }
# }
}

module "gke-dataset-resource-usage" {
source = "../../../modules/bigquery-dataset"
project_id = module.gke-project-0.project_id
id = "gke_resource_usage"
friendly_name = "GKE resource usage."
}
32 changes: 32 additions & 0 deletions examples/gke-serverless/multitenant-fleet/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2022 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
#
# https://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.

# tfdoc:file:description Output variables.

output "clusters" {
description = "Cluster resources."
value = module.gke-cluster
}

output "cluster_ids" {
description = "Cluster ids."
value = {
for k, v in module.gke-cluster : k => v.id
}
}

output "project_id" {
description = "GKE project id."
value = module.gke-project-0.project_id
}
Loading