Tan Kin Meng
Tan Kin Meng

Reputation: 47

Unable to view flask app on reserved static address on Google Cloud Platform

Instead of the usual way of deployment via Gcloud command line, I simply sshed the GCP Ubuntu instance and deployed my flask app via WinSCP by transferring the files onto the Ubuntu instance I have created. I was able to get it to run like so:

Flask server

I have also reserved a static address so that I could allow users to view the Flask app.

However, when I tried to access the external ip address, GCP refused to connect and I can't view my flask app.

What could I have possibly done wrong?

Upvotes: 3

Views: 1309

Answers (1)

Neo Anderson
Neo Anderson

Reputation: 6340

There is no VPC Firewall rule to allow ingress traffic to your instance on tcp/8080.

First step: Add a network tag on your GCE instance, allow-8080-ingress.

Second step: Under the web menu, go to VPC Network - Firewall - Create Firewall Rule and create a new rule with following properties:

  • Name: Whatever8080
  • Network: [select the network to whom your instance belongs to]
  • Direction of traffic: Ingress
  • Action on match: Allow
  • Targets: Specified target tags
  • Target Tags: allow-8080-ingress (the network tag that you added on your instance)
  • Source filter: IP ranges
  • Source IP ranges: 0.0.0.0/0 <<== This will allow incoming traffic from any IP. You may be more specific, choosing a smaller range or even a specific IP address.
  • Specified protocols and ports: Check tcp and add 8080

You did not attached the your flask code, but if you launch it like this, it will just work:

if __name__ == '__main__':     
  app.run(host='0.0.0.0', port=8080)

...being able to access it by the public IP:

enter image description here

Upvotes: 4

Related Questions