【问题标题】:How to make the read-only port 10255 only available in the vpc in Google Cloud with GKE?如何使用 GKE 使只读端口 10255 仅在 Google Cloud 中的 vpc 中可用?
【发布时间】:2022-01-25 09:16:45
【问题描述】:

我注意到我已将只读端口 10255 开放给万维网。我们想让它只在 VPC 内部可用,就像 this answer 建议的那样。我不确定如何指定这样的规则。我尝试过类似的方法:

gcloud compute firewall-rules create "testcloseport" --action=DENY --rules tcp:10255  --source-tags=public --source-ranges=0.0.0.0/0 --description="Close port 10255 from outside the vpc"

不幸的是,我收到了这个错误:

ERROR: (gcloud.compute.firewall-rules.create) Could not fetch resource:
 - The resource 'projects/myproject-prod/global/networks/default' was not found

我尝试这样设置区域和区域:

gcloud config set compute/region us-east1
gcloud config set compute/zone us-east1-d

我仍然得到错误。我只是想为 VPC 的外部关闭这个端口。有没有办法可以更改 firewall-rules create 命令使其正常工作?

【问题讨论】:

  • 您提出问题的答案暗示您已经拥有或创建了一个 VPC 网络,您是否已经创建了一个?引用 “如果您使用 VPC,您可以将防火墙规则添加到端口 (10255),以仅允许来自 VPC 资源的传入流量。”

标签: google-cloud-platform google-kubernetes-engine


【解决方案1】:

您收到此错误的原因:

资源 'projects/myproject-prod/global/networks/default' 不是 找到了

是因为您尝试运行的gcloud 命令默认使用名为“default”的 VPC,这是默认出现的。

为了创建自定义网络 (VPC) 的防火墙规则,您必须传递参数 --network 例如(替换 ):

gcloud compute firewall-rules create testcloseport --network <MY_VPC_NAME> --action=DENY --rules tcp:10255  --source-tags=public --source-ranges=0.0.0.0/0 --description="Close port 10255 from outside the vpc"

还有一件事,使用上面的规则,您将拒绝端口 10255 上的任何 IP 源,因此您可能需要第二条具有更高优先级的规则,仅允许端口 10255 到您希望允许该连接通过的私有子网。

【讨论】:

    猜你喜欢
    • 2019-11-15
    • 2019-01-16
    • 1970-01-01
    • 2020-05-01
    • 2022-01-08
    • 2020-11-06
    • 2018-09-19
    • 2022-10-02
    • 2019-07-05
    相关资源
    最近更新 更多