<p>I want to run several services on different ports in a kubernetes cluster and I would like to know how to check which ports are available and wouldn't cause any conflicts with my services. I would also like to know the names of the services on each port so I can understand my configuration better.</p>

<p>There was similar question related to verify which <code>NodePorts</code> are already in use. You can find it <a href="https://stackoverflow.com/a/39260160/11148139">here</a>.</p>

<p>This command will display all <code>ports</code> from all <code>namespaces</code> which are <code>NodePort</code> type and are already in use.</p>

<pre><code>$ kubectl get svc --all-namespaces -o go-template='{{range .items}}{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{"\n"}}{{end}}{{end}}{{end}}'
30007
30107
30207
30307
30407
30676
</code></pre>

<p>However, pleas keep in mind that Kubernetes will not allow you to use second time this same <code>NodePort</code>.</p>

<pre><code>$ cat&lt;&lt;eof|kubectl apply -f -
&gt; apiVersion: v1
&gt; kind: Service
&gt; metadata:
&gt;   name: my-service-test
&gt; spec:
&gt;   type: NodePort
&gt;   selector:
&gt;     app: MyApp
&gt;   ports:
&gt;     - port: 80
&gt;       targetPort: 80
&gt;       nodePort: 30307
&gt; eof
The Service "my-service-test" is invalid: spec.ports[0].nodePort: Invalid value: 30307: provided port is already allocated
</code></pre>

<p>In addition, there are some very specific scenarios, when you would like to use ports outside default range mentioned in <a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport" rel="noreferrer">K8s docs</a>. 
There is a workaround, if you will add a special flag <code>--service-node-port-range</code> with requested range, admission controller allow you to create <code>NodePort</code> with Ports <code>80</code> and <code>443</code>. For detailed information how to do it, check <a href="https://stackoverflow.com/a/58732307/11148139">this answer</a>.</p>
