title: Kubernetes: how to access service if nodePort is random?
body: <p>I'm new to K8s and am currently using Minikube to play around with the platform. How do I configure a public (i.e. outside the cluster) port for the service? I followed the <a href="https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/#exposing-the-service" rel="noreferrer">nginx example</a>, and K8s service tutorials. In my case, I created the service like so:</p>
  
  <pre><code>kubectl expose deployment/mysrv --type=NodePort --port=1234
  </code></pre>
  
  <p>The service's port is 1234 for anyone trying to access it from INSIDE the cluster. The minikube tutorials say I need to access the service directly through it's random nodePort, which works for manual testing purposes:</p>
  
  <pre><code>kubectl describe service mysrv | grep NodePort
  ...
  NodePort:                 &lt;unset&gt;  32387/TCP
  # curl "http://`minikube ip`:32387/"
  </code></pre>
  
  <p>But I don't understand how, in a real cluster, the service could have a fixed world-accessible port. The nginx examples describe something about using the LoadBalancer service kind, but they don't even specify ports there...</p>
  
  <p>Any ideas how to fix the external port for the entire service?</p>