8

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
  • 635
  • 4
  • 16

1 Answers1

-4

In Kubernetes, there is no built-in annotation specifically for adding a DNS name to a LoadBalancer service. LoadBalancer services typically expose an external IP address that can be used to access the service. However, you can achieve your goal of using a DNS name instead of an IP address by setting up a DNS record (such as a CNAME) that points to the IP address of your LoadBalancer service.

Here's what you can do:

Obtain External IP: After your LoadBalancer service is created, it will be assigned an external IP address. You can get this IP address from the service's status using kubectl get svc ilb-service -n -o jsonpath='{.status.loadBalancer.ingress[0].ip}'.

Create DNS Record: Once you have the external IP, you can create a DNS record (CNAME) that points to this IP. This can be done in your DNS provider's management console. For example, if you're using Google Cloud DNS, you can create a CNAME record that maps your desired DNS name (e.g., "my-dns-name.example.com") to the external IP of your LoadBalancer service.

Use DNS Name: Once the DNS record is set up and propagated, you can use your chosen DNS name (e.g., "my-dns-name.example.com") to access your service instead of the IP address.

Regarding your original question about annotations, annotations in Kubernetes are key-value pairs that can provide additional metadata or instructions to various Kubernetes components, controllers, or plugins. The annotations you've used in your configuration are for configuring the behavior of the internal load balancer in Google Kubernetes Engine (GKE), and they are specific to GKE's implementation.

For a list of annotations supported by GKE's internal load balancer, you should refer to the official documentation or resources provided by Google Cloud. You can start by looking at the GKE documentation related to internal load balancing

Sujay_ks
  • 47
  • 7