How to define a service label for a kubernetes service running on GKE

9/6/2020

I am creating a kubernetes cluster to host a service and added an internal load balancer to route traffic between my VM Instances and the kubernetes cluster. I want to add a service label to the load balancer FrontEnd so that I can use a dns name instead of an IP address. But I don't know the annotation to use to add a service label? My terraform config looks like below

Any idea where I can find the list of annotations supported

resource "kubernetes_manifest" "service_ilb" {
  provider = kubernetes-alpha

  manifest = {
    "apiVersion" = "v1"
    "kind"       = "Service"

    "metadata" = {
      "name"      = "ilb-service"
      "namespace" = var.namespace

      "annotations" = {
        "cloud.google.com/load-balancer-type"                          = "Internal"
        "networking.gke.io/internal-load-balancer-allow-global-access" = "true"
        "networking.gke.io/internal-load-balancer-subnet"              = var.subnetwork
        # Does not work
        "networking.gke.io/internal-load-balancer-service-label"       = "my-dns-name" 
      }
      "labels" = {
        "app.kubernetes.io/component" = "rabbitmq-server"
        "app.kubernetes.io/name"      = "rabbitmq-instance"
      }
    }

    "spec" = {
      "type" = "LoadBalancer"

      "ports" = [
        {
          "name"       = "amqp-tls"
          "port"       = 5671
          "targetPort" = 5671
          "protocol"   = "TCP"
          "nodePort"   = 31212
        },
        {
          "name"       = "http"
          "port"       = 15672
          "targetPort" = 15672
          "protocol"   = "TCP"
          "nodePort"   = 32511
        },
      ]

      "selector" = {
        "app.kubernetes.io/component" = "rabbitmq-server"
        "app.kubernetes.io/name"      = "rabbitmq-instance"
      }
    }
  }
  /*
  wait_for = {
    fields = {
      # Check an ingress has an IP
      "status.loadBalancer.ingress.0.ip" = "^(\\d+(\\.|$)){4}"
    }
  }
  */
}

Thanks in advance

-- RandomQuests
google-kubernetes-engine
kubernetes
terraform
terraform-provider-kubernetes

0 Answers