如何在命令行上查找 Google Cloud VM 实例的区域
问题:
你有一个 VM 实例(在我们的示例中为 my-instance),你想使用 gcloud 命令行工具查找它所在的区域。
解决方案
如果你只想查看实例的区域(记住将 my-instance 替换为你的实例名称!),使用
gcloud-instances-list.js
gcloud compute instances list --filter="name=my-instance" --format "[box]"这将格式化输出并显示有关你实例的更多信息。示例输出:
gcloud-output.txt
┌─────────────┬────────────────┬─────────────────────────────┬─────────────┬─────────────┬───────────────┬─────────┐
│ NAME │ ZONE │ MACHINE_TYPE │ PREEMPTIBLE │ INTERNAL_IP │ EXTERNAL_IP │ STATUS │
├─────────────┼────────────────┼─────────────────────────────┼─────────────┼─────────────┼───────────────┼─────────┤
│ my-instance │ europe-west3-c │ custom (16 vCPU, 32.00 GiB) │ │ 10.156.0.1 │ 35.207.77.101 │ RUNNING │
└─────────────┴────────────────┴─────────────────────────────┴─────────────┴─────────────┴───────────────┴─────────┘在此示例中,区域为 europe-west3-c。
如果你想只查看区域,请使用此命令:
gcloud-get-zone.sh
gcloud compute instances list --filter="name=katc-main" --format "get(zone)" | awk -F/ '{print $NF}'示例输出:
gcloud-zone-output.txt
europe-west3-c另请参见我们的其他文章如何在命令行上查找 Google Cloud VM 实例的 IP 地址。
要查看你可以以类似方式查看有关实例的其他信息,使用
gcloud-instances-list-text.sh
gcloud compute instances list --filter="name=my-instance" --format "text"Check out similar posts by category:
Cloud
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow