helm_release nginx-ingress-controller 重命名 digitalocean_loadbalancer 名称

问题描述 投票:0回答:1

我有 terraform 配置,它创建 digitalocean_loadbalancer,然后使用 nginx-ingress-controller 图表创建 helm_release。

第一部分:

resource "digitalocean_loadbalancer" "do_lb" {
  name   = "do-lb"
  region = "ams3"
  size = "lb-small"
  algorithm = "round_robin"
  redirect_http_to_https = true

  forwarding_rule {
    entry_port     = 80
    entry_protocol = "http"

    target_port     = 80
    target_protocol = "http"
  }

  forwarding_rule {
    entry_port     = 443
    entry_protocol = "https"

    target_port     = 443
    target_protocol = "https"
    tls_passthrough = true
  }
}

它成功创建了名为“do-lb”的负载均衡器。

然后,应用 helm_release 后

resource "helm_release" "nginx_ingress_chart" {
  name       = "nginx-ingress-controller"
  namespace  = "default"
  repository = "https://charts.bitnami.com/bitnami"
  chart      = "nginx-ingress-controller"
  set {
    name  = "service.type"
    value = "LoadBalancer"
  }
  set {
    name  = "service.annotations.kubernetes\\.digitalocean\\.com/load-balancer-id"
    value = digitalocean_loadbalancer.do_lb.id
  }
  depends_on = [
    digitalocean_loadbalancer.do_lb,
  ]
}

它会自动将负载均衡器名称重命名为类似 md5 的名称。

问题是如何防止这种重命名?

nginx terraform kubernetes-helm load-balancing digital-ocean
1个回答
1
投票

解决方案是提供

service.beta.kubernetes.io/do-loadbalancer-name
注释

指定负载均衡器的自定义名称。现有负载均衡器将被重命名。名称必须遵守以下规则:

  • 不得超过255个字符
  • 它必须以字母数字字符开头
  • 它必须由字母数字字符或“.”组成(点)或“-”(破折号)字符
  • 除了最后一个字符不能是“-”(破折号)

如果未指定自定义名称,则选择由服务 UID 附加的字符 a 组成的默认名称。

您的案例:

resource "helm_release" "nginx_ingress_chart" {
  name       = "nginx-ingress-controller"
  namespace  = "default"
  repository = "https://charts.bitnami.com/bitnami"
  chart      = "nginx-ingress-controller"
  set {
    name  = "service.type"
    value = "LoadBalancer"
  }
  set {
    name  = "service.annotations.kubernetes\\.digitalocean\\.com/load-balancer-id"
    value = digitalocean_loadbalancer.do_lb.id
  }
  set {
    name  = "service.annotations.kubernetes\\.digitalocean\\.com/load-balancer-name"
    value = "do-lb"
  }
  depends_on = [
    digitalocean_loadbalancer.do_lb,
  ]
}

© www.soinside.com 2019 - 2024. All rights reserved.