<p>I have a minikube cluster with a running WordPress in one deployment, and MySQL in another. Both of the deployments have corresponding services. The definition for WordPress service looks like this:</p>

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

<p>The service works fine, and <code>minikube service</code> gives me a nice path, with an address of <code>minikube ip</code> and a random high port. The problem is <strong>WordPress needs a full URL in the name of the site</strong>. I'd rather not change it every single time and have local DNS name for the cluster.</p>

<p>Is there a way to expose the LoadBalancer on an arbitrary port in minikube? I'll be fine with any port, as long as it's port is decided by me, and not minikube itself?</p>

mhaligowski
<p>Keep in mind that <strong>Minikube</strong> is unable to provide real <strong>loadbalancer</strong> like different cloud providers and it merely simulates it by using simple <a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport" rel="nofollow noreferrer"><code>nodePort</code></a> <code>Service</code> instead.</p>

<p>You can have full control over the port that is used. First of all you can specify it manually in the <code>nodePort</code> <code>Service</code> specification (remember it should be within the default range: 30000-32767):</p>

<blockquote>
  <p>If you want a specific port number, you can specify a value in the
  <code>nodePort</code> field. The control plane will either allocate you that port
  or report that the API transaction failed. This means that you need to
  take care of possible port collisions yourself. You also have to use a
  valid port number, one that’s inside the range configured for NodePort
  use.</p>
</blockquote>

<p>Your example may look as follows:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
    name: wordpress
spec: 
    selector:
        app: wordpress
    ports:
        - port: 80
          targetPort: 80
          nodePort: 30000
    type: NodePort
</code></pre>

<p>You can also change this default range by providing your custom value after <code>--service-node-port-range</code> flag when starting your <code>kube-apiserver</code>.</p>

<p>When you use <strong>kubernetes cluster</strong> set up by <strong>kukbeadm</strong> tool (<strong>Minikube</strong> also uses it as a default bootstrapper), you need to edit <code>/etc/kubernetes/manifests/kube-apiserver.yaml</code> file and provide the required flag with your custom port range.</p>
