How to expose minikube in GCP VM

4/5/2020

I created a debian VM in GCP and installed kubectl and minikube. I deployed one image in the kubectl. I exposed the service using the command kubectl expose deployment hw --type=NodePort --port=80. It exposed in port 31343. But it is not accessible using the external ip of the VM. I added firewall rule to traffic to the port. But still it is not working. How can I access the site using the external ip of the VM.

I know, I can use the GKE. But I need to try the kubernetes installation and configuration. That's why I following these steps.

-- NOBLE M.O.
google-cloud-platform
kubectl
kubernetes

2 Answers

4/26/2020

I found a solution by using nginx proxy. May be using kubeadm as mentioned in the previous answer was the standard method. But I didn't get enough reference in the web. We can use the GCP vm external ip to connect to the nginx server and it will redirect the request to the minikube. Also return the response back.

  1. Install nginx in the linux vm using sudo apt install nginx
  2. Create a nginx config file sudo vim /etc/nginx/conf.d/upstream.conf
  3. Add following lines to the file. Replace and .

    upstream app_server_32108 {
        server <minikube ip>:<port>;
    }    
    server {
        listen 80;
        location /proxy {
           proxy_pass http://app_server_32108/;
        }
    }
    
  4. sudo nginx -t

  5. Restart nginx server using sudo systemctl reload nginx

  6. Now the content hosted in minikube can access using http://<vm ip>/proxy

If it is not accessible edit nginx config file sudo vim /etc/nginx/nginx.conf and add comment to the line include /etc/nginx/sites-enabled/*; by adding # as prefix.

#include /etc/nginx/sites-enabled/*;

Restart nginx and try again. (Follow steps 4, 5 and 6).

-- NOBLE M.O.
Source: StackOverflow

4/7/2020

Minikube is basically a VM, so you are running a VM inside a VM.

You have exposed deployment from your Minikube to the VM, you can check what is the address of your Minikube using $ minikube ip or $ minikube status.

In order for this to work now you would need to setup a proxy on your GCP VM that would send traffic to minikube.

I would recommend using kubeadm and setting up single control-plane cluster with kubeadm.

-- Crou
Source: StackOverflow