gke-cluster-autopilot: add logging configuration (#1625)
Although one cannot disable Cloud Logging and Cloud Monitoring integration in GKE Autopilot clusters, one has some flexibility over which control plane components' logs should be ingested. This commit adds a new variable and a block to the cluster resource to facilitate that. * gke-cluster-autopilot: update logging configuration and add an example to module README
This commit is contained in:
parent
9fa30b5e9c
commit
80e85ad343
|
@ -35,7 +35,6 @@ module "cluster-1" {
|
||||||
# tftest modules=1 resources=1 inventory=basic.yaml
|
# tftest modules=1 resources=1 inventory=basic.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.
|
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.
|
||||||
|
@ -62,6 +61,31 @@ module "cluster-1" {
|
||||||
# tftest modules=1 resources=1 inventory=dns.yaml
|
# tftest modules=1 resources=1 inventory=dns.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Logging configuration
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
> **Note**
|
||||||
|
> System and workload logs collection is pre-configured for Autopilot clusters and cannot be disabled.
|
||||||
|
|
||||||
|
```hcl
|
||||||
|
module "cluster-1" {
|
||||||
|
source = "./fabric/modules/gke-cluster-autopilot"
|
||||||
|
project_id = var.project_id
|
||||||
|
name = "cluster-1"
|
||||||
|
location = "europe-west1"
|
||||||
|
vpc_config = {
|
||||||
|
network = var.vpc.self_link
|
||||||
|
subnetwork = var.subnet.self_link
|
||||||
|
}
|
||||||
|
logging_config = {
|
||||||
|
enable_api_server_logs = true
|
||||||
|
enable_scheduler_logs = true
|
||||||
|
enable_controller_manager_logs = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# tftest modules=1 resources=1 inventory=logging-config.yaml
|
||||||
|
```
|
||||||
|
|
||||||
### Backup for GKE
|
### Backup for GKE
|
||||||
|
|
||||||
|
@ -95,23 +119,24 @@ module "cluster-1" {
|
||||||
|
|
||||||
| name | description | type | required | default |
|
| name | description | type | required | default |
|
||||||
|---|---|:---:|:---:|:---:|
|
|---|---|:---:|:---:|:---:|
|
||||||
| [location](variables.tf#L112) | Autopilot cluster are always regional. | <code>string</code> | ✓ | |
|
| [location](variables.tf#L110) | Autopilot cluster are always regional. | <code>string</code> | ✓ | |
|
||||||
| [name](variables.tf#L147) | Cluster name. | <code>string</code> | ✓ | |
|
| [name](variables.tf#L155) | Cluster name. | <code>string</code> | ✓ | |
|
||||||
| [project_id](variables.tf#L173) | Cluster project id. | <code>string</code> | ✓ | |
|
| [project_id](variables.tf#L181) | Cluster project id. | <code>string</code> | ✓ | |
|
||||||
| [vpc_config](variables.tf#L196) | VPC-level configuration. | <code title="object({ network = string subnetwork = string master_ipv4_cidr_block = optional(string) secondary_range_blocks = optional(object({ pods = string services = string })) secondary_range_names = optional(object({ pods = string services = string }), { pods = "pods", services = "services" }) master_authorized_ranges = optional(map(string)) stack_type = optional(string) })">object({…})</code> | ✓ | |
|
| [vpc_config](variables.tf#L204) | VPC-level configuration. | <code title="object({ network = string subnetwork = string master_ipv4_cidr_block = optional(string) secondary_range_blocks = optional(object({ pods = string services = string })) secondary_range_names = optional(object({ pods = string services = string }), { pods = "pods", services = "services" }) 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) 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> |
|
| [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) 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> |
|
||||||
| [description](variables.tf#L37) | Cluster description. | <code>string</code> | | <code>null</code> |
|
| [description](variables.tf#L37) | Cluster description. | <code>string</code> | | <code>null</code> |
|
||||||
| [enable_addons](variables.tf#L43) | 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) 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) })">object({…})</code> | | <code title="{ horizontal_pod_autoscaling = true http_load_balancing = true }">{…}</code> |
|
| [enable_addons](variables.tf#L43) | 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) 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) })">object({…})</code> | | <code title="{ horizontal_pod_autoscaling = true http_load_balancing = true }">{…}</code> |
|
||||||
| [enable_features](variables.tf#L64) | Enable cluster-level features. Certain features allow configuration. | <code title="object({ 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) 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) })) tpu = optional(bool, false) upgrade_notifications = optional(object({ topic_id = optional(string) })) vertical_pod_autoscaling = optional(bool, false) })">object({…})</code> | | <code title="{ }">{…}</code> |
|
| [enable_features](variables.tf#L64) | Enable cluster-level features. Certain features allow configuration. | <code title="object({ 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) 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) })) 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#L100) | Enable issuing client certificate. | <code>bool</code> | | <code>false</code> |
|
| [issue_client_certificate](variables.tf#L98) | Enable issuing client certificate. | <code>bool</code> | | <code>false</code> |
|
||||||
| [labels](variables.tf#L106) | Cluster resource labels. | <code>map(string)</code> | | <code>null</code> |
|
| [labels](variables.tf#L104) | Cluster resource labels. | <code>map(string)</code> | | <code>null</code> |
|
||||||
| [maintenance_config](variables.tf#L118) | 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> |
|
| [logging_config](variables.tf#L115) | 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> |
|
||||||
| [min_master_version](variables.tf#L141) | Minimum version of the master, defaults to the version of the most recent official release. | <code>string</code> | | <code>null</code> |
|
| [maintenance_config](variables.tf#L126) | 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> |
|
||||||
| [node_locations](variables.tf#L152) | Zones in which the cluster's nodes are located. | <code>list(string)</code> | | <code>[]</code> |
|
| [min_master_version](variables.tf#L149) | Minimum version of the master, defaults to the version of the most recent official release. | <code>string</code> | | <code>null</code> |
|
||||||
| [private_cluster_config](variables.tf#L159) | 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> |
|
| [node_locations](variables.tf#L160) | Zones in which the cluster's nodes are located. | <code>list(string)</code> | | <code>[]</code> |
|
||||||
| [release_channel](variables.tf#L178) | Release channel for GKE upgrades. | <code>string</code> | | <code>null</code> |
|
| [private_cluster_config](variables.tf#L167) | 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> |
|
||||||
| [service_account](variables.tf#L184) | The Google Cloud Platform Service Account to be used by the node VMs created by GKE Autopilot. | <code>string</code> | | <code>null</code> |
|
| [release_channel](variables.tf#L186) | Release channel for GKE upgrades. | <code>string</code> | | <code>null</code> |
|
||||||
| [tags](variables.tf#L190) | Network tags applied to nodes. | <code>list(string)</code> | | <code>null</code> |
|
| [service_account](variables.tf#L192) | The Google Cloud Platform Service Account to be used by the node VMs created by GKE Autopilot. | <code>string</code> | | <code>null</code> |
|
||||||
|
| [tags](variables.tf#L198) | Network tags applied to nodes. | <code>list(string)</code> | | <code>null</code> |
|
||||||
|
|
||||||
## Outputs
|
## Outputs
|
||||||
|
|
||||||
|
@ -120,11 +145,11 @@ module "cluster-1" {
|
||||||
| [ca_certificate](outputs.tf#L17) | Public certificate of the cluster (base64-encoded). | ✓ |
|
| [ca_certificate](outputs.tf#L17) | Public certificate of the cluster (base64-encoded). | ✓ |
|
||||||
| [cluster](outputs.tf#L23) | Cluster resource. | ✓ |
|
| [cluster](outputs.tf#L23) | Cluster resource. | ✓ |
|
||||||
| [endpoint](outputs.tf#L29) | Cluster endpoint. | |
|
| [endpoint](outputs.tf#L29) | Cluster endpoint. | |
|
||||||
| [id](outputs.tf#L34) | FUlly qualified cluster id. | |
|
| [id](outputs.tf#L34) | Fully qualified cluster id. | |
|
||||||
| [location](outputs.tf#L39) | Cluster location. | |
|
| [location](outputs.tf#L39) | Cluster location. | |
|
||||||
| [master_version](outputs.tf#L44) | Master version. | |
|
| [master_version](outputs.tf#L44) | Master version. | |
|
||||||
| [name](outputs.tf#L49) | Cluster name. | |
|
| [name](outputs.tf#L49) | Cluster name. | |
|
||||||
| [notifications](outputs.tf#L54) | GKE PubSub notifications topic. | |
|
| [notifications](outputs.tf#L54) | GKE Pub/Sub notifications topic. | |
|
||||||
| [self_link](outputs.tf#L59) | Cluster self link. | ✓ |
|
| [self_link](outputs.tf#L59) | Cluster self link. | ✓ |
|
||||||
| [workload_identity_pool](outputs.tf#L65) | Workload identity pool. | |
|
| [workload_identity_pool](outputs.tf#L65) | Workload identity pool. | |
|
||||||
<!-- END TFDOC -->
|
<!-- END TFDOC -->
|
||||||
|
|
|
@ -121,6 +121,16 @@ resource "google_container_cluster" "cluster" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logging_config {
|
||||||
|
enable_components = toset(compact([
|
||||||
|
var.logging_config.enable_api_server_logs ? "APISERVER" : null,
|
||||||
|
var.logging_config.enable_controller_manager_logs ? "CONTROLLER_MANAGER" : null,
|
||||||
|
var.logging_config.enable_scheduler_logs ? "SCHEDULER" : null,
|
||||||
|
"SYSTEM_COMPONENTS",
|
||||||
|
"WORKLOADS",
|
||||||
|
]))
|
||||||
|
}
|
||||||
|
|
||||||
dynamic "gateway_api_config" {
|
dynamic "gateway_api_config" {
|
||||||
for_each = var.enable_features.gateway_api ? [""] : []
|
for_each = var.enable_features.gateway_api ? [""] : []
|
||||||
content {
|
content {
|
||||||
|
|
|
@ -32,7 +32,7 @@ output "endpoint" {
|
||||||
}
|
}
|
||||||
|
|
||||||
output "id" {
|
output "id" {
|
||||||
description = "FUlly qualified cluster id."
|
description = "Fully qualified cluster id."
|
||||||
value = google_container_cluster.cluster.id
|
value = google_container_cluster.cluster.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ output "name" {
|
||||||
}
|
}
|
||||||
|
|
||||||
output "notifications" {
|
output "notifications" {
|
||||||
description = "GKE PubSub notifications topic."
|
description = "GKE Pub/Sub notifications topic."
|
||||||
value = try(google_pubsub_topic.notifications[0].id, null)
|
value = try(google_pubsub_topic.notifications[0].id, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,9 +92,7 @@ variable "enable_features" {
|
||||||
}))
|
}))
|
||||||
vertical_pod_autoscaling = optional(bool, false)
|
vertical_pod_autoscaling = optional(bool, false)
|
||||||
})
|
})
|
||||||
default = {
|
default = {}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "issue_client_certificate" {
|
variable "issue_client_certificate" {
|
||||||
|
@ -114,6 +112,16 @@ variable "location" {
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "logging_config" {
|
||||||
|
description = "Logging configuration."
|
||||||
|
type = object({
|
||||||
|
enable_api_server_logs = optional(bool, false)
|
||||||
|
enable_scheduler_logs = optional(bool, false)
|
||||||
|
enable_controller_manager_logs = optional(bool, false)
|
||||||
|
})
|
||||||
|
default = {}
|
||||||
|
nullable = false
|
||||||
|
}
|
||||||
|
|
||||||
variable "maintenance_config" {
|
variable "maintenance_config" {
|
||||||
description = "Maintenance window configuration."
|
description = "Maintenance window configuration."
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
# Copyright 2023 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.
|
||||||
|
|
||||||
|
values:
|
||||||
|
module.cluster-1.google_container_cluster.cluster:
|
||||||
|
logging_config:
|
||||||
|
- enable_components:
|
||||||
|
- APISERVER
|
||||||
|
- CONTROLLER_MANAGER
|
||||||
|
- SCHEDULER
|
||||||
|
- SYSTEM_COMPONENTS
|
||||||
|
- WORKLOADS
|
||||||
|
|
||||||
|
counts:
|
||||||
|
google_container_cluster: 1
|
Loading…
Reference in New Issue