Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headless service targetPort not resolving containerPort name #20488

Closed
ewolinetz opened this issue Feb 2, 2016 · 4 comments
Closed

Headless service targetPort not resolving containerPort name #20488

ewolinetz opened this issue Feb 2, 2016 · 4 comments

Comments

@ewolinetz
Copy link

It seems that my headless service definition does not correctly resolve the containerPort name.
I receive this error when I oc process <template> | oc create -f -

Error from server: Service "logging-es-cluster" is invalid: spec.ports[0].port: invalid value '9300', Details: must be equal to targetPort when clusterIP = None

My service is defined as:

  -
    apiVersion: "v1"
    kind: "Service"
    metadata:
      name: "logging-es-cluster"
    spec:
      portalIP: "None"
      ports:
      -
        port: 9300
        targetPort: cluster
      selector:
        provider: "openshift"
        component: "es"

And my container is defined with:

              ports:
              -
                containerPort: 9200
                name: "restapi"
              -
                containerPort: 9300
                name: "cluster"

This was run using kubernetes v1.2.0-alpha.4-851-g4a65fa1

@thockin
Copy link
Member

thockin commented Feb 2, 2016

The concept of "port" being different from "targetPort" doesn't apply to headless services. The port translation is happening as part of the layer-4 load-balancing, but headless really means "no load-balancer".

Think of it from a traffic flow point of view. With a plain service, I can map port X to port Y. A client access the VIP on port X. The LB logic rewrites that to backend:Y. With a headless service, a client accesses backend:Y directly.

That is why we require X and Y to be the same in headless services.

@thockin thockin closed this as completed Feb 2, 2016
@sosiouxme
Copy link

@thockin I'm probably missing something here, but it looks to me like X and Y are both 9300 here. Does it make any difference that it's being referred to by name?

@thockin
Copy link
Member

thockin commented Feb 2, 2016

The resolution of name to number happens much later than API validation (in
a controller). Besides that the set of pods behind a Service can change
dynamically, so it is impossible to ensure that the mapping stays identical
over time. targetPort literally has no meaning to headless Services, so
we simply demand that it be the same as port (or empty, in which case the
defaulting logic sets it to port).

On Tue, Feb 2, 2016 at 8:58 AM, Luke Meyer notifications@github.com wrote:

@thockin https://github.com/thockin I'm probably missing something
here, but it looks to me like X and Y are both 9300 here. Does it make any
difference that it's being referred to by name?


Reply to this email directly or view it on GitHub
#20488 (comment)
.

@sosiouxme
Copy link

Thanks for clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants