我正在尝试使用marketplace posgresql11镜像构建一个VM (尽管这个问题似乎对我尝试过的所有镜像都是通用的),使用以下GCLOUD命令:
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.txtenvdata.txt文件包含映像的环境变量数据,metadata.txt文件包含格式化和挂载postgres数据的外部磁盘的bootcmd指令。
envdata.txt:
POSTGRES_USER=postgresuser
POSTGRES_PASSWORD=postgrespasswordmetadata.txt:
#cloud-config
bootcmd:
- fsck.ext4 -tvy /dev/sdb
- mkdir -p /mnt/disks/postgres_data
- mount -t ext4 -O ... /dev/sdb /mnt/disks/postgres_dataVM已创建,但sudo journalctl命令显示正在尝试连接到GCR,但这似乎不成功。postgres的docker映像不会下载,也不会在VM上启动。
如果我现在通过执行以下命令从cloud命令的network-interface行中删除no-address命令(允许google为VM分配一个外部IP地址):
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然后创建一个VM,下载POSTGRES映像并执行。sudo journalctl显示到GCR的连接正在启动。
谁能向我解释一下,为什么在我的情况下,映像的执行依赖于拥有外部IP,以及我如何使用GCR创建VM,而不必为实例分配外部IP地址?
发布于 2020-11-30 16:06:05
如果您有公网IP,则从您的实例到Internet的请求将通过Internet网关。如果您的实例没有公网IP,则需要设置Cloud NAT来提供到Internet的路由。这是最简单的解决方案。如果您只需要访问Google API和服务,而不需要访问公共互联网,请参阅下一个选项。
谷歌还提供了只能访问谷歌API和服务的Private Google Access。
https://stackoverflow.com/questions/65069759
复制相似问题