How do I enable http traffic for GCE instance templates?

╄→尐↘猪︶ㄣ 提交于 2019-12-19 17:27:28

问题


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 http tag would work, but it doesn't seem to do so.


回答1:


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.




回答2:


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.




回答3:


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



回答4:


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


来源:https://stackoverflow.com/questions/31509722/how-do-i-enable-http-traffic-for-gce-instance-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!