minikube: Get the URL to use for a given NodePort

minikube NodePort URL service

2 min read | by Jordi Prats

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? minikube uses it's own networking layer so it is not as obvious a looking for listening ports using netstat

Let's assume we have created the following NodePort service:

apiVersion: v1 kind: Service metadata:  labels:  app: demo  name: demo  namespace: default spec:  ports:  - name: 80-80  port: 80  protocol: TCP  targetPort: 80  selector:  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, we are just going to be able to see that it has an assigned port by looking at the PORT(S) column:

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

To get the URL we will be able to use on out browser we will have to use the minikube CLI. The command we will need to use is minikube service: It's going to tell us the URL to use:

$ minikube service --url demo http://192.168.49.2:30431 

Using this URL we will be able to reach the pods behind the service we have created


Posted on 05/02/2021