Is there a way to add arbitrary records to kube-dns?

后端 未结 5 1364
遥遥无期
遥遥无期 2020-12-28 21:27

I will use a very specific way to explain my problem, but I think this is better to be specific than explain in an abstract way...

Say, there is a MongoDB replica se

5条回答
  •  伪装坚强ぢ
    2020-12-28 22:23

    For the record, an alternate solution for those not checking the referenced github issue.

    You can define an "external" Service in Kubernetes, by not specifying any selector or ClusterIP. You have to also define a corresponding Endpoint pointing to your external IP.

    From the Kubernetes documentation:

    {
        "kind": "Service",
        "apiVersion": "v1",
        "metadata": {
            "name": "my-service"
        },
        "spec": {
            "ports": [
                {
                    "protocol": "TCP",
                    "port": 80,
                    "targetPort": 9376
                }
            ]
        }
    }
    {
        "kind": "Endpoints",
        "apiVersion": "v1",
        "metadata": {
            "name": "my-service"
        },
        "subsets": [
            {
                "addresses": [
                    { "ip": "1.2.3.4" }
                ],
                "ports": [
                    { "port": 9376 }
                ]
            }
        ]
    }
    

    With this, you can point your app inside the containers to my-service:9376 and the traffic should be forwarded to 1.2.3.4:9376

    Limitations:

    • The DNS name used needs to be only letters, numbers or dashes. You can't use multi-level names (something.like.this). This means you probably have to modify your app to point just to your-service, and not yourservice.domain.tld.
    • You can only point to a specific IP, not a DNS name. For that, you can define a kind of a DNS alias with an ExternalName type Service.

提交回复
热议问题