首页 > 解决方案 > Gcloud - 无法使用一个服务帐户配置多个 VM

问题描述

我正在使用 Gcloud 运行 Prow(持续集成服务器)。我的一项工作是创建一个虚拟机,执行一些测试,然后删除该实例。我使用服务帐户来创建 VM,运行测试。

#!/bin/bash

set -o errexit

cleanup() {
    gcloud compute instances delete kyma-integration-test-${RANDOM_ID}
}


gcloud config set project ...
gcloud auth activate-service-account --key-file ...

gcloud compute instances create <vm_name> \
    --metadata enable-oslogin=TRUE \
    --image debian-9-stretch-v20181009 \
    --image-project debian-cloud --machine-type n1-standard-4 --boot-disk-size 20 \

trap cleanup exit

gcloud compute scp --strict-host-key-checking=no --quiet <script.sh> <vm_name>:~/<script.sh>

gcloud compute ssh --quiet <vm_name> -- ./<script.sh>

一段时间后,我收到以下错误:

ERROR: (gcloud.compute.scp) INVALID_ARGUMENT: Login profile size exceeds 32 KiB. Delete profile values to make additional space.

实际上,对于该服务帐户,describe命令会返回大量数据,例如sshPublicKeys部分中的约 70 个条目。

gcloud auth activate-service-account --key-file ... gcloud compute os-login describe-profile

这些公钥中的大部分都引用了已删除的 VM 实例。如何执行此列表的清理?或者是否有可能根本不存储该公钥?

标签: google-cloud-platformcloudgcloudgoogle-iam

解决方案


一种对我有用的非常粗略的方法是:

for i in $(gcloud compute os-login ssh-keys list); do echo $i; gcloud compute os-login ssh-keys remove --key $i; done

在删除了几十个键后,我停止了这个(使用 Control-C),然后它再次工作。

实际上,在 GUI 中的项目元数据中,我没有看到很多关键点。仅有的 :

  • gke...cidr:网络名称...
  • sshKeys:gke-e9 ...
  • SSH 密钥 => peter_v : ssh-rsa 我的公钥

推荐阅读