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

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

<p>So a <code>Service</code> example with specified <code>NodePort</code> would look like this:</p>

<pre><code>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
</code></pre>

<p>For more information on NodePort, see <a href="https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport" rel="noreferrer">this doc</a>. For configuring API Server Node Port range please see <a href="https://kubernetes.io/docs/admin/kube-apiserver/" rel="noreferrer">this</a>.</p>
