为节点池指定“点” k8s标签?

克里斯·普鲁登(Kris Pruden)

Kubernetes在元数据标签键中支持点(例如app.role),实际上这似乎是一个常见约定。

terraform配置语言(0.12)在参数名称中不支持点,因此无法指定此形式的标签。例如,在google_container_node_pool配置中,我要指定以下内容:

resource "google_container_node_pool" "my-node-pool" {
  ...
  labels = {
    app.role = web
  }
}

有解决方法吗?

注意:斜线(/)在k8s标签中也很常见。

更新:万一有人偶然发现同一问题,我想出了问题的根源。labels通过省略误将参数指定为一个块=所以看起来像这样:

labels {
  "app.role" = "web"
}

这产生了以下错误,向我指出了错误的方向:

Error: Invalid argument name

  on main.tf line 45, in resource "google_container_node_pool" "primary_preemptible_nodes":
  45:       "app.role" = "web"

Argument names must not be quoted.

我注意到并修复了丢失的内容,=但并未将映射键的语法与参数名称的语法合并在一起。

罗伯特·贝利

我验证了@ydaetskcoR提出的将标签用引号引起来的建议。以下是定义我创建的节点池的片段(使用Terraform v0.11.13):

resource "google_container_node_pool" "node_pool" {
  cluster = "${google_container_cluster.cluster.name}"
  zone = "${var.cluster_location}"

  initial_node_count = "${var.node_count}"
  autoscaling {
    min_node_count = 1
    max_node_count = 5
  }
  management {
    auto_repair = true
    auto_upgrade = true
  }
  node_config {
    machine_type = "${var.machine_type}"

    oauth_scopes = [
      "https://www.googleapis.com/auth/logging.write",
      "https://www.googleapis.com/auth/monitoring",
      "https://www.googleapis.com/auth/devstorage.read_only",
    ]

    metadata {
      disable-legacy-endpoints = "true"
    }
    labels = {
      "app.role" = "web"
    }
  }
}

编辑:我也验证了与terraform 0.12.3相同。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章