Как настроить автоматическое восстановление и автоматическое масштабирование кластера Google Cloud Kubernetes с Terraform с отключенной драйвером стека - PullRequest
0 голосов
/ 08 октября 2018

Я читал этот блог о настройке доступного кластера 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: в настоящее время включено, должно быть Отключено .
  • Автоматическое обновление узла: в настоящее время отключено, должно быть Включено .
  • Автоматическое восстановление узла: в настоящее время отключено, должно быть Включено .

Я не могу найтиВарианты конфигурации в документации для google_container_cluster ресурс.Что мне сделать, чтобы установить эти параметры?

1 Ответ

0 голосов
/ 08 октября 2018

Я нашел варианты:

  • Регистрация в стеке драйвера: вызывается logging_service в google_container_cluster
  • Мониторинг в стеке: вызывается monitoring_service в google_container_cluster
  • Автоматическое обновление узла: вызывается management.auto_upgrade в container_node_pool
  • Автоматическое восстановление узла: вызывается management.auto_repair в container_node_pool `

Параметры 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"]
  }
}
...