[英]Cannot create a Google Compute Engine VM with a container image without en external IP address
I am attempting to build a VM using the marketplace posgresql11 image (though the problem appears to be general for all images I have tried) with the following GCLOUD command:我正在尝试使用以下 GCLOUD 命令使用市场 posgresql11 映像构建 VM(尽管对于我尝试过的所有映像,该问题似乎都很普遍):
gcloud compute instances create-with-container postgres-test \
--container-image gcr.io/cloud-marketplace/google/postgresql11:latest \
--container-env-file=envdata.txt \
--container-mount-host-path mount-path=/var/lib/postgresql,host-path=/mnt/disks/postgres_data,mode=rw \
--machine-type=e2-small \
--scopes=cloud-platform \
--boot-disk-size=10GB \
--boot-disk-device-name=postgres-test \
--create-disk="mode=rw,size=10GB,type=pd-standard,name=postgres-test-data,device-name=postgres-test_data" \
--network-interface=subnet="default,no-address" \
--tags=database-postgres \
--metadata-from-file user-data=metadata.txt
The envdata.txt file contains the environment variable data for the image and the metadata.txt file contains bootcmd instructions to format and mount the external disk for the postgres data. envdata.txt 文件包含映像的环境变量数据, metadata.txt 文件包含 bootcmd 指令,用于格式化和挂载 postgres 数据的外部磁盘。
envdata.txt:环境数据.txt:
POSTGRES_USER=postgresuser
POSTGRES_PASSWORD=postgrespassword
metadata.txt:元数据.txt:
#cloud-config
bootcmd:
- fsck.ext4 -tvy /dev/sdb
- mkdir -p /mnt/disks/postgres_data
- mount -t ext4 -O ... /dev/sdb /mnt/disks/postgres_data
The VM is created but and the sudo journalctl command shows that an attempt is starting to connect to the GCR but this appears to not be successful. VM 已创建,但 sudo journalctl 命令显示尝试开始连接到 GCR,但这似乎不成功。 The docker image for postgres is not downloaded and is not started on the VM.
用于 postgres 的 docker 映像未下载且未在 VM 上启动。
If I now remove the no-address command from the network-interface line of the cloud command (allowing google to allocate an external IP address to the VM) by executing the following:如果我现在通过执行以下命令从 cloud 命令的 network-interface 行中删除 no-address 命令(允许 google 将外部 IP 地址分配给 VM):
gcloud compute instances create-with-container postgres-test \
--container-image gcr.io/cloud-marketplace/google/postgresql11:latest \
--container-env-file=envdata.txt \
--container-mount-host-path mount-path=/var/lib/postgresql,host-path=/mnt/disks/postgres_data,mode=rw \
--machine-type=e2-small \
--scopes=cloud-platform \
--boot-disk-size=10GB \
--boot-disk-device-name=postgres-test \
--create-disk="mode=rw,size=10GB,type=pd-standard,name=postgres-test-data,device-name=postgres-test_data" \
--network-interface=subnet="default" \
--tags=database-postgres \
--metadata-from-file user-data=metadata.txt
Then a VM is created, the POSTGRES image is downloaded and is executed.然后创建一个 VM,下载并执行 POSTGRES 映像。 sudo journalctl shows that the connection to GCR starting and started.
sudo journalctl 显示与 GCR 的连接正在启动并已启动。
Can anyone explain to me why the execution of an image in my case is dependant on having an external IP and how I can create a VM using the GCR without having to allocate an external IP address to the instance?谁能向我解释为什么在我的情况下执行图像取决于具有外部 IP 以及如何使用 GCR 创建 VM 而无需为实例分配外部 IP 地址?
If you have a public IP, then requests from your instance to the Internet go thru the Internet Gateway.如果您有公共 IP,则通过 Internet 网关从您的实例向 Internet go 请求。 If your instance does not have a public IP then you need to setup Cloud NAT to provide a route to the Internet.
如果您的实例没有公共 IP,那么您需要设置 Cloud NAT 以提供到 Internet 的路由。 This is the simplest solution.
这是最简单的解决方案。 If you only need to access Google APIs and services and not the public Internet, see the next option.
如果您只需要访问 Google API 和服务而不需要访问公共 Internet,请参阅下一个选项。
Google also offers Private Google Access
to reach only Google APIs and services. Google 还提供
Private Google Access
以仅访问 Google API 和服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.