猿问

使用 python api 列出特定 gke 集群的防火墙?

我试图在 Project 下列出特定 GKE 集群的防火墙。(比如说,如果我的集群名称是项目“myproject”下的“democluster_1”)。如何列出特定于“democluster_1”的防火墙?

我使用这个 python API 列出了项目“myproject”下的所有防火墙。我需要知道如何为特定集群列出它..?https://cloud.google.com/compute/docs/reference/rest/v1/firewalls/list

我在这个 python-API 中探索了过滤器参数,但我不清楚如何使用这个参数。您能否举例说明如何为特定 GKE 集群过滤防火墙。或者是否有任何其他方法可以列出它..?

提前致谢。


一只萌萌小番薯
浏览 117回答 1
1回答

aluckdog

gcloud CLI我不熟悉 Python,但如果您想按照GKE 文档列出它们。$ gcloud compute firewall-rules list在我的项目中,我有大约 46 条防火墙规则:$ gcloud compute firewall-rules list | wc -lTo show all fields of the firewall, please show in JSON format: --format=jsonTo show all fields in table format, please see the examples in --help.46如果你想获得特定于你的集群的防火墙规则,你需要使用类似的东西:$ gcloud compute firewall-rules list --project <project-name> --filter="name~gke-<your-cluster-name>-[0-9a-z]*"在我的例子中,它只为这个测试集群指定了 3 条规则cluster。$ gcloud compute firewall-rules list --project <myproject> --filter="name~gke-cluster-[0-9a-z]*"NAME&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NETWORK&nbsp; DIRECTION&nbsp; PRIORITY&nbsp; ALLOW&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DENY&nbsp; DISABLEDgke-cluster-XXX-all&nbsp; default&nbsp; INGRESS&nbsp; &nbsp; 1000&nbsp; &nbsp; &nbsp; tcp,udp,XXX&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Falsegke-cluster-XXX-ssh&nbsp; default&nbsp; INGRESS&nbsp; &nbsp; 1000&nbsp; &nbsp; &nbsp; tcp:XX&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Falsegke-cluster-XXX-vms&nbsp; default&nbsp; INGRESS&nbsp; &nbsp; 1000&nbsp; &nbsp; &nbsp; icmp,tcp:1-XXXXX,udp:1-XXXXX&nbsp; &nbsp; &nbsp; &nbsp; False
随时随地看视频慕课网APP

相关分类

Python
我要回答