How do I enable http traffic for GCE instance templates?

前端 未结 5 625
攒了一身酷
攒了一身酷 2020-12-20 17:48

When creating an instance template in Google Compute Engine, how do I enable http traffic for instances created from the template?

I was thinking that providing an h

相关标签:
5条回答
  • 2020-12-20 18:05

    The following should work in theory, but in practice, it didn't work.

    One potential solution is to enable http traffic for all of your instances in that project. To do so, from within GCE command line tools, run:

    gcloud compute firewall-rules create FIREWALL_RULE --allow tcp:80
    

    It's not clear to me that setting the rule for a particular instance template is possible, but hopefully someone will correct me if it is.

    0 讨论(0)
  • 2020-12-20 18:05

    If the query is allowing this vm as http or https server then I just used successfully:

    cloud compute instances add-tags myvm1 --tags=http-server
    
    0 讨论(0)
  • 2020-12-20 18:07

    One potential solution is to enable http traffic for all of your instances >in that project. To do so, from within GCE command line tools, run:

    gcloud compute firewall-rules create FIREWALL_RULE --allow tcp:80

    I try your command but it doesn't work because the command want the name of the instance:

    google130505_student@qwiklabs-gcp-286ef104ac93631b:~$ gcloud compute firewall-rules create FIREWALL_RULE --allow tcp:80
    Creating firewall...failed.
    ERROR: (gcloud.compute.firewall-rules.create) Could not fetch resource:
     - Invalid value for field 'resource.name': 'FIREWALL_RULE'. Must be a match of regex '(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)'
    google130505_student@qwiklabs-gcp-286ef104ac93631b:~$ gcloud compute firewall-rules create gclab2 --allow tcp:80
    Creating firewall.../Created [https://www.googleapis.com/compute/v1/projects/qwiklabs-gcp-286ef104ac93631b/global/firewalls/gclab2].
    Creating firewall...done.
    NAME    NETWORK  DIRECTION  PRIORITY  ALLOW   DENY
    gclab2  default  INGRESS    1000      tcp:80
    

    so the correct command is:

    gcloud compute firewall-rules create NAME_OF_YOUR_INSTANCE --allow tcp:80
    
    0 讨论(0)
  • 2020-12-20 18:10
    gcloud compute firewall-rules create FIREWALL_RULE --allow tcp:80,tcp:443 
    

    This command should do it

    0 讨论(0)
  • 2020-12-20 18:12

    The default network in the project comes with default firewall rules "default-allow-http" and "default-allow-https" to allow traffic on port 80 and 443. These rules have a target tag setup as "http-server". When setting up the instance template you can check the box "Allow HTTP traffic" and "Allow HTTPS traffic" from your developer console, by doing that the default firewall rules will be applied to the new instances created through this instance template.

    0 讨论(0)
提交回复
热议问题