Search code examples
javagoogle-cloud-platformgoogle-compute-enginedropwizard

Cannot access java application outside compute engine but its running on localhost


I have a dropwizard application. And a e2-small (2 vCPUs, 2 GB memory) memory. When I run the application passing necessary properties it run successfully without error.(log snippet at end of question)

My application is running on port 8080 and from my compute engine console(after connecting SSH) I do

curl http://0.0.0.0:8080

It returns me as expected. But I am not able to access this application from outside. I have External IP (needed that for cloud SQL too) , so I try to access the application as http://externalip:8080 it does not return me anything . Also curl http://externalip:8080 from compute engine console(after connecting SSH) does not return anything.

I have allowed http and https traffic in firewall section while creating compute engine instance.

I have set up my deployment pipeline(using third party tool) using same external ip and it successfully copies my artifacts to my compute engine. So I am sure the external ip is enabled.

Can you please help me understand what might be the issue?

INFO [2020-11-18 15:32:09,981] org.eclipse.jetty.server.handler.ContextHandler: Started i.d.j.MutableServletContextHandler@4850a747{/,null,AVAILABLE} INFO [2020-11-18 15:32:09,995] org.eclipse.jetty.server.AbstractConnector: Started application@50a0404b{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} INFO [2020-11-18 15:32:09,997] org.eclipse.jetty.server.AbstractConnector: Started application@e328d88{HTTP/1.1,[http/1.1]}{0.0.0.0:8443} INFO [2020-11-18 15:32:09,998] org.eclipse.jetty.server.AbstractConnector: Started admin@78ea668{HTTP/1.1,[http/1.1]}{0.0.0.0:8081} INFO [2020-11-18 15:32:09,999] org.eclipse.jetty.server.AbstractConnector: Started admin@10af6715{HTTP/1.1,[http/1.1]}{0.0.0.0:8444} INFO [2020-11-18 15:32:10,000] org.eclipse.jetty.server.Server: Started @9687ms 127.0.0.1 - - [18/Nov/2020:15:33:53 +0000] "GET / HTTP/1.1" 200 2314 "-" "curl/7.64.0" 54 127.0.0.1 - - [18/Nov/2020:15:34:13 +0000] "GET / HTTP/1.1" 200 2314 "-" "curl/7.64.0" 3


Solution

  • By default GCP firewall denies any ingress traffic. Ingress traffic is traffic that originates outside the network that is traveling into the network For same was the reason any http request from outside VM instance were getting Connection refused error.

    I followed

    1. https://cloud.google.com/vpc/docs/using-vpc and
    2. https://cloud.google.com/vpc/docs/using-firewalls

    After which we added firewall rules for my project(u can make it instance level too) and allowed ingress traffic which resolved my issue