代码之家  ›  专栏  ›  技术社区  ›  Amin Shah Gilani

如何在禁用stackdriver的Terraform中配置自动修复和自动伸缩Google云Kubernetes集群

  •  1
  • Amin Shah Gilani  · 技术社区  · 7 年前

    我在看书 this

    问题是,随着时间的推移,我往往会忘记许多手动配置,所以我决定使用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监视:当前已启用, 必须是 残疾人 .
    • 必须是 启用
    • 自动节点修复:当前已禁用, 启用 .

    在文档中找不到 google_container_cluster

    1 回复  |  直到 7 年前
        1
  •  1
  •   Amin Shah Gilani    7 年前

    我找到了选择:

    这个 容器\节点\池 不幸的是,这些选项不适用于使用集群创建的默认池,因此我找到的一个解决方法是删除默认池,然后向集群添加一个完全配置的节点池。

    /* 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"]
      }
    }