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.
3
Answers
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.
sudo apt install nginx
sudo vim /etc/nginx/conf.d/upstream.conf
Add following lines to the file. Replace and .
sudo nginx -t
Restart nginx server using
sudo systemctl reload nginx
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 lineinclude /etc/nginx/sites-enabled/*;
by adding # as prefix.Restart nginx and try again. (Follow steps 4, 5 and 6).
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 tominikube
.I would recommend using
kubeadm
and setting up single control-plane cluster with kubeadm.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
this comment is meant for something else.