Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes NodePort Custom Port

Is there way to specify a custom NodePort port in a kubernetes service YAML definition? I need to be able to define the port explicitly in my configuration file.

like image 239
Artem Dolobanko Avatar asked May 12 '17 10:05

Artem Dolobanko


People also ask

How do I specify node ports?

Configuring the ServiceLog in to the master node. Edit the service definition to specify spec. type:NodePort and optionally specify a port in the 30000-32767 range. Note that the external IP is listed as <none> and the node ports are listed.

How do you define NodePort in Kubernetes?

You can set the type NodePort in your Service Deployment. Note that there is a Node Port Range configured for your API server with the option --service-node-port-range (by default 30000-32767 ).

What is the difference between a port and a NodePort in Kubernetes?

Port : port redirects the traffic to the container from the service. NodePort : is the port that enables the service to access the externally.

What is port NodePort?

Port exposes the Kubernetes service on the specified port within the cluster. Other pods within the cluster can communicate with this server on the specified port. TargetPort is the port on which the service will send requests to, that your pod will be listening on.


1 Answers

You can set the type NodePort in your Service Deployment. Note that there is a Node Port Range configured for your API server with the option --service-node-port-range (by default 30000-32767). You can also specify a port in that range specifically by setting the nodePort attribute under the Port object, or the system will chose a port in that range for you.

So a Service example with specified NodePort would look like this:

apiVersion: v1 kind: Service metadata:   name: nginx   labels:     name: nginx spec:   type: NodePort   ports:     - port: 80       nodePort: 30080       name: http     - port: 443       nodePort: 30443       name: https   selector:     name: nginx 

For more information on NodePort, see this doc. For configuring API Server Node Port range please see this.

like image 127
Oswin Noetzelmann Avatar answered Oct 10 '22 06:10

Oswin Noetzelmann