Is it possible to define nodePort in "kubectl expose" command?

5/11/2016

I have a ReplicationController and I expose it as a Service by:

kubectl expose rc my-rc --port=9000 --target-port=8080 --type=NodePort --name=my-service

Then, Kubernetes gives me a random public port for the exposed Service, 31289 for instance. If you create the Service using a yaml file, you can define that port in spec.ports[*].nodePort field. In this case, I have to create the Service via expose command instead of declaratively using a yaml.

Is there a way to define the nodePort in kubectl expose command?

-- Héctor
kubernetes

1 Answer

5/11/2016

There isn't a way to specify a NodePort when creating a service of type NodePort. Feel free to file a feature request to add this feature (or send a pull request).

-- Robert Bailey
Source: StackOverflow