google-cloud-platform - 更新 Deployment Manager 部署时如何在 VM 实例上执行命令行脚本
问题描述
我目前在我的vm.yaml
文件中有此配置,它设置了一个允许 http 请求并提供自定义Hello World!
页面的 vm 实例,如以下startup-scripts
部分所述:
resources:
- type: compute.v1.instance
name: quickstart-deployment-vm
properties:
zone: us-central1-f
machineType: https://www.googleapis.com/compute/v1/projects/my_project/zones/us-central1-f/machineTypes/f1-micro
disks:
...
networkInterfaces:
...
tags:
items: ["http"]
metadata:
items:
- key: startup-script
value: |
#!/bin/bash
apt-get update
apt-get install -y apache2
echo '<!doctype html><html><body><h1>Hello World!</h1></body></html>' | sudo tee /var/www/html/index.html
- type: compute.v1.firewall
name: tcp-firewall-rule
properties:
targetTags: ["http"]
network: https://www.googleapis.com/compute/v1/projects/my_project/global/networks/default
sourceRanges: ["0.0.0.0/0"]
targetTags: ["http","http-server"]
allowed:
- IPProtocol: TCP
ports: ["80"]
运行后,我在访问 vm 的外部 ip 时gcloud deployment-manager deployments create vm-deploy --config vm.yaml
得到了预期的响应。Hello World!
但是,我现在想更新此部署以更改响应的内容,比如说,What's up, everyone!
但是,似乎我不能仅通过更改该startup-scripts
部分中的内容来做到这一点。我试着把它放在一个vm-update.yaml
文件中:
resources:
- type: compute.v1.instance
name: quickstart-deployment-vm
properties:
...
metadata:
items:
- key: startup-script
value: |
#!/bin/bash
apt-get update
apt-get install -y apache2
echo '<!doctype html><html><body><h1>What's up, everyone!</h1></body></html>' | sudo tee /var/www/html/index.html
- type: compute.v1.firewall
name: tcp-firewall-rule
properties:
...
并跑了gcloud deployment-manager deployments update vm-deploy --config vm-update.yaml
。但是,响应和index.html
文件并没有改变,它们仍然是Hello World!
. 我猜这是因为startup-script
仅在实例创建时执行,而不是在实例更新时执行。有谁知道当我更新虚拟机时如何使用部署管理器在我的虚拟机上执行脚本?
解决方案
我发现的一个“黑客”是我可以更改machineType
虚拟vm-update.yaml
机的startup-script
.
推荐阅读
- python - Tkinter 文本小部件逐行着色动画
- google-bigquery - BigQuery ga_realtime_sessions 表生命周期
- excel - excel - vba 防止自定义样式缩进删除
- image - ffmpeg:从 .mp3 和 .jpg 创建 .mp4
- python - 在尝试绘制昼夜图时面临这个非常特殊的错误
- rust - 在 Rust 宏中,如何跟随符号获取另一个函数定义的令牌流?
- flutter - 为什么在颤动中使用 Colors.color_name[value] 设置背景颜色时显示错误?
- react-native - 在 React Native 中安装模块时出错
- api - 无法使用Api拦截python返回response.url
- javascript - 签名板