skip to Main Content

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


  1. Chosen as BEST ANSWER

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


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

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search