Search code examples
cookiesdnsload-balancinggoogle-kubernetes-engine

Is there a way to get a domain for GKE loadbalancer instead of an ip?


Edit : I'm working on a project that deploys on GKE several projects a day in a 100% automatic way. Our project is developed in nodejs, here is a pseudo code:

projects = get_all_projects_today() // returns 15 projects for today (for example)

for project in projects
    deploy_to_GKE(project) //generate a deployment manifest for project and post it to GKE (using api call)
    public_ip = create_service_on_GKE(project, type=Loadbalancer) //generate a service manifest (type loadbalancer) for project, post it to GKE (using api call) and returns the public created ip address
    get_domain_from_ip(public_ip) //how to do this !

deployed projects must be accessible via domain names and not ip like this for example :

appx.mysite.com, or
mysite.com/appx

End Edit

Here is an example of service manifest that i use :

{
    "kind": "Service",
    "apiVersion": "v1",
    "metadata": {
        "name": "backend-__ID__"
    },
    "spec": {
        "selector": {
            "app": "backend-__ID__"
        },
        "type": "LoadBalancer",
        "ports": [
            {
                "name": "app1",
                "protocol": "TCP",
                "port": 8080,
                "targetPort": "8080"
            },
            {
                "name": "app2",
                "protocol": "TCP",
                "port": "3010",
                "targetPort": "3010"
            }
        ]
    }
}

which gives me this result on google cloud : enter image description here

The only way to access the project from outside is to use the ip address (Endpoint), but this blocks the use of cookies (we can not set cookies on ip, we should use a domain name).

So is there a way to get, automatically, from GKE named domains for Endpoints to access the projet from outside ?

i tried using reverse DNS lookup to get a domain name for the external ip but that did not work :(

Thank you


Solution

  • I found it!

    using reverse dns lookup, i found that google provide a domain like this : [LOADBALANCER_IP].bc.googleusercontent.com.

    example of reverse dns lookup site : https://mxtoolbox.com/ReverseLookup.aspx