minikube: Get the URL to use for a given NodePort

To avoid having to create an Ingress it is quite handy to use NodePort for testing purposes. But how do we get the URL we can use to connect to a NodePort on a minikube cluster?

Let's assume we are going to create the following NodePort service:

apiVersion: v1
kind: Service
    app: demo
  name: demo
  namespace: default
  - name: 80-80
    port: 80
    protocol: TCP
    targetPort: 80
    app: demo
  type: NodePort

We can apply it as usual:

$ kubectl apply -f demo.yaml
service/demo created

But we won't get an external IP out of the kubectl get svc command, just it's assigned port:

$ kubectl get svc
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
demo         NodePort   <none>        80:30431/TCP   9d
kubernetes   ClusterIP      <none>        443/TCP        9d

For minikube what we can do is to use minikube service to get the URL to use:

$ minikube service --url demo

Posted on 05/02/2021