How to define a service label for a kubernetes service running on GKE
Asked Answered
R

1

10

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

Reborn answered 6/9, 2020 at 18:54 Comment(0)
S
0

Actually Kubernetes documentation doesn't provide an exhaustive list of all possible annotations that can be applied to a Service object.

This is because annotations are designed to be user-defined and can be used for various purposes beyond those defined by Kubernetes itself.

But here is the list of annotations that are offered for LB Service by GKE in GCP - https://cloud.google.com/kubernetes-engine/docs/concepts/service-load-balancer-parameters

And these are some labels and annotations that are supported by Kubernetes in General - https://kubernetes.io/docs/reference/labels-annotations-taints/

You can choose from these annotations or create your custom annotation and use that as well.

Read more here: https://kubernetes.io/docs/reference/kubectl/generated/kubectl_annotate/ https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/

Sap answered 25/4, 2024 at 13:6 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.