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

lymgl2op  于 5个月前  发布在  Nginx
关注(0)|答案(1)|浏览(47)

我有一个terraform配置,它创建了digitalocean_loadbalancer,然后用nginx-ingress-controller chart创建了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的名称。
问题是如何防止这种重命名?

0md85ypi

0md85ypi1#

解决方案是提供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,
  ]
}

字符串

相关问题