我们正在使用我在Google Cloud Platform上创建的服务器来创建和管理那里的其他服务器。但是,当尝试使用 GCloud 计算实例创建函数从 Linux 命令行创建新服务器时,我们收到以下错误:
marco@ans-mgmt-01:~/gcloud$ ./create_gcloud_instance.sh app-tst-04 tst,backend-server,bootstrap home-tst 10.20.22.104
ERROR: (gcloud.compute.instances.create) Could not fetch resource:
- The resource 'projects/REMOVED_OUR_PROJECTID/global/images/family/debian-8' was not found
我们的脚本如下所示:
#!/bin/bash
if [ "$#" -ne 4 ]; then
echo "Usage: create_gcloud_instance <instance_name> <tags> <subnet_name> <server_ip>"
exit 1
fi
set -e
INSTANCE_NAME=$1
TAGS=$2
SERVER_SUBNET=$3
SERVER_IP=$4
gcloud compute --project "REMOVED OUR PROJECT ID" instances create "$INSTANCE_NAME"
--zone "europe-west1-c"
--machine-type "f1-micro"
--network "cloudnet"
--subnet "$SERVER_SUBNET"
--no-address
--private-network-ip="$SERVER_IP"
--maintenance-policy "MIGRATE"
--scopes "https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring.write","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append"
--service-account "default"
--tags "$TAGS"
--image-family "debian-8"
--boot-disk-size "10"
--boot-disk-type "pd-ssd"
--boot-disk-device-name "bootdisk-$INSTANCE_NAME"
./clean_known_hosts.sh $INSTANCE_NAME
在谷歌云控制台(console.cloud.google.com(上,我为ans-mgmt-01服务器启用了云api访问范围,并尝试从那里创建服务器。这是没有问题的工作。
问题是 gcloud 在你的项目中寻找的是镜像系列,而不是它真正存在的 debian-cloud 项目。
这可以通过简单地使用--image-project debian-cloud
来解决。
这样,它不会寻找projects/{yourID}/global/images/family/debian-8
,而是寻找projects/debian-cloud/global/images/family/debian-8
。
对我来说,问题是 debian-8(现在是 debian-9(到了生命周期的尽头,不再受支持。更新到 debian-10 或 debian-11 修复了此问题
对我来说,问题是 debian-9 在这么多时间结束并尝试更新到 debian-10 修复了这个问题
您可以运行以下命令以查看图像是否可用
gcloud compute images list | grep debian
下面是命令的结果
NAME: debian-10-buster-v20221206
PROJECT: debian-cloud
FAMILY: debian-10
NAME: debian-11-bullseye-arm64-v20221102
PROJECT: debian-cloud
FAMILY: debian-11-arm64
NAME: debian-11-bullseye-v20221206
PROJECT: debian-cloud
FAMILY: debian-11
所以你可以从你的结果中有一些想法