Search code examples
dockernetwork-programmingkubernetesgcloudminikube

How to access minikube dashboard from external browser, deployed on gcloud compute engine


I created an ubuntu instance on gcloud and installed minikube and all the required dependency in it. Now I can do curl from gnode terminal "curl http://127.0.0.1:8080/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/" I get the HTML response back.

But I want to Access this URL from my Laptop browser. I tried opening these Ports in firewall of instance-node tcp:8080,8085,443,80,8005,8006,8007,8009,8009,8010,7990,7992,7993,7946,4789,2376,2377

But still unable to access the above mentioned url while replacing it with my external(39.103.89.09) IP i.e http://39.103.89.09:8080/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

I believe I need to do some networking related changes but don't know what.

I am very new to Cloud computing and networking so please help me.


Solution

  • I suspect that minikube binds to the VM's localhost interface making it inaccessible from a remote machine.

    There may be a way to run minikube such that it binds to 0.0.0.0 and then you may be able to use it remotely.

    Alternatively, you can keep the firewall limited to e.g. 22 and use SSH to port-forward the VM's port 8080 to your localhost. `gcloud' includes a helper for this too:

    1. Ensure minikube is running on the VM
    2. gcloud compute ssh ${INSTANCE} --project=${PROJECT} --zone=${ZONE} --ssh-flag="-L 8080:localhost:8080"
    3. Try accessing Kubernetes endpoints from your local machine using localhost:8080/api/v1/...

    Update

    OK, I created a Debian VM (n1-instance-2), installed docker and minikube.

    SSH'd into the instance:

    gcloud compute ssh ${INSTANCE} \
    --zone=${ZONE} \
    --project=${PROJECT}
    

    Then minikube start

    Then:

    minikube kubectl -- get namespaces
    NAME              STATUS   AGE
    default           Active   14s
    kube-node-lease   Active   16s
    kube-public       Active   16s
    kube-system       Active   16s
    

    minikube appears (I'm unfamiliar it) to run as a Docker container called minikube and it exposes 4 ports to the VM's (!) localhost: 22,2376,5000,8443. The latter is key.

    To determine the port mapping, either eyeball it:

    docker container ls \
    --filter=name=minikube \
    --format="{{.Ports}}" \
    | tr , \\n
    

    Returns something like:

    127.0.0.1:32771->22/tcp
    127.0.0.1:32770->2376/tcp
    127.0.0.1:32769->5000/tcp
    127.0.0.1:32768->8443/tcp
    

    In this case, the port we're interested in is 32768

    Or:

    docker container inspect minikube \
    --format="{{ (index (index .NetworkSettings.Ports \"8443/tcp\") 0).HostPort }}"
    32768
    

    Then, exit the shell and return using --ssh-flag:

    gcloud compute ssh ${INSTANCE} \
    --zone=${ZONE} \
    --project=${PROJECT} \
    --ssh-flag="-L 8443:localhost:32768"
    

    NOTE 8443 will be the port on the localhost; 32768 is the remote minikube port

    Then, from another shell on your local machine (and while the port-forwarding ssh continues in the other shell), pull the ca.crt, client.key and client.crt:

    gcloud compute scp \
    $(whoami)@${INSTANCE}:./.minikube/profiles/minikube/client.* \
    ${PWD} \
    --zone=${ZONE} \
    --project=${PROJECT} 
    
    gcloud compute scp \
    $(whoami)@${INSTANCE}:./.minikube/ca.crt \
    ${PWD} \
    --zone=${ZONE} \
    --project=${PROJECT}
    

    Now, create a config file, call it kubeconfig:

    apiVersion: v1
    clusters:
    - cluster:
        certificate-authority: ./ca.crt
        server: https://localhost:8443
      name: minikube
    contexts:
    - context:
        cluster: minikube
        user: minikube
      name: minikube
    current-context: minikube
    kind: Config
    preferences: {}
    users:
    - name: minikube
      user:
        client-certificate: ./client.crt
        client-key: ./client.key
    

    And, lastly:

    KUBECONFIG=./kubeconfig kubectl get namespaces
    

    Should yield:

    NAME              STATUS   AGE
    default           Active   23m
    kube-node-lease   Active   23m
    kube-public       Active   23m
    kube-system       Active   23m