简体   繁体   中英

How to expose minikube in GCP VM

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.

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 .

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).

So the few answers above are probably things you should do, what you also should do is allow the port in the VPC firewall

Consider the firewall rule you need either through the web interface or from the console you can apply it like the comment below

gcloud compute firewall-rules create "allow-internal-memcache" --allow=tcp:31343 --source-ranges="10.0.0.0/22,10.0.0.0/14" --description="Allow internal traffic and drop outside"

this comment is meant for something else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM