0

We've got a dev environment setup in which a part of our services are inside Kubernetes (using kind) and a part of it is not. Inside the Kubernetes pod, a request is made to a certain host (localdev.companyName.com), we own this domain and return 127.0.0.1 everytime a request is made (this was to avoid having to resolve host locally in dev computers).

While this is fine when we run our docker instances on the host ( app instance is listening on 127.0.0.1 on port 80, so the frontends can easily communicate ), this is not okay when we want to make a network request from inside the Kubernetes pod to that app instance.

This is due to the fact that 127.0.0.1 inside the kubernetes cluster is not associated to any docker instance, and we need the docker instance from the host. So my question is how can I configure my pod to resolve localdev.companyName.com to the loopback address of the host instead of Kubernetes node one ?

I tried ExternalName with the following configurations to no avail ( it's a Terraform Code )

resource "kubernetes_service" "my-service-external-name" {
  metadata {
    name      = "my-service-external-name-external-name"
    namespace = namespace name
enter code here
    annotations = {
      "app.kubernetes.io/name" = "localdev.companyName.com"
    }
  }

  spec {
    type          = "ExternalName"
    external_name = "host.docker.internal"
  }

}

I've also researched about headless services. I've read this question too.

Pouya Ataei
  • 1,959
  • 2
  • 19
  • 30
  • Let us know if you are able to resolve "localdev.companyName.com" from inside the pod either using curl, nslookup or any other utility. Also mention the port number and type in external service definition. kindly share the error you are getting – Nataraj Medayhal Sep 28 '22 at 03:45
  • @NatarajMedayhal maybe the question is not clear, but I've stated that we own the domain and it returns 127.0..0.1, which is fine on host machine because it's associated to a docker instance,,, the error we got is connection refused, because nothing is listening on port 80 on 127.0.0.1 inside the pod network... that is only available on the host machine – Pouya Ataei Sep 28 '22 at 22:40

1 Answers1

-1

You need to connect them with services as per K8s documentation. Here is the link

jmvcollaborator
  • 2,141
  • 1
  • 6
  • 17