<p>After deploying nginx (or any application for that matter) , I try to expose it using the following config file: </p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 80
  selector:
    app: nginx
</code></pre>

<p>The result:</p>

<pre><code>C:\install\kube&gt;kubectl get service -l app=nginx
NAME      TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
nginx     LoadBalancer   10.108.193.215   &lt;pending&gt;     80:31035/TCP   21h
</code></pre>

<p>Note the port number 31035 is randomly assigned. Is it possible to define a specific port? </p>

<p>Versions:</p>

<pre><code>C:\install\kube&gt;minikube version
minikube version: v0.24.1

C:\install\kube&gt;kubectl version
Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.0", GitCommit:"6e937839ac04a38cac63e6a7a306c5d035fe7b0a", GitTreeState:"clean", BuildDate:"2017-09-28T22:57:57Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.0", GitCommit:"0b9efaeb34a2fc51ff8e4d34ad9bc6375459c4a4", GitTreeState:"clean", BuildDate:"2017-11-29T22:43:34Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"linux/amd64"}
</code></pre>

<p><code>LoadBalancer</code> service uses <code>NodePort</code> internally. Yes, it possible to specify a <code>NodePort</code> for a service. There are two ways to do it:</p>

<ol>
<li>Using <code>nodePort: 31036</code> in the YAML spec file for the service.</li>
<li>Run <code>kubectl edit &lt;service name&gt;</code>, edit the <code>nodePort</code> field under <code>ports</code> and save it.</li>
</ol>

<p>Keep in mind that <code>NodePort</code> must be set to a number in the flag-configured range range <code>30000-32767</code>. Otherwise, kubernetes throws an error. This <code>NodePort</code> range can be changed using the flag <code>--service-node-port-range</code> passed to <code>kube-apiserver</code> per <a href="https://kubernetes.io/docs/reference/generated/kube-apiserver/" rel="noreferrer">https://kubernetes.io/docs/reference/generated/kube-apiserver/</a>:</p>

<pre><code>  --service-node-port-range portRange      A port range to reserve for services
                                           with NodePort visibility. 
                                           Example: '30000-32767'. Inclusive at both ends
                                           of the range. (default 30000-32767)
</code></pre>
