Refactor GKE cluster modules access configurations, add support for DNS endpoint (#2761)
* stub * gke standard module and tests * blueprints * tfdoc * autopilot * blueprints * tfdoc * gke hub module examples * dataproc and gke fixture
This commit is contained in:
committed by
GitHub
parent
d59d182456
commit
d86b8d565c
File diff suppressed because one or more lines are too long
@@ -38,7 +38,6 @@ variable "dataproc_config" {
|
||||
node_group_affinity = optional(object({
|
||||
node_group_uri = string
|
||||
}))
|
||||
|
||||
shielded_instance_config = optional(object({
|
||||
enable_secure_boot = bool
|
||||
enable_vtpm = bool
|
||||
@@ -138,7 +137,6 @@ variable "dataproc_config" {
|
||||
dataproc_metastore_service = string
|
||||
}))
|
||||
}))
|
||||
|
||||
virtual_cluster_config = optional(object({
|
||||
staging_bucket = optional(string)
|
||||
auxiliary_services_config = optional(object({
|
||||
@@ -155,7 +153,6 @@ variable "dataproc_config" {
|
||||
component_version = map(string)
|
||||
properties = optional(map(string))
|
||||
})
|
||||
|
||||
gke_cluster_config = object({
|
||||
gke_cluster_target = optional(string)
|
||||
node_pool_target = optional(object({
|
||||
@@ -166,7 +163,6 @@ variable "dataproc_config" {
|
||||
min_node_count = optional(number)
|
||||
max_node_count = optional(number)
|
||||
}))
|
||||
|
||||
config = object({
|
||||
machine_type = optional(string)
|
||||
preemptible = optional(bool)
|
||||
@@ -174,7 +170,6 @@ variable "dataproc_config" {
|
||||
min_cpu_platform = optional(string)
|
||||
spot = optional(bool)
|
||||
})
|
||||
|
||||
locations = optional(list(string))
|
||||
}))
|
||||
}))
|
||||
|
||||
@@ -3,19 +3,18 @@
|
||||
This module offers a way to create and manage Google Kubernetes Engine (GKE) [Autopilot clusters](https://cloud.google.com/kubernetes-engine/docs/concepts/autopilot-overview). With its sensible default settings based on best practices and authors' experience as Google Cloud practitioners, the module accommodates for many common use cases out-of-the-box, without having to rely on verbose configuration.
|
||||
|
||||
<!-- BEGIN TOC -->
|
||||
- [Examples](#examples)
|
||||
- [GKE Autopilot cluster](#gke-autopilot-cluster)
|
||||
- [Cloud DNS](#cloud-dns)
|
||||
- [Logging configuration](#logging-configuration)
|
||||
- [Monitoring configuration](#monitoring-configuration)
|
||||
- [Backup for GKE](#backup-for-gke)
|
||||
- [GKE Autopilot cluster](#gke-autopilot-cluster)
|
||||
- [Cloud DNS](#cloud-dns)
|
||||
- [Logging configuration](#logging-configuration)
|
||||
- [Monitoring configuration](#monitoring-configuration)
|
||||
- [Backup for GKE](#backup-for-gke)
|
||||
- [Variables](#variables)
|
||||
- [Outputs](#outputs)
|
||||
<!-- END TOC -->
|
||||
|
||||
## Examples
|
||||
For an explanation of cluster access configurations, please refer to the [GKE cluster standard](../gke-cluster-standard/README.md) module.
|
||||
|
||||
### GKE Autopilot cluster
|
||||
## GKE Autopilot cluster
|
||||
|
||||
This example shows how to [create a GKE cluster in Autopilot mode](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-an-autopilot-cluster).
|
||||
|
||||
@@ -25,6 +24,13 @@ module "cluster-1" {
|
||||
project_id = "myproject"
|
||||
name = "cluster-1"
|
||||
location = "europe-west1"
|
||||
access_config = {
|
||||
ip_access = {
|
||||
authorized_ranges = {
|
||||
internal-vms = "10.0.0.0/8"
|
||||
}
|
||||
}
|
||||
}
|
||||
vpc_config = {
|
||||
network = var.vpc.self_link
|
||||
subnetwork = var.subnet.self_link
|
||||
@@ -32,14 +38,6 @@ module "cluster-1" {
|
||||
pods = "pods"
|
||||
services = "services"
|
||||
}
|
||||
master_authorized_ranges = {
|
||||
internal-vms = "10.0.0.0/8"
|
||||
}
|
||||
master_ipv4_cidr_block = "192.168.0.0/28"
|
||||
}
|
||||
private_cluster_config = {
|
||||
enable_private_endpoint = true
|
||||
master_global_access = false
|
||||
}
|
||||
labels = {
|
||||
environment = "dev"
|
||||
@@ -48,7 +46,7 @@ module "cluster-1" {
|
||||
# tftest modules=1 resources=1 inventory=basic.yaml
|
||||
```
|
||||
|
||||
### Cloud DNS
|
||||
## Cloud DNS
|
||||
|
||||
> [!WARNING]
|
||||
> [Cloud DNS is the only DNS provider for Autopilot clusters](https://cloud.google.com/kubernetes-engine/docs/concepts/service-discovery#cloud_dns) running version `1.25.9-gke.400` and later, and version `1.26.4-gke.500` and later. It is [pre-configured](https://cloud.google.com/kubernetes-engine/docs/resources/autopilot-standard-feature-comparison#feature-comparison) for those clusters. The following example *only* applies to Autopilot clusters running *earlier* versions.
|
||||
@@ -77,12 +75,12 @@ module "cluster-1" {
|
||||
# tftest modules=1 resources=1 inventory=dns.yaml
|
||||
```
|
||||
|
||||
### Logging configuration
|
||||
## Logging configuration
|
||||
|
||||
> [!NOTE]
|
||||
> System and workload logs collection is pre-configured for Autopilot clusters and cannot be disabled.
|
||||
|
||||
This example shows how to [collect logs for the Kubernetes control plane components](https://cloud.google.com/stackdriver/docs/solutions/gke/installing). The logs for these components are not collected by default.
|
||||
This example shows how to [collect logs for the Kubernetes control plane components](https://cloud.google.com/stackdriver/docs/solutions/gke/installing). The logs for these components are not collected by default.
|
||||
|
||||
```hcl
|
||||
module "cluster-1" {
|
||||
@@ -104,7 +102,7 @@ module "cluster-1" {
|
||||
# tftest modules=1 resources=1 inventory=logging-config.yaml
|
||||
```
|
||||
|
||||
### Monitoring configuration
|
||||
## Monitoring configuration
|
||||
|
||||
> [!NOTE]
|
||||
> [System metrics](https://cloud.google.com/stackdriver/docs/solutions/gke/managing-metrics#enable-system-metrics) collection is pre-configured for Autopilot clusters and cannot be disabled.
|
||||
@@ -164,15 +162,15 @@ module "cluster-1" {
|
||||
|
||||
The *control plane metrics* and *kube state metrics* collection can be configured in a single `monitoring_config` block.
|
||||
|
||||
### Backup for GKE
|
||||
## Backup for GKE
|
||||
|
||||
> [!NOTE]
|
||||
> Although Backup for GKE can be enabled as an add-on when configuring your GKE clusters, it is a separate service from GKE.
|
||||
|
||||
[Backup for GKE](https://cloud.google.com/kubernetes-engine/docs/add-on/backup-for-gke/concepts/backup-for-gke) is a service for backing up and restoring workloads in GKE clusters. It has two components:
|
||||
|
||||
* A [Google Cloud API](https://cloud.google.com/kubernetes-engine/docs/add-on/backup-for-gke/reference/rest) that serves as the control plane for the service.
|
||||
* A GKE add-on (the [Backup for GKE agent](https://cloud.google.com/kubernetes-engine/docs/add-on/backup-for-gke/concepts/backup-for-gke#agent_overview)) that must be enabled in each cluster for which you wish to perform backup and restore operations.
|
||||
- A [Google Cloud API](https://cloud.google.com/kubernetes-engine/docs/add-on/backup-for-gke/reference/rest) that serves as the control plane for the service.
|
||||
- A GKE add-on (the [Backup for GKE agent](https://cloud.google.com/kubernetes-engine/docs/add-on/backup-for-gke/concepts/backup-for-gke#agent_overview)) that must be enabled in each cluster for which you wish to perform backup and restore operations.
|
||||
|
||||
Backup for GKE is supported in GKE Autopilot clusters with [some restrictions](https://cloud.google.com/kubernetes-engine/docs/add-on/backup-for-gke/concepts/about-autopilot).
|
||||
|
||||
@@ -206,25 +204,25 @@ module "cluster-1" {
|
||||
|
||||
| name | description | type | required | default |
|
||||
|---|---|:---:|:---:|:---:|
|
||||
| [location](variables.tf#L118) | Autopilot clusters are always regional. | <code>string</code> | ✓ | |
|
||||
| [name](variables.tf#L195) | Cluster name. | <code>string</code> | ✓ | |
|
||||
| [project_id](variables.tf#L240) | Cluster project ID. | <code>string</code> | ✓ | |
|
||||
| [vpc_config](variables.tf#L256) | VPC-level configuration. | <code title="object({ disable_default_snat = optional(bool) network = string subnetwork = string master_ipv4_cidr_block = optional(string) master_endpoint_subnetwork = optional(string) secondary_range_blocks = optional(object({ pods = string services = string })) secondary_range_names = optional(object({ pods = optional(string) services = optional(string) })) additional_ranges = optional(list(string)) master_authorized_ranges = optional(map(string)) stack_type = optional(string) })">object({…})</code> | ✓ | |
|
||||
| [backup_configs](variables.tf#L17) | Configuration for Backup for GKE. | <code title="object({ enable_backup_agent = optional(bool, false) backup_plans = optional(map(object({ encryption_key = optional(string) include_secrets = optional(bool, true) include_volume_data = optional(bool, true) labels = optional(map(string)) namespaces = optional(list(string)) region = string schedule = string retention_policy_days = optional(string) retention_policy_lock = optional(bool, false) retention_policy_delete_lock_days = optional(string) })), {}) })">object({…})</code> | | <code>{}</code> |
|
||||
| [deletion_protection](variables.tf#L38) | Whether or not to allow Terraform to destroy the cluster. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the cluster will fail. | <code>bool</code> | | <code>true</code> |
|
||||
| [description](variables.tf#L45) | Cluster description. | <code>string</code> | | <code>null</code> |
|
||||
| [enable_addons](variables.tf#L51) | Addons enabled in the cluster (true means enabled). | <code title="object({ cloudrun = optional(bool, false) config_connector = optional(bool, false) istio = optional(object({ enable_tls = bool })) kalm = optional(bool, false) })">object({…})</code> | | <code>{}</code> |
|
||||
| [enable_features](variables.tf#L65) | Enable cluster-level features. Certain features allow configuration. | <code title="object({ beta_apis = optional(list(string)) binary_authorization = optional(bool, false) cost_management = optional(bool, false) dns = optional(object({ provider = optional(string) scope = optional(string) domain = optional(string) })) database_encryption = optional(object({ state = string key_name = string })) gateway_api = optional(bool, false) groups_for_rbac = optional(string) l4_ilb_subsetting = optional(bool, false) mesh_certificates = optional(bool) pod_security_policy = optional(bool, false) secret_manager_config = optional(bool) security_posture_config = optional(object({ mode = string vulnerability_mode = string })) allow_net_admin = optional(bool, false) resource_usage_export = optional(object({ dataset = string enable_network_egress_metering = optional(bool) enable_resource_consumption_metering = optional(bool) })) service_external_ips = optional(bool, true) tpu = optional(bool, false) upgrade_notifications = optional(object({ topic_id = optional(string) })) vertical_pod_autoscaling = optional(bool, false) })">object({…})</code> | | <code>{}</code> |
|
||||
| [issue_client_certificate](variables.tf#L106) | Enable issuing client certificate. | <code>bool</code> | | <code>false</code> |
|
||||
| [labels](variables.tf#L112) | Cluster resource labels. | <code>map(string)</code> | | <code>null</code> |
|
||||
| [logging_config](variables.tf#L123) | Logging configuration. | <code title="object({ enable_api_server_logs = optional(bool, false) enable_scheduler_logs = optional(bool, false) enable_controller_manager_logs = optional(bool, false) })">object({…})</code> | | <code>{}</code> |
|
||||
| [maintenance_config](variables.tf#L134) | Maintenance window configuration. | <code title="object({ daily_window_start_time = optional(string) recurring_window = optional(object({ start_time = string end_time = string recurrence = string })) maintenance_exclusions = optional(list(object({ name = string start_time = string end_time = string scope = optional(string) }))) })">object({…})</code> | | <code title="{ daily_window_start_time = "03:00" recurring_window = null maintenance_exclusion = [] }">{…}</code> |
|
||||
| [min_master_version](variables.tf#L157) | Minimum version of the master, defaults to the version of the most recent official release. | <code>string</code> | | <code>null</code> |
|
||||
| [monitoring_config](variables.tf#L163) | Monitoring configuration. System metrics collection cannot be disabled. Control plane metrics are optional. Kube state metrics are optional. Google Cloud Managed Service for Prometheus is enabled by default. | <code title="object({ enable_api_server_metrics = optional(bool, false) enable_controller_manager_metrics = optional(bool, false) enable_scheduler_metrics = optional(bool, false) enable_daemonset_metrics = optional(bool, false) enable_deployment_metrics = optional(bool, false) enable_hpa_metrics = optional(bool, false) enable_pod_metrics = optional(bool, false) enable_statefulset_metrics = optional(bool, false) enable_storage_metrics = optional(bool, false) enable_managed_prometheus = optional(bool, true) })">object({…})</code> | | <code>{}</code> |
|
||||
| [node_config](variables.tf#L200) | Configuration for nodes and nodepools. | <code title="object({ boot_disk_kms_key = optional(string) service_account = optional(string) tags = optional(list(string)) workload_metadata_config_mode = optional(string) })">object({…})</code> | | <code>{}</code> |
|
||||
| [node_locations](variables.tf#L219) | Zones in which the cluster's nodes are located. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [private_cluster_config](variables.tf#L226) | Private cluster configuration. | <code title="object({ enable_private_endpoint = optional(bool) master_global_access = optional(bool) peering_config = optional(object({ export_routes = optional(bool) import_routes = optional(bool) project_id = optional(string) })) })">object({…})</code> | | <code>null</code> |
|
||||
| [release_channel](variables.tf#L245) | Release channel for GKE upgrades. Clusters created in the Autopilot mode must use a release channel. Choose between \"RAPID\", \"REGULAR\", and \"STABLE\". | <code>string</code> | | <code>"REGULAR"</code> |
|
||||
| [location](variables.tf#L143) | Autopilot clusters are always regional. | <code>string</code> | ✓ | |
|
||||
| [name](variables.tf#L220) | Cluster name. | <code>string</code> | ✓ | |
|
||||
| [project_id](variables.tf#L251) | Cluster project ID. | <code>string</code> | ✓ | |
|
||||
| [vpc_config](variables.tf#L267) | VPC-level configuration. | <code title="object({ disable_default_snat = optional(bool) network = string subnetwork = string secondary_range_blocks = optional(object({ pods = string services = string })) secondary_range_names = optional(object({ pods = optional(string) services = optional(string) })) additional_ranges = optional(list(string)) stack_type = optional(string) })">object({…})</code> | ✓ | |
|
||||
| [access_config](variables.tf#L17) | Control plane endpoint and nodes access configurations. | <code title="object({ dns_access = optional(bool, true) ip_access = optional(object({ authorized_ranges = optional(map(string), {}) disable_public_endpoint = optional(bool, true) private_endpoint_config = optional(object({ endpoint_subnetwork = optional(string) global_access = optional(bool, true) }), {}) }), {}) private_nodes = optional(bool, true) })">object({…})</code> | | <code>{}</code> |
|
||||
| [backup_configs](variables.tf#L42) | Configuration for Backup for GKE. | <code title="object({ enable_backup_agent = optional(bool, false) backup_plans = optional(map(object({ encryption_key = optional(string) include_secrets = optional(bool, true) include_volume_data = optional(bool, true) labels = optional(map(string)) namespaces = optional(list(string)) region = string schedule = string retention_policy_days = optional(string) retention_policy_lock = optional(bool, false) retention_policy_delete_lock_days = optional(string) })), {}) })">object({…})</code> | | <code>{}</code> |
|
||||
| [deletion_protection](variables.tf#L63) | Whether or not to allow Terraform to destroy the cluster. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the cluster will fail. | <code>bool</code> | | <code>true</code> |
|
||||
| [description](variables.tf#L70) | Cluster description. | <code>string</code> | | <code>null</code> |
|
||||
| [enable_addons](variables.tf#L76) | Addons enabled in the cluster (true means enabled). | <code title="object({ cloudrun = optional(bool, false) config_connector = optional(bool, false) istio = optional(object({ enable_tls = bool })) kalm = optional(bool, false) })">object({…})</code> | | <code>{}</code> |
|
||||
| [enable_features](variables.tf#L90) | Enable cluster-level features. Certain features allow configuration. | <code title="object({ beta_apis = optional(list(string)) binary_authorization = optional(bool, false) cost_management = optional(bool, false) dns = optional(object({ provider = optional(string) scope = optional(string) domain = optional(string) })) database_encryption = optional(object({ state = string key_name = string })) gateway_api = optional(bool, false) groups_for_rbac = optional(string) l4_ilb_subsetting = optional(bool, false) mesh_certificates = optional(bool) pod_security_policy = optional(bool, false) secret_manager_config = optional(bool) security_posture_config = optional(object({ mode = string vulnerability_mode = string })) allow_net_admin = optional(bool, false) resource_usage_export = optional(object({ dataset = string enable_network_egress_metering = optional(bool) enable_resource_consumption_metering = optional(bool) })) service_external_ips = optional(bool, true) tpu = optional(bool, false) upgrade_notifications = optional(object({ topic_id = optional(string) })) vertical_pod_autoscaling = optional(bool, false) })">object({…})</code> | | <code>{}</code> |
|
||||
| [issue_client_certificate](variables.tf#L131) | Enable issuing client certificate. | <code>bool</code> | | <code>false</code> |
|
||||
| [labels](variables.tf#L137) | Cluster resource labels. | <code>map(string)</code> | | <code>null</code> |
|
||||
| [logging_config](variables.tf#L148) | Logging configuration. | <code title="object({ enable_api_server_logs = optional(bool, false) enable_scheduler_logs = optional(bool, false) enable_controller_manager_logs = optional(bool, false) })">object({…})</code> | | <code>{}</code> |
|
||||
| [maintenance_config](variables.tf#L159) | Maintenance window configuration. | <code title="object({ daily_window_start_time = optional(string) recurring_window = optional(object({ start_time = string end_time = string recurrence = string })) maintenance_exclusions = optional(list(object({ name = string start_time = string end_time = string scope = optional(string) }))) })">object({…})</code> | | <code title="{ daily_window_start_time = "03:00" recurring_window = null maintenance_exclusion = [] }">{…}</code> |
|
||||
| [min_master_version](variables.tf#L182) | Minimum version of the master, defaults to the version of the most recent official release. | <code>string</code> | | <code>null</code> |
|
||||
| [monitoring_config](variables.tf#L188) | Monitoring configuration. System metrics collection cannot be disabled. Control plane metrics are optional. Kube state metrics are optional. Google Cloud Managed Service for Prometheus is enabled by default. | <code title="object({ enable_api_server_metrics = optional(bool, false) enable_controller_manager_metrics = optional(bool, false) enable_scheduler_metrics = optional(bool, false) enable_daemonset_metrics = optional(bool, false) enable_deployment_metrics = optional(bool, false) enable_hpa_metrics = optional(bool, false) enable_pod_metrics = optional(bool, false) enable_statefulset_metrics = optional(bool, false) enable_storage_metrics = optional(bool, false) enable_managed_prometheus = optional(bool, true) })">object({…})</code> | | <code>{}</code> |
|
||||
| [node_config](variables.tf#L225) | Configuration for nodes and nodepools. | <code title="object({ boot_disk_kms_key = optional(string) service_account = optional(string) tags = optional(list(string)) workload_metadata_config_mode = optional(string) })">object({…})</code> | | <code>{}</code> |
|
||||
| [node_locations](variables.tf#L244) | Zones in which the cluster's nodes are located. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [release_channel](variables.tf#L256) | Release channel for GKE upgrades. Clusters created in the Autopilot mode must use a release channel. Choose between \"RAPID\", \"REGULAR\", and \"STABLE\". | <code>string</code> | | <code>"REGULAR"</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
@@ -232,12 +230,13 @@ module "cluster-1" {
|
||||
|---|---|:---:|
|
||||
| [ca_certificate](outputs.tf#L17) | Public certificate of the cluster (base64-encoded). | ✓ |
|
||||
| [cluster](outputs.tf#L23) | Cluster resource. | ✓ |
|
||||
| [endpoint](outputs.tf#L29) | Cluster endpoint. | |
|
||||
| [id](outputs.tf#L34) | Fully qualified cluster ID. | |
|
||||
| [location](outputs.tf#L39) | Cluster location. | |
|
||||
| [master_version](outputs.tf#L44) | Master version. | |
|
||||
| [name](outputs.tf#L49) | Cluster name. | |
|
||||
| [notifications](outputs.tf#L54) | GKE Pub/Sub notifications topic. | |
|
||||
| [self_link](outputs.tf#L59) | Cluster self link. | ✓ |
|
||||
| [workload_identity_pool](outputs.tf#L65) | Workload identity pool. | |
|
||||
| [dns_endpoint](outputs.tf#L29) | Control plane DNS endpoint. | |
|
||||
| [endpoint](outputs.tf#L37) | Cluster endpoint. | |
|
||||
| [id](outputs.tf#L42) | Fully qualified cluster ID. | |
|
||||
| [location](outputs.tf#L47) | Cluster location. | |
|
||||
| [master_version](outputs.tf#L52) | Master version. | |
|
||||
| [name](outputs.tf#L57) | Cluster name. | |
|
||||
| [notifications](outputs.tf#L62) | GKE Pub/Sub notifications topic. | |
|
||||
| [self_link](outputs.tf#L67) | Cluster self link. | ✓ |
|
||||
| [workload_identity_pool](outputs.tf#L73) | Workload identity pool. | |
|
||||
<!-- END TFDOC -->
|
||||
|
||||
@@ -81,6 +81,14 @@ resource "google_container_cluster" "cluster" {
|
||||
service_account = var.node_config.service_account
|
||||
}
|
||||
}
|
||||
dynamic "control_plane_endpoints_config" {
|
||||
for_each = var.access_config.dns_access == true ? [""] : []
|
||||
content {
|
||||
dns_endpoint_config {
|
||||
allow_external_traffic = true
|
||||
}
|
||||
}
|
||||
}
|
||||
dynamic "database_encryption" {
|
||||
for_each = var.enable_features.database_encryption != null ? [""] : []
|
||||
content {
|
||||
@@ -200,10 +208,10 @@ resource "google_container_cluster" "cluster" {
|
||||
}
|
||||
}
|
||||
dynamic "master_authorized_networks_config" {
|
||||
for_each = var.vpc_config.master_authorized_ranges != null ? [""] : []
|
||||
for_each = try(var.access_config.ip_access.authorized_ranges, null) != null ? [""] : []
|
||||
content {
|
||||
dynamic "cidr_blocks" {
|
||||
for_each = var.vpc_config.master_authorized_ranges
|
||||
for_each = var.access_config.ip_access.authorized_ranges
|
||||
iterator = range
|
||||
content {
|
||||
cidr_block = range.value
|
||||
@@ -260,16 +268,21 @@ resource "google_container_cluster" "cluster" {
|
||||
}
|
||||
}
|
||||
dynamic "private_cluster_config" {
|
||||
for_each = (
|
||||
var.private_cluster_config != null ? [""] : []
|
||||
)
|
||||
for_each = var.access_config.private_nodes == true ? [""] : []
|
||||
content {
|
||||
enable_private_nodes = true
|
||||
enable_private_endpoint = var.private_cluster_config.enable_private_endpoint
|
||||
private_endpoint_subnetwork = try(var.vpc_config.master_endpoint_subnetwork, null)
|
||||
master_ipv4_cidr_block = try(var.vpc_config.master_ipv4_cidr_block, null)
|
||||
enable_private_nodes = true
|
||||
enable_private_endpoint = (
|
||||
var.access_config.ip_access.disable_public_endpoint
|
||||
)
|
||||
private_endpoint_subnetwork = try(
|
||||
var.access_config.ip_access.private_endpoint_config.endpoint_subnetwork,
|
||||
null
|
||||
)
|
||||
master_global_access_config {
|
||||
enabled = var.private_cluster_config.master_global_access
|
||||
enabled = try(
|
||||
var.access_config.ip_access.private_endpoint_config.global_access,
|
||||
null
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -364,20 +377,6 @@ resource "google_gke_backup_backup_plan" "backup_plan" {
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_network_peering_routes_config" "gke_master" {
|
||||
count = (
|
||||
try(var.private_cluster_config.peering_config, null) != null ? 1 : 0
|
||||
)
|
||||
project = coalesce(var.private_cluster_config.peering_config.project_id, var.project_id)
|
||||
peering = try(
|
||||
google_container_cluster.cluster.private_cluster_config[0].peering_name,
|
||||
null
|
||||
)
|
||||
network = element(reverse(split("/", var.vpc_config.network)), 0)
|
||||
import_custom_routes = var.private_cluster_config.peering_config.import_routes
|
||||
export_custom_routes = var.private_cluster_config.peering_config.export_routes
|
||||
}
|
||||
|
||||
resource "google_pubsub_topic" "notifications" {
|
||||
count = (
|
||||
try(var.enable_features.upgrade_notifications, null) != null &&
|
||||
|
||||
@@ -26,6 +26,14 @@ output "cluster" {
|
||||
value = google_container_cluster.cluster
|
||||
}
|
||||
|
||||
output "dns_endpoint" {
|
||||
description = "Control plane DNS endpoint."
|
||||
value = try(
|
||||
google_container_cluster.cluster.control_plane_endpoints_config[0].dns_endpoint_config[0].endpoint,
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
output "endpoint" {
|
||||
description = "Cluster endpoint."
|
||||
value = google_container_cluster.cluster.endpoint
|
||||
|
||||
@@ -14,6 +14,31 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
variable "access_config" {
|
||||
description = "Control plane endpoint and nodes access configurations."
|
||||
type = object({
|
||||
dns_access = optional(bool, true)
|
||||
ip_access = optional(object({
|
||||
authorized_ranges = optional(map(string), {})
|
||||
disable_public_endpoint = optional(bool, true)
|
||||
private_endpoint_config = optional(object({
|
||||
endpoint_subnetwork = optional(string)
|
||||
global_access = optional(bool, true)
|
||||
}), {})
|
||||
}), {})
|
||||
private_nodes = optional(bool, true)
|
||||
})
|
||||
nullable = false
|
||||
default = {}
|
||||
validation {
|
||||
condition = (
|
||||
try(var.access_config.ip_access.disable_public_endpoint, null) != true ||
|
||||
var.access_config.private_nodes == true
|
||||
)
|
||||
error_message = "Private endpoint can only be enabled with private nodes."
|
||||
}
|
||||
}
|
||||
|
||||
variable "backup_configs" {
|
||||
description = "Configuration for Backup for GKE."
|
||||
type = object({
|
||||
@@ -223,20 +248,6 @@ variable "node_locations" {
|
||||
nullable = false
|
||||
}
|
||||
|
||||
variable "private_cluster_config" {
|
||||
description = "Private cluster configuration."
|
||||
type = object({
|
||||
enable_private_endpoint = optional(bool)
|
||||
master_global_access = optional(bool)
|
||||
peering_config = optional(object({
|
||||
export_routes = optional(bool)
|
||||
import_routes = optional(bool)
|
||||
project_id = optional(string)
|
||||
}))
|
||||
})
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "project_id" {
|
||||
description = "Cluster project ID."
|
||||
type = string
|
||||
@@ -256,11 +267,9 @@ variable "release_channel" {
|
||||
variable "vpc_config" {
|
||||
description = "VPC-level configuration."
|
||||
type = object({
|
||||
disable_default_snat = optional(bool)
|
||||
network = string
|
||||
subnetwork = string
|
||||
master_ipv4_cidr_block = optional(string)
|
||||
master_endpoint_subnetwork = optional(string)
|
||||
disable_default_snat = optional(bool)
|
||||
network = string
|
||||
subnetwork = string
|
||||
secondary_range_blocks = optional(object({
|
||||
pods = string
|
||||
services = string
|
||||
@@ -269,9 +278,8 @@ variable "vpc_config" {
|
||||
pods = optional(string)
|
||||
services = optional(string)
|
||||
}))
|
||||
additional_ranges = optional(list(string))
|
||||
master_authorized_ranges = optional(map(string))
|
||||
stack_type = optional(string)
|
||||
additional_ranges = optional(list(string))
|
||||
stack_type = optional(string)
|
||||
})
|
||||
nullable = false
|
||||
}
|
||||
|
||||
@@ -6,25 +6,31 @@ This module offers a way to create and manage Google Kubernetes Engine (GKE) [St
|
||||
> This module should be used together with the [`gke-nodepool`](../gke-nodepool/) module because the default node pool is deleted upon cluster creation by default.
|
||||
|
||||
<!-- BEGIN TOC -->
|
||||
- [Example](#example)
|
||||
- [GKE Standard cluster](#gke-standard-cluster)
|
||||
- [Enable Dataplane V2](#enable-dataplane-v2)
|
||||
- [Managing GKE logs](#managing-gke-logs)
|
||||
- [Monitoring configuration](#monitoring-configuration)
|
||||
- [Disable GKE logs or metrics collection](#disable-gke-logs-or-metrics-collection)
|
||||
- [Cloud DNS](#cloud-dns)
|
||||
- [Backup for GKE](#backup-for-gke)
|
||||
- [Automatic creation of new secondary ranges](#automatic-creation-of-new-secondary-ranges)
|
||||
- [Node auto-provisioning with GPUs and TPUs](#node-auto-provisioning-with-gpus-and-tpus)
|
||||
- [Cluster access configurations](#cluster-access-configurations)
|
||||
- [Private cluster with DNS endpoint enabled](#private-cluster-with-dns-endpoint-enabled)
|
||||
- [Public cluster](#public-cluster)
|
||||
- [Regional cluster](#regional-cluster)
|
||||
- [Enable Dataplane V2](#enable-dataplane-v2)
|
||||
- [Managing GKE logs](#managing-gke-logs)
|
||||
- [Monitoring configuration](#monitoring-configuration)
|
||||
- [Disable GKE logs or metrics collection](#disable-gke-logs-or-metrics-collection)
|
||||
- [Cloud DNS](#cloud-dns)
|
||||
- [Backup for GKE](#backup-for-gke)
|
||||
- [Automatic creation of new secondary ranges](#automatic-creation-of-new-secondary-ranges)
|
||||
- [Node auto-provisioning with GPUs and TPUs](#node-auto-provisioning-with-gpus-and-tpus)
|
||||
- [Variables](#variables)
|
||||
- [Outputs](#outputs)
|
||||
<!-- END TOC -->
|
||||
|
||||
## Example
|
||||
## Cluster access configurations
|
||||
|
||||
### GKE Standard cluster
|
||||
The `access_config` variable can be used to configure access to the control plane, and nodes public access. The following examples illustrate different possible configurations.
|
||||
|
||||
This example shows how to [create a zonal GKE cluster in Standard mode](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-zonal-cluster).
|
||||
### Private cluster with DNS endpoint enabled
|
||||
|
||||
The default module configuration creates a cluster with private nodes, no public endpoint, and access via the DNS endpoint enabled. The default variable configuration is shown in comments.
|
||||
|
||||
Master authorized ranges can be set via the `access_config.ip_access.authorized_ranges` attribute.
|
||||
|
||||
```hcl
|
||||
module "cluster-1" {
|
||||
@@ -32,6 +38,20 @@ module "cluster-1" {
|
||||
project_id = "myproject"
|
||||
name = "cluster-1"
|
||||
location = "europe-west1-b"
|
||||
# access_config can be omitted if master authorized ranges are not needed
|
||||
access_config = {
|
||||
# dns_access = true
|
||||
ip_access = {
|
||||
authorized_ranges = {
|
||||
internal-vms = "10.0.0.0/8"
|
||||
}
|
||||
# disable_public_endpoint = true
|
||||
# private_endpoint_config = {
|
||||
# global_access = true
|
||||
# }
|
||||
}
|
||||
# private_nodes = true
|
||||
}
|
||||
vpc_config = {
|
||||
network = var.vpc.self_link
|
||||
subnetwork = var.subnet.self_link
|
||||
@@ -39,24 +59,86 @@ module "cluster-1" {
|
||||
pods = "pods"
|
||||
services = "services"
|
||||
}
|
||||
master_authorized_ranges = {
|
||||
internal-vms = "10.0.0.0/8"
|
||||
}
|
||||
master_ipv4_cidr_block = "192.168.0.0/28"
|
||||
}
|
||||
max_pods_per_node = 32
|
||||
private_cluster_config = {
|
||||
enable_private_endpoint = true
|
||||
master_global_access = false
|
||||
}
|
||||
labels = {
|
||||
environment = "dev"
|
||||
}
|
||||
}
|
||||
# tftest modules=1 resources=1 inventory=basic.yaml
|
||||
# tftest modules=1 resources=1 inventory=access-private.yaml
|
||||
```
|
||||
|
||||
### Enable Dataplane V2
|
||||
### Public cluster
|
||||
|
||||
To configure a public cluster, turn off `access_config.ip_access.disable_public_endpoint`. Nodes can be left as private or made public if needed, like in the example below. DNS endpoint is turned off here as it's probably redundant for a public cluster.
|
||||
|
||||
```hcl
|
||||
module "cluster-1" {
|
||||
source = "./fabric/modules/gke-cluster-standard"
|
||||
project_id = "myproject"
|
||||
name = "cluster-1"
|
||||
location = "europe-west1-b"
|
||||
access_config = {
|
||||
dns_access = false
|
||||
ip_access = {
|
||||
authorized_ranges = {
|
||||
"corporate proxy" = "8.8.8.8/32"
|
||||
}
|
||||
disable_public_endpoint = false
|
||||
}
|
||||
private_nodes = false
|
||||
}
|
||||
vpc_config = {
|
||||
network = var.vpc.self_link
|
||||
subnetwork = var.subnet.self_link
|
||||
secondary_range_names = {
|
||||
pods = "pods"
|
||||
services = "services"
|
||||
}
|
||||
}
|
||||
max_pods_per_node = 32
|
||||
labels = {
|
||||
environment = "dev"
|
||||
}
|
||||
}
|
||||
# tftest modules=1 resources=1 inventory=access-public.yaml
|
||||
```
|
||||
|
||||
## Regional cluster
|
||||
|
||||
Regional clusters are created by setting `location` to a GCP region and then configuring `node_locations`, as shown in the example below.
|
||||
|
||||
```hcl
|
||||
module "cluster-1" {
|
||||
source = "./fabric/modules/gke-cluster-standard"
|
||||
project_id = "myproject"
|
||||
name = "cluster-1"
|
||||
location = "europe-west1"
|
||||
node_locations = ["europe-west1-b"]
|
||||
access_config = {
|
||||
ip_access = {
|
||||
authorized_ranges = {
|
||||
internal-vms = "10.0.0.0/8"
|
||||
}
|
||||
}
|
||||
}
|
||||
vpc_config = {
|
||||
network = var.vpc.self_link
|
||||
subnetwork = var.subnet.self_link
|
||||
secondary_range_names = {
|
||||
pods = "pods"
|
||||
services = "services"
|
||||
}
|
||||
}
|
||||
max_pods_per_node = 32
|
||||
labels = {
|
||||
environment = "dev"
|
||||
}
|
||||
}
|
||||
# tftest modules=1 resources=1 inventory=regional.yaml
|
||||
```
|
||||
|
||||
## Enable Dataplane V2
|
||||
|
||||
This example shows how to [create a zonal GKE Cluster with Dataplane V2 enabled](https://cloud.google.com/kubernetes-engine/docs/how-to/dataplane-v2).
|
||||
|
||||
@@ -70,14 +152,6 @@ module "cluster-1" {
|
||||
network = var.vpc.self_link
|
||||
subnetwork = var.subnet.self_link
|
||||
secondary_range_names = {} # use default names "pods" and "services"
|
||||
master_authorized_ranges = {
|
||||
internal-vms = "10.0.0.0/8"
|
||||
}
|
||||
master_ipv4_cidr_block = "192.168.0.0/28"
|
||||
}
|
||||
private_cluster_config = {
|
||||
enable_private_endpoint = true
|
||||
master_global_access = false
|
||||
}
|
||||
enable_features = {
|
||||
dataplane_v2 = true
|
||||
@@ -89,10 +163,10 @@ module "cluster-1" {
|
||||
environment = "dev"
|
||||
}
|
||||
}
|
||||
# tftest modules=1 resources=1 inventory=dataplane-v2.yaml
|
||||
# tftest modules=1 resources=1
|
||||
```
|
||||
|
||||
### Managing GKE logs
|
||||
## Managing GKE logs
|
||||
|
||||
This example shows you how to [control which logs are sent from your GKE cluster to Cloud Logging](https://cloud.google.com/stackdriver/docs/solutions/gke/installing).
|
||||
|
||||
@@ -119,7 +193,7 @@ module "cluster-1" {
|
||||
# tftest modules=1 resources=1 inventory=logging-config-enable-all.yaml
|
||||
```
|
||||
|
||||
### Monitoring configuration
|
||||
## Monitoring configuration
|
||||
|
||||
This example shows how to [configure collection of Kubernetes control plane metrics](https://cloud.google.com/stackdriver/docs/solutions/gke/managing-metrics#enable-control-plane-metrics). These metrics are optional and are not collected by default.
|
||||
|
||||
@@ -173,7 +247,7 @@ module "cluster-1" {
|
||||
|
||||
The *control plane metrics* and *kube state metrics* collection can be configured in a single `monitoring_config` block.
|
||||
|
||||
### Disable GKE logs or metrics collection
|
||||
## Disable GKE logs or metrics collection
|
||||
|
||||
> [!WARNING]
|
||||
> If you've disabled Cloud Logging or Cloud Monitoring, GKE customer support
|
||||
@@ -221,7 +295,7 @@ module "cluster-1" {
|
||||
# tftest modules=1 resources=1 inventory=monitoring-config-disable-all.yaml
|
||||
```
|
||||
|
||||
### Cloud DNS
|
||||
## Cloud DNS
|
||||
|
||||
This example shows how to [use Cloud DNS as a Kubernetes DNS provider](https://cloud.google.com/kubernetes-engine/docs/how-to/cloud-dns) for GKE Standard clusters.
|
||||
|
||||
@@ -247,7 +321,7 @@ module "cluster-1" {
|
||||
# tftest modules=1 resources=1 inventory=dns.yaml
|
||||
```
|
||||
|
||||
### Backup for GKE
|
||||
## Backup for GKE
|
||||
|
||||
> [!NOTE]
|
||||
> Although Backup for GKE can be enabled as an add-on when configuring your GKE clusters, it is a separate service from GKE.
|
||||
@@ -286,7 +360,7 @@ module "cluster-1" {
|
||||
# tftest modules=1 resources=2 inventory=backup.yaml
|
||||
```
|
||||
|
||||
### Automatic creation of new secondary ranges
|
||||
## Automatic creation of new secondary ranges
|
||||
|
||||
You can use `var.vpc_config.secondary_range_blocks` to let GKE create new secondary ranges for the cluster. The example below reserves an available /14 block for pods and a /20 for services.
|
||||
|
||||
@@ -308,7 +382,7 @@ module "cluster-1" {
|
||||
# tftest modules=1 resources=1
|
||||
```
|
||||
|
||||
### Node auto-provisioning with GPUs and TPUs
|
||||
## Node auto-provisioning with GPUs and TPUs
|
||||
|
||||
You can use `var.cluster_autoscaling` block to configure node auto-provisioning for the GKE cluster. The example below configures limits for CPU, memory, GPUs and TPUs.
|
||||
|
||||
@@ -353,41 +427,42 @@ module "cluster-1" {
|
||||
|
||||
| name | description | type | required | default |
|
||||
|---|---|:---:|:---:|:---:|
|
||||
| [location](variables.tf#L243) | Cluster zone or region. | <code>string</code> | ✓ | |
|
||||
| [name](variables.tf#L355) | Cluster name. | <code>string</code> | ✓ | |
|
||||
| [project_id](variables.tf#L402) | Cluster project id. | <code>string</code> | ✓ | |
|
||||
| [vpc_config](variables.tf#L413) | VPC-level configuration. | <code title="object({ disable_default_snat = optional(bool) network = string subnetwork = string master_ipv4_cidr_block = optional(string) master_endpoint_subnetwork = optional(string) secondary_range_blocks = optional(object({ pods = string services = string })) secondary_range_names = optional(object({ pods = optional(string) services = optional(string) })) additional_ranges = optional(list(string)) master_authorized_ranges = optional(map(string)) stack_type = optional(string) })">object({…})</code> | ✓ | |
|
||||
| [backup_configs](variables.tf#L18) | Configuration for Backup for GKE. | <code title="object({ enable_backup_agent = optional(bool, false) backup_plans = optional(map(object({ region = string applications = optional(map(list(string))) encryption_key = optional(string) include_secrets = optional(bool, true) include_volume_data = optional(bool, true) labels = optional(map(string)) namespaces = optional(list(string)) schedule = optional(string) retention_policy_days = optional(number) retention_policy_lock = optional(bool, false) retention_policy_delete_lock_days = optional(number) })), {}) })">object({…})</code> | | <code>{}</code> |
|
||||
| [cluster_autoscaling](variables.tf#L40) | Enable and configure limits for Node Auto-Provisioning with Cluster Autoscaler. | <code title="object({ enabled = optional(bool, true) autoscaling_profile = optional(string, "BALANCED") auto_provisioning_defaults = optional(object({ boot_disk_kms_key = optional(string) disk_size = optional(number) disk_type = optional(string, "pd-standard") image_type = optional(string) oauth_scopes = optional(list(string)) service_account = optional(string) management = optional(object({ auto_repair = optional(bool, true) auto_upgrade = optional(bool, true) })) shielded_instance_config = optional(object({ integrity_monitoring = optional(bool, true) secure_boot = optional(bool, false) })) upgrade_settings = optional(object({ blue_green = optional(object({ node_pool_soak_duration = optional(string) standard_rollout_policy = optional(object({ batch_percentage = optional(number) batch_node_count = optional(number) batch_soak_duration = optional(string) })) })) surge = optional(object({ max = optional(number) unavailable = optional(number) })) })) })) cpu_limits = optional(object({ min = optional(number, 0) max = number })) mem_limits = optional(object({ min = optional(number, 0) max = number })) accelerator_resources = optional(list(object({ resource_type = string min = optional(number, 0) max = number }))) })">object({…})</code> | | <code>null</code> |
|
||||
| [default_nodepool](variables.tf#L119) | Enable default nodepool. | <code title="object({ remove_pool = optional(bool, true) initial_node_count = optional(number, 1) })">object({…})</code> | | <code>{}</code> |
|
||||
| [deletion_protection](variables.tf#L137) | Whether or not to allow Terraform to destroy the cluster. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the cluster will fail. | <code>bool</code> | | <code>true</code> |
|
||||
| [description](variables.tf#L144) | Cluster description. | <code>string</code> | | <code>null</code> |
|
||||
| [enable_addons](variables.tf#L150) | Addons enabled in the cluster (true means enabled). | <code title="object({ cloudrun = optional(bool, false) config_connector = optional(bool, false) dns_cache = optional(bool, false) gce_persistent_disk_csi_driver = optional(bool, false) gcp_filestore_csi_driver = optional(bool, false) gcs_fuse_csi_driver = optional(bool, false) horizontal_pod_autoscaling = optional(bool, false) http_load_balancing = optional(bool, false) istio = optional(object({ enable_tls = bool })) kalm = optional(bool, false) network_policy = optional(bool, false) stateful_ha = optional(bool, false) })">object({…})</code> | | <code title="{ horizontal_pod_autoscaling = true http_load_balancing = true }">{…}</code> |
|
||||
| [enable_features](variables.tf#L175) | Enable cluster-level features. Certain features allow configuration. | <code title="object({ beta_apis = optional(list(string)) binary_authorization = optional(bool, false) cilium_clusterwide_network_policy = optional(bool, false) cost_management = optional(bool, false) dns = optional(object({ provider = optional(string) scope = optional(string) domain = optional(string) })) database_encryption = optional(object({ state = string key_name = string })) dataplane_v2 = optional(bool, false) fqdn_network_policy = optional(bool, false) gateway_api = optional(bool, false) groups_for_rbac = optional(string) image_streaming = optional(bool, false) intranode_visibility = optional(bool, false) l4_ilb_subsetting = optional(bool, false) mesh_certificates = optional(bool) pod_security_policy = optional(bool, false) secret_manager_config = optional(bool) security_posture_config = optional(object({ mode = string vulnerability_mode = string })) resource_usage_export = optional(object({ dataset = string enable_network_egress_metering = optional(bool) enable_resource_consumption_metering = optional(bool) })) service_external_ips = optional(bool, true) shielded_nodes = optional(bool, false) tpu = optional(bool, false) upgrade_notifications = optional(object({ topic_id = optional(string) })) vertical_pod_autoscaling = optional(bool, false) workload_identity = optional(bool, true) })">object({…})</code> | | <code title="{ workload_identity = true }">{…}</code> |
|
||||
| [issue_client_certificate](variables.tf#L230) | Enable issuing client certificate. | <code>bool</code> | | <code>false</code> |
|
||||
| [labels](variables.tf#L236) | Cluster resource labels. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [logging_config](variables.tf#L248) | Logging configuration. | <code title="object({ enable_system_logs = optional(bool, true) enable_workloads_logs = optional(bool, false) enable_api_server_logs = optional(bool, false) enable_scheduler_logs = optional(bool, false) enable_controller_manager_logs = optional(bool, false) })">object({…})</code> | | <code>{}</code> |
|
||||
| [maintenance_config](variables.tf#L269) | Maintenance window configuration. | <code title="object({ daily_window_start_time = optional(string) recurring_window = optional(object({ start_time = string end_time = string recurrence = string })) maintenance_exclusions = optional(list(object({ name = string start_time = string end_time = string scope = optional(string) }))) })">object({…})</code> | | <code title="{ daily_window_start_time = "03:00" recurring_window = null maintenance_exclusion = [] }">{…}</code> |
|
||||
| [max_pods_per_node](variables.tf#L292) | Maximum number of pods per node in this cluster. | <code>number</code> | | <code>110</code> |
|
||||
| [min_master_version](variables.tf#L298) | Minimum version of the master, defaults to the version of the most recent official release. | <code>string</code> | | <code>null</code> |
|
||||
| [monitoring_config](variables.tf#L304) | Monitoring configuration. Google Cloud Managed Service for Prometheus is enabled by default. | <code title="object({ enable_system_metrics = optional(bool, true) enable_api_server_metrics = optional(bool, false) enable_controller_manager_metrics = optional(bool, false) enable_scheduler_metrics = optional(bool, false) enable_daemonset_metrics = optional(bool, false) enable_deployment_metrics = optional(bool, false) enable_hpa_metrics = optional(bool, false) enable_pod_metrics = optional(bool, false) enable_statefulset_metrics = optional(bool, false) enable_storage_metrics = optional(bool, false) enable_managed_prometheus = optional(bool, true) advanced_datapath_observability = optional(object({ enable_metrics = bool enable_relay = bool })) })">object({…})</code> | | <code>{}</code> |
|
||||
| [node_config](variables.tf#L360) | Node-level configuration. | <code title="object({ boot_disk_kms_key = optional(string) k8s_labels = optional(map(string)) labels = optional(map(string)) service_account = optional(string) tags = optional(list(string)) workload_metadata_config_mode = optional(string) })">object({…})</code> | | <code>{}</code> |
|
||||
| [node_locations](variables.tf#L381) | Zones in which the cluster's nodes are located. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [private_cluster_config](variables.tf#L388) | Private cluster configuration. | <code title="object({ enable_private_endpoint = optional(bool) master_global_access = optional(bool) peering_config = optional(object({ export_routes = optional(bool) import_routes = optional(bool) project_id = optional(string) })) })">object({…})</code> | | <code>null</code> |
|
||||
| [release_channel](variables.tf#L407) | Release channel for GKE upgrades. | <code>string</code> | | <code>null</code> |
|
||||
| [location](variables.tf#L267) | Cluster zone or region. | <code>string</code> | ✓ | |
|
||||
| [name](variables.tf#L379) | Cluster name. | <code>string</code> | ✓ | |
|
||||
| [project_id](variables.tf#L412) | Cluster project id. | <code>string</code> | ✓ | |
|
||||
| [vpc_config](variables.tf#L423) | VPC-level configuration. | <code title="object({ disable_default_snat = optional(bool) network = string subnetwork = string secondary_range_blocks = optional(object({ pods = string services = string })) secondary_range_names = optional(object({ pods = optional(string) services = optional(string) })) additional_ranges = optional(list(string)) stack_type = optional(string) })">object({…})</code> | ✓ | |
|
||||
| [access_config](variables.tf#L17) | Control plane endpoint and nodes access configurations. | <code title="object({ dns_access = optional(bool, true) ip_access = optional(object({ authorized_ranges = optional(map(string), {}) disable_public_endpoint = optional(bool, true) private_endpoint_config = optional(object({ endpoint_subnetwork = optional(string) global_access = optional(bool, true) }), {}) }), {}) private_nodes = optional(bool, true) })">object({…})</code> | | <code>{}</code> |
|
||||
| [backup_configs](variables.tf#L42) | Configuration for Backup for GKE. | <code title="object({ enable_backup_agent = optional(bool, false) backup_plans = optional(map(object({ region = string applications = optional(map(list(string))) encryption_key = optional(string) include_secrets = optional(bool, true) include_volume_data = optional(bool, true) labels = optional(map(string)) namespaces = optional(list(string)) schedule = optional(string) retention_policy_days = optional(number) retention_policy_lock = optional(bool, false) retention_policy_delete_lock_days = optional(number) })), {}) })">object({…})</code> | | <code>{}</code> |
|
||||
| [cluster_autoscaling](variables.tf#L64) | Enable and configure limits for Node Auto-Provisioning with Cluster Autoscaler. | <code title="object({ enabled = optional(bool, true) autoscaling_profile = optional(string, "BALANCED") auto_provisioning_defaults = optional(object({ boot_disk_kms_key = optional(string) disk_size = optional(number) disk_type = optional(string, "pd-standard") image_type = optional(string) oauth_scopes = optional(list(string)) service_account = optional(string) management = optional(object({ auto_repair = optional(bool, true) auto_upgrade = optional(bool, true) })) shielded_instance_config = optional(object({ integrity_monitoring = optional(bool, true) secure_boot = optional(bool, false) })) upgrade_settings = optional(object({ blue_green = optional(object({ node_pool_soak_duration = optional(string) standard_rollout_policy = optional(object({ batch_percentage = optional(number) batch_node_count = optional(number) batch_soak_duration = optional(string) })) })) surge = optional(object({ max = optional(number) unavailable = optional(number) })) })) })) cpu_limits = optional(object({ min = optional(number, 0) max = number })) mem_limits = optional(object({ min = optional(number, 0) max = number })) accelerator_resources = optional(list(object({ resource_type = string min = optional(number, 0) max = number }))) })">object({…})</code> | | <code>null</code> |
|
||||
| [default_nodepool](variables.tf#L143) | Enable default nodepool. | <code title="object({ remove_pool = optional(bool, true) initial_node_count = optional(number, 1) })">object({…})</code> | | <code>{}</code> |
|
||||
| [deletion_protection](variables.tf#L161) | Whether or not to allow Terraform to destroy the cluster. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the cluster will fail. | <code>bool</code> | | <code>true</code> |
|
||||
| [description](variables.tf#L168) | Cluster description. | <code>string</code> | | <code>null</code> |
|
||||
| [enable_addons](variables.tf#L174) | Addons enabled in the cluster (true means enabled). | <code title="object({ cloudrun = optional(bool, false) config_connector = optional(bool, false) dns_cache = optional(bool, false) gce_persistent_disk_csi_driver = optional(bool, false) gcp_filestore_csi_driver = optional(bool, false) gcs_fuse_csi_driver = optional(bool, false) horizontal_pod_autoscaling = optional(bool, false) http_load_balancing = optional(bool, false) istio = optional(object({ enable_tls = bool })) kalm = optional(bool, false) network_policy = optional(bool, false) stateful_ha = optional(bool, false) })">object({…})</code> | | <code title="{ horizontal_pod_autoscaling = true http_load_balancing = true }">{…}</code> |
|
||||
| [enable_features](variables.tf#L199) | Enable cluster-level features. Certain features allow configuration. | <code title="object({ beta_apis = optional(list(string)) binary_authorization = optional(bool, false) cilium_clusterwide_network_policy = optional(bool, false) cost_management = optional(bool, false) dns = optional(object({ provider = optional(string) scope = optional(string) domain = optional(string) })) database_encryption = optional(object({ state = string key_name = string })) dataplane_v2 = optional(bool, false) fqdn_network_policy = optional(bool, false) gateway_api = optional(bool, false) groups_for_rbac = optional(string) image_streaming = optional(bool, false) intranode_visibility = optional(bool, false) l4_ilb_subsetting = optional(bool, false) mesh_certificates = optional(bool) pod_security_policy = optional(bool, false) secret_manager_config = optional(bool) security_posture_config = optional(object({ mode = string vulnerability_mode = string })) resource_usage_export = optional(object({ dataset = string enable_network_egress_metering = optional(bool) enable_resource_consumption_metering = optional(bool) })) service_external_ips = optional(bool, true) shielded_nodes = optional(bool, false) tpu = optional(bool, false) upgrade_notifications = optional(object({ topic_id = optional(string) })) vertical_pod_autoscaling = optional(bool, false) workload_identity = optional(bool, true) })">object({…})</code> | | <code title="{ workload_identity = true }">{…}</code> |
|
||||
| [issue_client_certificate](variables.tf#L254) | Enable issuing client certificate. | <code>bool</code> | | <code>false</code> |
|
||||
| [labels](variables.tf#L260) | Cluster resource labels. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [logging_config](variables.tf#L272) | Logging configuration. | <code title="object({ enable_system_logs = optional(bool, true) enable_workloads_logs = optional(bool, false) enable_api_server_logs = optional(bool, false) enable_scheduler_logs = optional(bool, false) enable_controller_manager_logs = optional(bool, false) })">object({…})</code> | | <code>{}</code> |
|
||||
| [maintenance_config](variables.tf#L293) | Maintenance window configuration. | <code title="object({ daily_window_start_time = optional(string) recurring_window = optional(object({ start_time = string end_time = string recurrence = string })) maintenance_exclusions = optional(list(object({ name = string start_time = string end_time = string scope = optional(string) }))) })">object({…})</code> | | <code title="{ daily_window_start_time = "03:00" recurring_window = null maintenance_exclusion = [] }">{…}</code> |
|
||||
| [max_pods_per_node](variables.tf#L316) | Maximum number of pods per node in this cluster. | <code>number</code> | | <code>110</code> |
|
||||
| [min_master_version](variables.tf#L322) | Minimum version of the master, defaults to the version of the most recent official release. | <code>string</code> | | <code>null</code> |
|
||||
| [monitoring_config](variables.tf#L328) | Monitoring configuration. Google Cloud Managed Service for Prometheus is enabled by default. | <code title="object({ enable_system_metrics = optional(bool, true) enable_api_server_metrics = optional(bool, false) enable_controller_manager_metrics = optional(bool, false) enable_scheduler_metrics = optional(bool, false) enable_daemonset_metrics = optional(bool, false) enable_deployment_metrics = optional(bool, false) enable_hpa_metrics = optional(bool, false) enable_pod_metrics = optional(bool, false) enable_statefulset_metrics = optional(bool, false) enable_storage_metrics = optional(bool, false) enable_managed_prometheus = optional(bool, true) advanced_datapath_observability = optional(object({ enable_metrics = bool enable_relay = bool })) })">object({…})</code> | | <code>{}</code> |
|
||||
| [node_config](variables.tf#L384) | Node-level configuration. | <code title="object({ boot_disk_kms_key = optional(string) k8s_labels = optional(map(string)) labels = optional(map(string)) service_account = optional(string) tags = optional(list(string)) workload_metadata_config_mode = optional(string) })">object({…})</code> | | <code>{}</code> |
|
||||
| [node_locations](variables.tf#L405) | Zones in which the cluster's nodes are located. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [release_channel](variables.tf#L417) | Release channel for GKE upgrades. | <code>string</code> | | <code>null</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
| name | description | sensitive |
|
||||
|---|---|:---:|
|
||||
| [ca_certificate](outputs.tf#L17) | Public certificate of the cluster (base64-encoded). | ✓ |
|
||||
| [cluster](outputs.tf#L23) | Cluster resource. | ✓ |
|
||||
| [endpoint](outputs.tf#L29) | Cluster endpoint. | |
|
||||
| [id](outputs.tf#L34) | FUlly qualified cluster id. | |
|
||||
| [location](outputs.tf#L39) | Cluster location. | |
|
||||
| [master_version](outputs.tf#L44) | Master version. | |
|
||||
| [name](outputs.tf#L49) | Cluster name. | |
|
||||
| [notifications](outputs.tf#L54) | GKE PubSub notifications topic. | |
|
||||
| [self_link](outputs.tf#L59) | Cluster self link. | ✓ |
|
||||
| [workload_identity_pool](outputs.tf#L65) | Workload identity pool. | |
|
||||
| [cluster](outputs.tf#L25) | Cluster resource. | ✓ |
|
||||
| [dns_endpoint](outputs.tf#L31) | Control plane DNS endpoint. | |
|
||||
| [endpoint](outputs.tf#L39) | Cluster endpoint. | |
|
||||
| [id](outputs.tf#L44) | FUlly qualified cluster id. | |
|
||||
| [location](outputs.tf#L49) | Cluster location. | |
|
||||
| [master_version](outputs.tf#L54) | Master version. | |
|
||||
| [name](outputs.tf#L59) | Cluster name. | |
|
||||
| [notifications](outputs.tf#L64) | GKE PubSub notifications topic. | |
|
||||
| [self_link](outputs.tf#L69) | Cluster self link. | ✓ |
|
||||
| [workload_identity_pool](outputs.tf#L75) | Workload identity pool. | |
|
||||
<!-- END TFDOC -->
|
||||
|
||||
@@ -249,6 +249,14 @@ resource "google_container_cluster" "cluster" {
|
||||
}
|
||||
}
|
||||
}
|
||||
dynamic "control_plane_endpoints_config" {
|
||||
for_each = var.access_config.dns_access == true ? [""] : []
|
||||
content {
|
||||
dns_endpoint_config {
|
||||
allow_external_traffic = true
|
||||
}
|
||||
}
|
||||
}
|
||||
dynamic "database_encryption" {
|
||||
for_each = var.enable_features.database_encryption != null ? [""] : []
|
||||
content {
|
||||
@@ -384,10 +392,10 @@ resource "google_container_cluster" "cluster" {
|
||||
}
|
||||
}
|
||||
dynamic "master_authorized_networks_config" {
|
||||
for_each = var.vpc_config.master_authorized_ranges != null ? [""] : []
|
||||
for_each = try(var.access_config.ip_access.authorized_ranges, null) != null ? [""] : []
|
||||
content {
|
||||
dynamic "cidr_blocks" {
|
||||
for_each = var.vpc_config.master_authorized_ranges
|
||||
for_each = var.access_config.ip_access.authorized_ranges
|
||||
iterator = range
|
||||
content {
|
||||
cidr_block = range.value
|
||||
@@ -464,16 +472,21 @@ resource "google_container_cluster" "cluster" {
|
||||
}
|
||||
}
|
||||
dynamic "private_cluster_config" {
|
||||
for_each = (
|
||||
var.private_cluster_config != null ? [""] : []
|
||||
)
|
||||
for_each = var.access_config.private_nodes == true ? [""] : []
|
||||
content {
|
||||
enable_private_nodes = true
|
||||
enable_private_endpoint = var.private_cluster_config.enable_private_endpoint
|
||||
private_endpoint_subnetwork = try(var.vpc_config.master_endpoint_subnetwork, null)
|
||||
master_ipv4_cidr_block = try(var.vpc_config.master_ipv4_cidr_block, null)
|
||||
enable_private_nodes = true
|
||||
enable_private_endpoint = (
|
||||
var.access_config.ip_access.disable_public_endpoint
|
||||
)
|
||||
private_endpoint_subnetwork = try(
|
||||
var.access_config.ip_access.private_endpoint_config.endpoint_subnetwork,
|
||||
null
|
||||
)
|
||||
master_global_access_config {
|
||||
enabled = var.private_cluster_config.master_global_access
|
||||
enabled = try(
|
||||
var.access_config.ip_access.private_endpoint_config.global_access,
|
||||
null
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -600,21 +613,6 @@ resource "google_gke_backup_backup_plan" "backup_plan" {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
resource "google_compute_network_peering_routes_config" "gke_master" {
|
||||
count = (
|
||||
try(var.private_cluster_config.peering_config, null) != null ? 1 : 0
|
||||
)
|
||||
project = coalesce(var.private_cluster_config.peering_config.project_id, var.project_id)
|
||||
peering = try(
|
||||
google_container_cluster.cluster.private_cluster_config[0].peering_name,
|
||||
null
|
||||
)
|
||||
network = element(reverse(split("/", var.vpc_config.network)), 0)
|
||||
import_custom_routes = var.private_cluster_config.peering_config.import_routes
|
||||
export_custom_routes = var.private_cluster_config.peering_config.export_routes
|
||||
}
|
||||
|
||||
resource "google_pubsub_topic" "notifications" {
|
||||
count = (
|
||||
try(var.enable_features.upgrade_notifications, null) != null &&
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
|
||||
output "ca_certificate" {
|
||||
description = "Public certificate of the cluster (base64-encoded)."
|
||||
value = google_container_cluster.cluster.master_auth[0].cluster_ca_certificate
|
||||
sensitive = true
|
||||
value = (
|
||||
google_container_cluster.cluster.master_auth[0].cluster_ca_certificate
|
||||
)
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
output "cluster" {
|
||||
@@ -26,6 +28,14 @@ output "cluster" {
|
||||
value = google_container_cluster.cluster
|
||||
}
|
||||
|
||||
output "dns_endpoint" {
|
||||
description = "Control plane DNS endpoint."
|
||||
value = try(
|
||||
google_container_cluster.cluster.control_plane_endpoints_config[0].dns_endpoint_config[0].endpoint,
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
output "endpoint" {
|
||||
description = "Cluster endpoint."
|
||||
value = google_container_cluster.cluster.endpoint
|
||||
|
||||
@@ -14,6 +14,30 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
variable "access_config" {
|
||||
description = "Control plane endpoint and nodes access configurations."
|
||||
type = object({
|
||||
dns_access = optional(bool, true)
|
||||
ip_access = optional(object({
|
||||
authorized_ranges = optional(map(string), {})
|
||||
disable_public_endpoint = optional(bool, true)
|
||||
private_endpoint_config = optional(object({
|
||||
endpoint_subnetwork = optional(string)
|
||||
global_access = optional(bool, true)
|
||||
}), {})
|
||||
}), {})
|
||||
private_nodes = optional(bool, true)
|
||||
})
|
||||
nullable = false
|
||||
default = {}
|
||||
validation {
|
||||
condition = (
|
||||
try(var.access_config.ip_access.disable_public_endpoint, null) != true ||
|
||||
var.access_config.private_nodes == true
|
||||
)
|
||||
error_message = "Private endpoint can only be enabled with private nodes."
|
||||
}
|
||||
}
|
||||
|
||||
variable "backup_configs" {
|
||||
description = "Configuration for Backup for GKE."
|
||||
@@ -385,20 +409,6 @@ variable "node_locations" {
|
||||
nullable = false
|
||||
}
|
||||
|
||||
variable "private_cluster_config" {
|
||||
description = "Private cluster configuration."
|
||||
type = object({
|
||||
enable_private_endpoint = optional(bool)
|
||||
master_global_access = optional(bool)
|
||||
peering_config = optional(object({
|
||||
export_routes = optional(bool)
|
||||
import_routes = optional(bool)
|
||||
project_id = optional(string)
|
||||
}))
|
||||
})
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "project_id" {
|
||||
description = "Cluster project id."
|
||||
type = string
|
||||
@@ -413,11 +423,9 @@ variable "release_channel" {
|
||||
variable "vpc_config" {
|
||||
description = "VPC-level configuration."
|
||||
type = object({
|
||||
disable_default_snat = optional(bool)
|
||||
network = string
|
||||
subnetwork = string
|
||||
master_ipv4_cidr_block = optional(string)
|
||||
master_endpoint_subnetwork = optional(string)
|
||||
disable_default_snat = optional(bool)
|
||||
network = string
|
||||
subnetwork = string
|
||||
secondary_range_blocks = optional(object({
|
||||
pods = string
|
||||
services = string
|
||||
@@ -426,9 +434,8 @@ variable "vpc_config" {
|
||||
pods = optional(string)
|
||||
services = optional(string)
|
||||
}))
|
||||
additional_ranges = optional(list(string))
|
||||
master_authorized_ranges = optional(map(string))
|
||||
stack_type = optional(string)
|
||||
additional_ranges = optional(list(string))
|
||||
stack_type = optional(string)
|
||||
})
|
||||
nullable = false
|
||||
}
|
||||
|
||||
@@ -50,22 +50,21 @@ module "cluster_1" {
|
||||
project_id = module.project.project_id
|
||||
name = "cluster-1"
|
||||
location = "europe-west1"
|
||||
access_config = {
|
||||
ip_access = {
|
||||
authorized_ranges = {
|
||||
rfc1918_10_8 = "10.0.0.0/8"
|
||||
}
|
||||
}
|
||||
}
|
||||
vpc_config = {
|
||||
network = module.vpc.self_link
|
||||
subnetwork = module.vpc.subnet_self_links["europe-west1/cluster-1"]
|
||||
master_authorized_ranges = {
|
||||
rfc1918_10_8 = "10.0.0.0/8"
|
||||
}
|
||||
master_ipv4_cidr_block = "192.168.0.0/28"
|
||||
}
|
||||
enable_features = {
|
||||
dataplane_v2 = true
|
||||
workload_identity = true
|
||||
}
|
||||
private_cluster_config = {
|
||||
enable_private_endpoint = true
|
||||
master_global_access = false
|
||||
}
|
||||
}
|
||||
|
||||
module "hub" {
|
||||
@@ -196,20 +195,18 @@ module "cluster_1" {
|
||||
project_id = module.project.project_id
|
||||
name = "cluster-1"
|
||||
location = "europe-west1"
|
||||
access_config = {
|
||||
ip_access = {
|
||||
authorized_ranges = {
|
||||
mgmt = "10.0.0.0/28"
|
||||
pods-cluster-1 = "10.3.0.0/16"
|
||||
}
|
||||
}
|
||||
}
|
||||
vpc_config = {
|
||||
network = module.vpc.self_link
|
||||
subnetwork = module.vpc.subnet_self_links["europe-west1/subnet-cluster-1"]
|
||||
master_authorized_ranges = {
|
||||
mgmt = "10.0.0.0/28"
|
||||
pods-cluster-1 = "10.3.0.0/16"
|
||||
}
|
||||
master_ipv4_cidr_block = "192.168.1.0/28"
|
||||
}
|
||||
private_cluster_config = {
|
||||
enable_private_endpoint = false
|
||||
master_global_access = true
|
||||
}
|
||||
|
||||
release_channel = "REGULAR"
|
||||
labels = {
|
||||
mesh_id = "proj-${module.project.number}"
|
||||
@@ -237,18 +234,17 @@ module "cluster_2" {
|
||||
project_id = module.project.project_id
|
||||
name = "cluster-2"
|
||||
location = "europe-west4"
|
||||
access_config = {
|
||||
ip_access = {
|
||||
authorized_ranges = {
|
||||
mgmt = "10.0.0.0/28"
|
||||
pods-cluster-1 = "10.3.0.0/16"
|
||||
}
|
||||
}
|
||||
}
|
||||
vpc_config = {
|
||||
network = module.vpc.self_link
|
||||
subnetwork = module.vpc.subnet_self_links["europe-west4/subnet-cluster-2"]
|
||||
master_authorized_ranges = {
|
||||
mgmt = "10.0.0.0/28"
|
||||
pods-cluster-1 = "10.3.0.0/16"
|
||||
}
|
||||
master_ipv4_cidr_block = "192.168.2.0/28"
|
||||
}
|
||||
private_cluster_config = {
|
||||
enable_private_endpoint = false
|
||||
master_global_access = true
|
||||
}
|
||||
release_channel = "REGULAR"
|
||||
labels = {
|
||||
|
||||
Reference in New Issue
Block a user