LoginSignup
1
1

More than 1 year has passed since last update.

GCP触ってみた②

Posted at

WindowsのGoogle Cloud SDK Shell入れたけどタブ補完利かなくて不便でWebコンソールからやってるのは内緒

Cloud IAM

「IAMと管理」から「IAM」を選択する
image.png

「アクセス権を付与」を選択する
image.png

自分のアカウントを使っているのでここに載せられないが、Gmailアカウントにサービスごとのアクセス権を付与できるらしい
最小限のアクセス権を付与するのが望ましいのはAWSと考え方が変わらないような気がする

Google Compute Engine(GCE)

AWSでいうEC2。仮想マシンのリソースを利用できる

GCP触ってみた①で一度やっているが、もう一度インスタンスを作成してみる

インスタンスの作成

gcloud compute instances create gcp --preemptible --zone=us-west1-a --machine-type=e2-micro

今回は起動タイプ、ゾーンを指定してみる

Created [https://www.googleapis.com/compute/v1/projects/<projectID>/zones/us-west1-a/instances/gcp].
NAME: gcp
ZONE: us-west1-a
MACHINE_TYPE: e2-micro
PREEMPTIBLE: true
INTERNAL_IP: 10.138.0.4
EXTERNAL_IP: 35.247.113.32
STATUS: RUNNING

いいのではないか

image.png

GUIから見てもインスタンスが作成されている
ゾーンも正しそうだ

image.png

image.png

ほかの起動オプションも動作してるようだ

インスタンスの削除(できなくて焦る)

# インスタンス一覧表示
gcloud compute instances list
NAME: gcp
ZONE: us-west1-a
MACHINE_TYPE: e2-micro
PREEMPTIBLE: true
INTERNAL_IP: 10.138.0.4
EXTERNAL_IP: 35.247.113.32
STATUS: RUNNING

NAME: gcppractice
ZONE: us-west1-a
MACHINE_TYPE: n1-standard-1
PREEMPTIBLE: true
INTERNAL_IP: 10.138.0.3
EXTERNAL_IP: 34.168.195.33
STATUS: RUNNING

NAME: gcpstudy
ZONE: us-west1-a
MACHINE_TYPE: n1-standard-1
PREEMPTIBLE:
INTERNAL_IP: 10.138.0.2
EXTERNAL_IP: 35.197.82.4
STATUS: RUNNING
# インスタンス削除
gcloud compute instances delete gcpstudy -q
ERROR: (gcloud.compute.instances.delete) Underspecified resource [gcpstudy]. Specify the [--zone] flag.

どうやら削除コマンドの実行の時もゾーンを指定する必要があるらしい

gcloud compute instances delete gcpstudy --zone=us-west1-a
The following instances will be deleted. Any attached disks configured to be auto-deleted will be deleted unless they are attached to any other instances or the `--keep-disks` flag is given and specifies them for keeping. Deleting a disk is irreversible and any data on the disk will be lost.
 - [gcpstudy] in [us-west1-a]

Do you want to continue (Y/n)?  y

Deleted [https://www.googleapis.com/compute/v1/projects/<projectID>/zones/us-west1-a/instances/gcpstudy].

削除できたっぽい、気を付けないと

-qオプションでインタラクティブな確認をyesでスキップできるらしいのでしてみる

gcloud compute instances delete gcp --zone=us-west1-a -q
Deleted [https://www.googleapis.com/compute/v1/projects/<projectID>/zones/us-west1-a/instances/gcp].

できたっぽいですね!
今日はここまで

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1