You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Specify NodePort in "kubectl expose" command #25478
If you define a Service declaratively, in a yaml file, you use the field spec.ports[*].nodePort to achieve it. But, if it is not possible to create a declarative Service, there is not a way to specify the nodePort.
I'd much prefer that create service be the place where we accumulate
flag-per-field sorts of things. Expose is supposed to be simple. That
said, this flag is not egregious to me, since there's ample precedent
I didn't know of the existence of the feature create service. So I'm agree with place it in kubectl create service.
I'd much prefer that create service be the place where we accumulate
flag-per-field sorts of things. Expose is supposed to be simple. That
said, this flag is not egregious to me, since there's ample precedent
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
Prevent issues from auto-closing with an /lifecycle frozen comment.
If this issue is safe to close now please do so with /close.
Send feedback to sig-testing, kubernetes/test-infra and/or @fejta.
/lifecycle stale
Expose already offers 2 ports, one of which (port) is superfluous for nodeports since we only care about the nodePort and the targetPort. Adding one more port would really help everyone confronted with the thousands of tutorials using kubectl expose which don't mention that you can't specify a nodeport.
kubectl create service nodeport myservice --node-port=31000 --tcp=3050:80
This doesn't seem to be well documented. How do you specify which pods you are selecting?
I don't think you do - that's another issue that's documented - #46191, as @mmumshad pointed out, this will not use the pods labels as selectors, instead it will assume selectors as app=myservice so generate the file and modify the selectors before creating the service
I'd much prefer that create service be the place where we accumulate flag-per-field sorts of things. Expose is supposed to be simple. That said, this flag is not egregious to me, since there's ample precedent
We've been discussing recently that expose has too many options. If we
have create service, do we need this in expose?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub #25478 (comment)
expose already simple and very nice coz I do not need specify selectors it does that for me. But what I do not like is that coz I can't specify nodeport I need to do more jumps review labels and add selector. I wish --node-port was there. Do not use if you don't need it
kubectl create service has weird semantics. As far as I can tell it doesn't even take a selector, which makes it awkward to use.
kubectl expose has weird semantics, too (only one port flag) but is closer.
Choosing a specific nodeport is very uncommon, so there's not much demand for it.
All of these CLI modes are sort of "toys". Good for kicking the tires but probably not what you want in prod. kubectl {apply | create | replace} support everything.
That said, I would not object to adding this to expose (with the current weird semantics), or to fixing expose to be less weird, or to fixing create service to take a selector.
Activity
adohe-zz commentedon May 12, 2016
@bgrant0607 wdyt?
smarterclayton commentedon May 12, 2016
We've been discussing recently that expose has too many options. If we have create service, do we need this in expose?
thockin commentedon May 12, 2016
I'd much prefer that
create servicebe the place where we accumulateflag-per-field sorts of things. Expose is supposed to be simple. That
said, this flag is not egregious to me, since there's ample precedent
On Wed, May 11, 2016 at 7:17 PM, Clayton Coleman notifications@github.com
wrote:
hvalls commentedon May 12, 2016
I didn't know of the existence of the feature
create service. So I'm agree with place it inkubectl create service.bgrant0607 commentedon May 12, 2016
I'd also like to add
--editto expose (and to run, create), which would allow someone to add arbitrary fields that didn't have flags. #180640xmichalis commentedon Jun 20, 2017
/sig cli
fejta-bot commentedon Dec 29, 2017
Issues go stale after 90d of inactivity.
Mark the issue as fresh with
/remove-lifecycle stale.Stale issues rot after an additional 30d of inactivity and eventually close.
Prevent issues from auto-closing with an
/lifecycle frozencomment.If this issue is safe to close now please do so with
/close.Send feedback to sig-testing, kubernetes/test-infra and/or
@fejta./lifecycle stale
2 remaining items
charpty commentedon Apr 20, 2018
@hvalls hi, how did you solve this problem?
hvalls commentedon Apr 20, 2018
@charpty Actually, I didn't. I just used the declarative way, automating yml generation.
mkasep commentedon Jul 20, 2018
@hvalls So besides te declarative way, there is no other way to describe a nodeport on a single command?
odedpriva commentedon Sep 4, 2018
you can do something like that
you can also add
--dry-run -o yamlto check validate the service object that will be created.Sher-Chowdhury commentedon May 30, 2019
Here's how I managed to do it:
cawoodm commentedon Feb 11, 2022
This doesn't seem to be well documented. How do you specify which pods you are selecting?
cawoodm commentedon Feb 11, 2022
Expose already offers 2 ports, one of which (port) is superfluous for nodeports since we only care about the nodePort and the targetPort. Adding one more port would really help everyone confronted with the thousands of tutorials using
kubectl exposewhich don't mention that you can't specify a nodeport.ultraasi-atanas commentedon Feb 22, 2022
I don't think you do - that's another issue that's documented - #46191, as @mmumshad pointed out, this will not use the pods labels as selectors, instead it will assume selectors as app=myservice so generate the file and modify the selectors before creating the service

alkdese commentedon Apr 7, 2022
expose already simple and very nice coz I do not need specify selectors it does that for me. But what I do not like is that coz I can't specify nodeport I need to do more jumps review labels and add selector. I wish
--node-portwas there. Do not use if you don't need itcarlosjmarin commentedon Oct 4, 2023
Seems cumbersome to have to create a service for this imparatively, has there been a plan to add nodeport as an option to expose?
esgn commentedon Oct 10, 2023
Would be helpful to have such and option directly in expose or
k create servicethockin commentedon Oct 10, 2023
kubectl create servicehas weird semantics. As far as I can tell it doesn't even take a selector, which makes it awkward to use.kubectl exposehas weird semantics, too (only one port flag) but is closer.Choosing a specific nodeport is very uncommon, so there's not much demand for it.
All of these CLI modes are sort of "toys". Good for kicking the tires but probably not what you want in prod.
kubectl {apply | create | replace}support everything.That said, I would not object to adding this to expose (with the current weird semantics), or to fixing expose to be less weird, or to fixing
create serviceto take a selector.KEPs welcome.