如何使用 Terraform 禁用 stackdriver 配置自动修复和自动缩放 Google Cloud Kubernetes 集群
How do I configure an auto-repairing & auto-scaling Google Cloud Kubernetes cluster with Terraform with stackdriver disabled
我正在阅读 this 关于为个人项目设置负担得起的 Kubernetes 集群的博客,并设置了我的集群。
问题是,随着时间的推移,我往往会忘记很多手动配置,所以我决定使用 Terraform 将其存储在声明性代码中。
我已经成功构建并应用了以下配置:
provider "google" {
credentials = "${file("secret-account.json")}"
project = "worklark-218609"
zone = "us-central1-a"
}
# configuration
resource "google_container_cluster" "primary" {
name = "worklark-cluster"
initial_node_count = 3
node_config {
machine_type = "f1-micro"
disk_size_gb = 10 # Set the initial disk size
preemptible = true
}
addons_config {
kubernetes_dashboard {
disabled = false # Configure the Kubernetes dashboard
}
http_load_balancing {
disabled = false # Configure the Kubernetes dashboard
}
}
}
问题是,这两个集群的配置略有不同,这是我需要添加到配置中的内容:
- Stackdriver 日志记录:当前已启用,必须已禁用.
- Stackdriver Monitoring:当前已启用,必须已禁用。
- 自动节点升级:当前已禁用,必须启用.
- 自动节点修复:当前已禁用,必须启用.
我在 google_container_cluster
资源的文档中找不到配置选项。我该如何设置这些选项?
我找到了选项:
- Stackdriver 日志记录:在
google_container_cluster
下调用了 logging_service
- Stackdriver Monitoring:在
google_container_cluster
下调用了 monitoring_service
- 自动节点升级:在
container_node_pool
下调用 management.auto_upgrade
- 自动节点修复:在
container_node_pool
` 下调用了 management.auto_repair
container_node_pool
选项不适用于集群创建的默认池,不幸的是,所以我找到的解决方法是删除默认池,然后将完全配置的节点池添加到集群.
这是最终配置:
/* This configuration sets up a Kubernetes Cluster following
https://www.doxsey.net/blog/kubernetes--the-surprisingly-affordable-platform-for-personal-projects
Confession: there's a minor difference between the article and my config, the
former created a Cluster and configured the default node pool, however the options
for doing this via the API are limited, so my configuration creates an empty
default node pool for the cluster, and the creates and adds a fully configured
one on top
*/
provider "google" {
credentials = "${file("secret-account.json")}"
project = "worklark-218609"
zone = "us-central1-a"
}
# Node pool configuration
resource "google_container_node_pool" "primary_pool" {
name = "worklark-node-pool"
cluster = "${google_container_cluster.primary.name}"
node_count = 3
node_config {
machine_type = "f1-micro"
disk_size_gb = 10 # Set the initial disk size
preemptible = true
}
management {
auto_repair = true
auto_upgrade = true
}
}
# configuration
resource "google_container_cluster" "primary" {
name = "worklark-cluster"
logging_service = "none"
monitoring_service = "none"
addons_config {
kubernetes_dashboard {
disabled = false # Configure the Kubernetes dashboard
}
http_load_balancing {
disabled = false # Configure the Kubernetes dashboard
}
}
remove_default_node_pool = "true"
node_pool {
name = "default-pool"
}
}
resource "google_compute_firewall" "default" {
name = "http-https"
network = "${google_container_cluster.primary.network}"
description = "Enable HTTP and HTTPS access"
direction = "INGRESS"
allow {
protocol = "tcp"
ports = ["80", "443"]
}
}
我正在阅读 this 关于为个人项目设置负担得起的 Kubernetes 集群的博客,并设置了我的集群。
问题是,随着时间的推移,我往往会忘记很多手动配置,所以我决定使用 Terraform 将其存储在声明性代码中。
我已经成功构建并应用了以下配置:
provider "google" {
credentials = "${file("secret-account.json")}"
project = "worklark-218609"
zone = "us-central1-a"
}
# configuration
resource "google_container_cluster" "primary" {
name = "worklark-cluster"
initial_node_count = 3
node_config {
machine_type = "f1-micro"
disk_size_gb = 10 # Set the initial disk size
preemptible = true
}
addons_config {
kubernetes_dashboard {
disabled = false # Configure the Kubernetes dashboard
}
http_load_balancing {
disabled = false # Configure the Kubernetes dashboard
}
}
}
问题是,这两个集群的配置略有不同,这是我需要添加到配置中的内容:
- Stackdriver 日志记录:当前已启用,必须已禁用.
- Stackdriver Monitoring:当前已启用,必须已禁用。
- 自动节点升级:当前已禁用,必须启用.
- 自动节点修复:当前已禁用,必须启用.
我在 google_container_cluster
资源的文档中找不到配置选项。我该如何设置这些选项?
我找到了选项:
- Stackdriver 日志记录:在
google_container_cluster
下调用了 - Stackdriver Monitoring:在
google_container_cluster
下调用了 - 自动节点升级:在
container_node_pool
下调用 - 自动节点修复:在
container_node_pool
` 下调用了
logging_service
monitoring_service
management.auto_upgrade
management.auto_repair
container_node_pool
选项不适用于集群创建的默认池,不幸的是,所以我找到的解决方法是删除默认池,然后将完全配置的节点池添加到集群.
这是最终配置:
/* This configuration sets up a Kubernetes Cluster following
https://www.doxsey.net/blog/kubernetes--the-surprisingly-affordable-platform-for-personal-projects
Confession: there's a minor difference between the article and my config, the
former created a Cluster and configured the default node pool, however the options
for doing this via the API are limited, so my configuration creates an empty
default node pool for the cluster, and the creates and adds a fully configured
one on top
*/
provider "google" {
credentials = "${file("secret-account.json")}"
project = "worklark-218609"
zone = "us-central1-a"
}
# Node pool configuration
resource "google_container_node_pool" "primary_pool" {
name = "worklark-node-pool"
cluster = "${google_container_cluster.primary.name}"
node_count = 3
node_config {
machine_type = "f1-micro"
disk_size_gb = 10 # Set the initial disk size
preemptible = true
}
management {
auto_repair = true
auto_upgrade = true
}
}
# configuration
resource "google_container_cluster" "primary" {
name = "worklark-cluster"
logging_service = "none"
monitoring_service = "none"
addons_config {
kubernetes_dashboard {
disabled = false # Configure the Kubernetes dashboard
}
http_load_balancing {
disabled = false # Configure the Kubernetes dashboard
}
}
remove_default_node_pool = "true"
node_pool {
name = "default-pool"
}
}
resource "google_compute_firewall" "default" {
name = "http-https"
network = "${google_container_cluster.primary.network}"
description = "Enable HTTP and HTTPS access"
direction = "INGRESS"
allow {
protocol = "tcp"
ports = ["80", "443"]
}
}