谷歌云gcp shell 新建实例的代码

# 设置变量
project_name=$(gcloud config get-value project)
machine_name=my-vm
region=us-central1
zone=us-central1-a # 选择一个可用区域
machine_type=e2-medium
image_family=debian-11
image_project=debian-cloud
disk_size=20 # 20 GB
public_ip_name=${machine_name}-ip

# 创建静态 IP 地址(如果需要)
gcloud compute addresses create $public_ip_name –region=$region

# 获取分配的静态 IP 地址
public_ip=$(gcloud compute addresses describe $public_ip_name –region=$region –format=”value(address)”)

# 创建虚拟机实例
gcloud compute instances create $machine_name \
–project=$project_name \
–zone=$zone \
–machine-type=$machine_type \
–network-interface=network-tier=PREMIUM,nic-type=GVNIC,stack-type=IPV4_ONLY,subnet=default,address=$public_ip \
–image-family=$image_family \
–image-project=$image_project \
–boot-disk-size=$disk_size \
–tags=http-server,https-server \
–no-shielded-secure-boot \
–shielded-vtpm \
–shielded-integrity-monitoring

Comments

No comments yet. Why don’t you start the discussion?

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注