もくじ
Gcloud
- ほとんどのGCPサービスはCLI(コマンドライン)から管理する事が可能
- Compute Engine Virtual Machine
- マネージドインスタンスグループ
- データベースなどなど
- 作成・削除・更新・読み込みやデプロイのようなアクションも可能
- 特定のCLIツールを持つサービスがある
- Cloud Storage – gsutil
- Cloud BigQuery – bq
- Cloud Bigtable – cbt
- Kubernetes -kubectl
gcloudの準備
- インストール
- GcloudはGoogle Cloud SDKの一部
Cloud SDKはPythonを必要とする - Cloud Shellで使用することもできる
- GcloudはGoogle Cloud SDKの一部
- GCPへの接続
- gcloud init -gloudを初期化または再初期化
gcloudがあなたのユーザーアカウント認証情報を使用することを承認 - gcloud config list -アクティブな構成のすべてのプロパティを一覧表示
- gcloud init -gloudを初期化または再初期化
gcloudのconfig set
- アクティブなConfigrationにプロパティを設定する
- gcloud config set compute/region us-east2 -regionの設定
- gcloud config set compute/zone us-east1-b -zoneの設定
- gcloud config list -一覧
- 構文:gcloud config set SECTION/PROPERTY VALUE
- SECTION: coreまたはcompute
- PROPERTY: プロジェクト、リージョン、ゾーン
- SECTIONはデフォルトではcoreなので、指定しなくても良い
- gcloud config set (core/)project VALUE
- gcloud config set –help で詳細確認
- gcloud config unset で解除
Configurationの管理
- gcloud config configurations create/delete/describe/active/list
- 新しい設定の作成:gcloud configurations create NAME(dev)
- 設定の有効化:gcloud configurations active NAME(dev)
- コンフィグの一覧:gcloud configurations list
gcloudコマンドの構成
- gcloud GROUP SUBGROUP ACTION
- GROUP:どのサービスを使用しているか(config, compute, container, dataflow, functions, iam,…)
- SUBGROUP:どのサブグループを使用するか(instances, images, instance-templates, machine-types, regions, zones,…)
- ACTION:どうするか(create, list, start, describe,…)
- 例
- gcloud compute instances list
- gcloud compute machine-types list –filter=”zone:us-central1-b”
- gcloud compute machine-types list –filter=”zone:(us-central1-b europe-west1-d)”
Cmpute Instanceの作成
- gcloud compute instance create [NAME]
- オプション
- -machine-type (デフォルトは n1-standard-1 – gcloud compute machine-types list)
- –custom-cpu –custom-memory –custom-vm-type(n1/n2) (カスタムマシン)
- –custom-cpu 6 –custom-memory 3072MB –custom-vm-type n2
- –image または –image-family または –source-snapshot または –source-instance-template または –source-machine-image (ベータ版)
- –service-account または –no-service-account
- –zone=us-central1-b
- -tags(タグのリスト – VMインスタンスに適用されるネットワークファイアウォールルールおよびルートを許可する)
- –preemptible
- –restart-on-failure(default) –no-restart-on-failure –maintenance-policy(MIGRATE(default)/TERMINATE)
- –deletion-protection –no-deletion-protection(デフォルト)
- –metadata/metadata-from-file startup-script/startup-script-url
- –metadata-from-file startup-script=/local/path/to/script/startup OR –metadata startup-script=”echo ‘hello world’””.
- –network –subnet –network-tier (PREMIUM(デフォルト)、STANDARD)
- –accelerator=”type=nvidia-tesla-v100,count=8″ –metadata=”install-nvidia-driver=True” (GPU)です。
リージョンとゾーンの設定と優先順位
- Option1(一元化設定):gcloud compute project-info add-metadata –metadata=[google-compute-default-region=REGION|google-compute-default-zone=ZONE]
- Option2(ローカルなgcloudの設定):gcloud config set compute/region REGION
- Option3(コマンドに指定):gcloud compute instance create [NAME] –zone or –region
- 優先順位:OP3 > OP2 > OP1
コマンドの一覧と説明
- list:リソース集合をリストアップするために使用
- gcloud compute image/region/ zones/disk-types list
- いくつかの共有のオプションがある
- –filter=”zone:VALUE”
- –sort-by (NAME, ~NAME)
- gcloud compute images list –sort-by NAME –filter “PROJECT:(windows-cloud ubuntu-os-cloud)”
- describe:特定のリソースを記述
- gcloud compute images describe ubuntu-1604-xenial- v20210203 –project ubuntu- os-cloud
- gcloud compute regions describe us-central1
Compute Instanceの操作
- gcloud compute instances list/start/stop/delete/reset/describe/move
- gcloud compute instances start example-instance
- gcloud compute instances stop example-instance-1 example-instance-2
- gcloud compute instances move example-instance-1 –zone us-central1-b –destination-zone us- central1-f
VMのゾーンを移動
インスタンステンプレートの操作
- gcloud compute instance-templates create/delete/describe/list
- gcloud compute instance-templates create INSTANCE-TEMPLATE:インスタンスの作成
- –source-instance=SOURCE_INSTANCE
–source-instance-zone (どのインスタンスからテンプレートを作成するか?) - gcloud compute instances create [NAME]で使われるオプションのほぼ全てをサポートしている
- gcloud compute instances create my-test-vm –source-instance-template=my-instance-template- with-custom-image
インスタンステンプレートを使用してインスタンスを作成