Search code examples
localminikube

Minikube - External IP not match host's public IP


Shortly, I use GOOGLE COMPUTE ENGINE (external IP: 34.73.89.55, all ports and protocols are opened), then I install Docker, minikube, kubectl. Then:

minikube start --driver=docker

minikube tunnel

kubectl create deployment hello-minikube1 --image=k8s.gcr.io/echoserver:1.4

kubectl expose deployment hello-minikube1 --type=LoadBalancer --port=8080

kubectl get svc

and I get:

NAME              TYPE           CLUSTER-IP       EXTERNAL-IP      PORT(S)          AGE

hello-minikube1   LoadBalancer   10.110.130.109   10.110.130.109   8080:31993/TCP   9m22s

My question is, why the EXTERNAL-IP did not match with the host's external IP: 34.73.89.55? How can I access this service remotely by the host's external IP (ex: I'm at home and access via browser)?

Ps: I would like to use GOOGLE COMPUTE ENGINE.

EDIT: I also try:

 sudo minikube start --driver=none

 sudo kubectl create deployment hello-minikube1 --image=k8s.gcr.io/echoserver:1.4

 sudo kubectl expose deployment hello-minikube1 --type=NodePort --port=8080

 wget 127.0.0.1:8080

=>not work


Solution

  • By default minikube expects to run in a separate VM. This can be changed by explicitly specifying a driver.

    1. Why the EXTERNAL-IP did not match with the host's external IP?

    Because minikube uses a tunnel which creates a route to services deployed with type LoadBalancer and sets their Ingress to their ClusterIP. For a detailed example see this documentation.

    1. How can I access this service remotely by the host's external IP?

    I see two options here:

    • More recommended: Set --driver=none

    Minikube also supports a --driver=none option that runs the Kubernetes components on the host and not in a VM. Using this driver requires Docker and a Linux environment but not a hypervisor.

    • Might be less ideal: Use port forwarding (either using iptables or proxy). This might be less ideal.

    Also remember that minikube was created for testing purposes on locahost. Keep that in mind while using it.

    EDIT:

    When going for --driver=none you can:

    • Use NodePort type instead of LoadBalancer.

    • Continue using Loadbalancer with a modified Service by adding:

    spec: externalIPs: - <host_address>

    For example:

    apiVersion: v1
    kind: Service
    metadata:
     creationTimestamp: null
     labels:
       app: hello-minikube1
     name: hello-minikube1
    spec:
     externalIPs:
     - <host_address>
     ports:
     - port: 8080
       protocol: TCP
       targetPort: 8080
     selector:
       app: hello-minikube1
     type: LoadBalancer
    status:
     loadBalancer: {}
    

    The above was tested and resulted in EXTERNAL IP = HOST IP.

    Please let me know if that helped.