首页 > 解决方案 > 有没有办法为 GKE 负载均衡器获取域而不是 ip?

问题描述

编辑:我正在开发一个项目,该项目每天以 100% 自动的方式在 GKE 上部署多个项目。我们的项目是用nodejs开发的,下面是一段伪代码:

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 !

部署的项目必须可以通过域名访问,而不是像这样的 ip,例如:

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

结束编辑

这是我使用的服务清单示例:

{
    "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"
            }
        ]
    }
}

这在谷歌云上给了我这个结果: 在此处输入图像描述

从外部访问项目的唯一方法是使用 ip 地址(Endpoint),但这会阻止使用 cookie(我们不能在 ip 上设置 cookie,我们应该使用域名)。

那么有没有办法从 GKE 命名域中自动获取 Endpoints 以从外部访问项目?

我尝试使用反向 DNS 查找来获取外部 ip 的域名,但这不起作用:(

谢谢

标签: cookiesdnsload-balancinggoogle-kubernetes-engine

解决方案


我找到了!

使用反向 dns 查找,我发现 google 提供了这样的域:[LOADBALANCER_IP].bc.googleusercontent.com。

反向 dns 查找站点示例:https ://mxtoolbox.com/ReverseLookup.aspx


推荐阅读