動かざることバグの如し

近づきたいよ 君の理想に

GCPのインスタンスを生成するコマンド

コード

PROJECT=myproject
NAME=db01
TYPE=g1-small
DISK_SIZE=10GB
ZONE=asia-east1-a

gcloud compute --project $PROJECT \
instances create $NAME \
  --zone $ZONE \
  --machine-type $TYPE \
  --tags http-server,https-server,trains \
  --image-family ubuntu-1604-lts \
  --image-project ubuntu-os-cloud \
  --boot-disk-size $DISK_SIZE \
  --boot-disk-type pd-standard \
  --boot-disk-auto-delete \
  --boot-disk-device-name $NAME-disk \
  --metadata=sshKeys="user:$(cat /Users/thr3a/.ssh/id_rsa.pub)"
  • PROJECT プロジェクト名
  • NAME インスタンス名 任意だが重複不可
  • TYPE インスタンスタイプ
  • DISK_SIZE ディスクサイズ GB単位
  • ZONE リージョン

その他のオプション

  • boot-disk-auto-delete インスタンス削除時にディスクも自動で削除する
  • metadata=sshKeys SSH認証鍵を設定したい場合
$ ./gcp.sh 
WARNING: You have selected a disk size of under [200GB]. This may result in poor I/O performance. For more information, see: https://developers.google.com/compute/docs/disks#performance.

Created [https://www.googleapis.com/compute/v1/projects/myproject/zones/asia-east1-a/instances/db01].
NAME  ZONE          MACHINE_TYPE  PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP     STATUS
db01  asia-east1-a  g1-small                   10.240.0.3   xxxxxxx  RUNNING