我需要在我的Compute引擎VM上执行命令。我们需要对SQL进行初始设置,计划是为此使用云构建(只触发一次);IAP已经实现,防火墙规则已经到位。(允许TCP 22在35.235.240.0/20之间)
这是我的构建步骤:
# Setup Cloud SQL
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
id: 'Setup Cloud SQL Tables'
entrypoint: 'bash'
args:
- -c
- |
echo "Upload File to $_SQL_JUMP_BOX_NAME" &&
gcloud compute scp --recurse cloud-sql/setup-sql.sh --tunnel-through-iap --zone $_ZONE "$_SQL_JUMP_BOX_NAME:~" &&
echo "SSH to $_SQL_JUMP_BOX_NAME" &&
gcloud compute ssh --tunnel-through-iap --zone $_ZONE "$_SQL_JUMP_BOX_NAME" --project "$_TARGET_PROJECT_ID" --command="chmod +x setup-sql.sh && ./setup-sql.sh"我收到这个错误:
root@compute.3726515935009049919: Permission denied (publickey).
WARNING:
To increase the performance of the tunnel, consider installing NumPy. For instructions,
please see https://cloud.google.com/iap/docs/using-tcp-forwarding#increasing_the_tcp_upload_bandwidth
root@compute.3726515935009049919: Permission denied (publickey).
ERROR: (gcloud.compute.scp) Could not SSH into the instance. It is possible that your SSH key has not propagated to the instance yet. Try running this command again. If you still cannot connect, verify that the firewall and instance are set to accept ssh traffic.

这也将被触发/执行到多个环境中,因此我们使用云构建来实现可重用性。
发布于 2022-07-04 19:11:02
已经开始工作了!我偶然发现了这个博客-- https://hodo.dev/posts/post-14-cloud-build-iap/
对我的脚本进行更改后,需要在SCP/SSH命令上指定用户
工作脚本/步骤:
# Setup Cloud SQL
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
id: 'Setup Cloud SQL Tables'
entrypoint: 'bash'
args:
- -c
- |
echo "Upload File to $_SQL_JUMP_BOX_NAME" &&
gcloud compute scp --recurse cloud-sql/setup-sql.sh --tunnel-through-iap --zone $_ZONE cloudbuild@$_SQL_JUMP_BOX_NAME:~ &&
echo "SSH to $_SQL_JUMP_BOX_NAME" &&
gcloud compute ssh --tunnel-through-iap --zone $_ZONE cloudbuild@$_SQL_JUMP_BOX_NAME --project "$_TARGET_PROJECT_ID" --command="chmod +x setup-sql.sh && ./setup-sql.sh"需要与目标VM相关的更改
之前: gcloud计算ssh隧道贯穿iap-zone $_ZONE "$_SQL_JUMP_BOX_NAME“
之后: gcloud计算ssh隧道贯穿iap-zone cloudbuild@$_SQL_JUMP_BOX_NAME $_ZONE
https://stackoverflow.com/questions/72859970
复制相似问题