【问题标题】:Specify "dotted" k8s labels for node pools?为节点池指定“点状”k8s 标签?
【发布时间】:2019-11-08 16:41:55
【问题描述】:

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.

我注意到并修复了丢失的=,但我没有将映射键与参数名称的语法不同的放在一起。

【问题讨论】:

  • 如果您计划这样做会怎样?您可以编辑问题中的任何适用错误吗?我认为您应该能够将app.role 用引号括起来,例如"app.role" = "web",这样应该可以正常工作。

标签: terraform google-kubernetes-engine


【解决方案1】:

我验证了@ydaetskcoR 的建议,即用引号将标签括起来是可行的。这是定义我创建的节点池的 sn-p(使用 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。

【讨论】:

  • 这太奇怪了。我可以发誓我试过这个但没有用。它现在可以工作了。谢谢!
猜你喜欢
  • 2021-06-23
  • 1970-01-01
  • 2020-07-25
  • 2021-01-16
  • 2021-11-21
  • 1970-01-01
  • 2019-04-25
  • 2020-05-19
  • 2022-06-13
相关资源
最近更新 更多