<p>When a Kubernetes attempts to allocate a random port in NodePort range (30000-32767) and it happens to be in use by another process running on the host, will Kubernetes simply use another random port in NodePort range? Or will it throw an error?</p>
<p>I know that host processes should not be configured to use ports in NodePort range but this question is not about best practices. I just want to know how Kubernetes will respond in such a situation.</p>

Dojo
<p>This is the main reason why Kubernetes choose port range 30000-32767 as its default node port range and this range avoids conflicts with any process runs on the common port on the host machine (for example, 22, 80, 443 etc).</p>
<p>Please follow this <a href="https://github.com/kubernetes/kubernetes/issues/9995" rel="nofollow noreferrer">link</a> . All these are explained very well by one of the Kubernetes official Members.</p>
<p><strong>And the answer to your question</strong></p>
<p>Kubernetes just takes a random port and if that one conflicts and it finds that it isn't free it takes the next one.
You can refer to this <a href="https://github.com/kubernetes/kubernetes/blob/master/pkg/registry/core/service/portallocator/operation_test.go" rel="nofollow noreferrer">Kubernetes golang code</a>. (It is actually a set of test cases for the node port allocation operation. You can understand the behaviour from there).</p>
<p>And just a piece of additional information, it's possible to modify the node port default range by giving <code>--service-node-port-range</code> argument to the kube-apiserver</p>
