consul-k8s icon indicating copy to clipboard operation
consul-k8s copied to clipboard

Impossible to get all NodePort of a service

Open VictorBac opened this issue 4 years ago • 1 comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Overview of the Issue

Hi team,

I am trying to expose my services in Kubernetes with multiple NodePort in Consul using consul-sync.

When I query my service this is all I get:

...
        "ServiceAddress": "x.x.x.x.",
        "ServiceMeta": {
            "external-k8s-ns": "my-ns",
            "external-source": "kubernetes",
            "port-port80": "80",   # Local port of the pod
            "port-port81": "81"    # Local port of the pod
        },
        "ServicePort": 28252,     # NodePort of the first port (80)
...

There is no way to get all the NodePorts.

However when I read the doc: https://www.consul.io/docs/k8s/service-sync#service-ports

"all ports will be registered in the service instance metadata with the key "port-X" where X is the name of the port and the value is the externally accessible port." => I don't have the externally accessible port, but the pod's port (which is useless if I want to access my service from outside the cluster)

Is there a way to get all the nodeports of my Service ? Not just the first one ?

Expected behavior

I expected the get the nodePorts in the ServiceMeta data. Something like this:

        "ServiceMeta": {
            "external-k8s-ns": "my-ns",
            "external-source": "kubernetes",
            "port-port80": "28252",   #  NodePort
            "port-port81": "28253"    #  NodePort
        },

Environment details

$ consul-k8s  --version
v0.26.0

Thank you!

VictorBac avatar Aug 31 '21 14:08 VictorBac

Hey @VictorBac sorry you ran into that! Since Consul services currently support only one port per service instance that is registered, only the first NodePort is synced as part of the service registration to Consul (see: https://www.consul.io/docs/k8s/service-sync#nodeport). I'll tag this as a feature request.

There are related requests for Consul to support multiple ports, so this would need to be added after support for multiple ports is added.

ndhanushkodi avatar Sep 03 '21 04:09 ndhanushkodi