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.
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 .
upstream app_server_32108 {
server <minikube ip>:<port>;
}
server {
listen 80;
location /proxy {
proxy_pass http://app_server_32108/;
}
}
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 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).
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.