6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GCPチュートリアル試行「VPCの作成や削除」

Last updated at Posted at 2018-08-09

お題

表題のチュートリアルを試しにやってみる。

【参照】
https://cloud.google.com/vpc/docs/using-vpc?authuser=1&hl=ja

前提

  • GCP環境は保持済み。
  • gcloudコマンドインストール済み。

Virtual Private Cloud(VPC)

  • VPCネットワークには、「自動モード」と「カスタムモード」がある。
  • 1プロジェクトにつき、5ネットワークまで作れる。(※デフォルトも含め)
  • ネットワークモードを自動からカスタムに切り替えられる。(一方向のみ)
  • サブネットの IP 範囲を拡張できる。縮小はできない。

自動モードのVPCネットワーク作成


$ gcloud compute networks create auto-network1 --subnet-mode auto

Created [https://www.googleapis.com/compute/v1/projects/XXXXXXXX/global/networks/auto-network1].
NAME           SUBNET_MODE  BGP_ROUTING_MODE  IPV4_RANGE  GATEWAY_IPV4
auto-network1  AUTO         REGIONAL

Instances on this network will not be reachable until firewall rules
are created. As an example, you can allow all internal traffic between
instances as well as SSH, RDP, and ICMP by running:

$ gcloud compute firewall-rules create  --network auto-network1 --allow tcp,udp,icmp --source-ranges 
$ gcloud compute firewall-rules create  --network auto-network1 --allow tcp:22,tcp:3389,icmp

作成結果

リージョン毎にサブネットが1つずつ作られる。
vpc01.png

アジアリージョンの詳細

vpc02.png

カスタムサブネットを使用してVPCネットワーク作成


$ gcloud compute networks create custom-network1 --subnet-mode custom

Created [https://www.googleapis.com/compute/v1/projects/XXXXXXXX/global/networks/custom-network1].
NAME             SUBNET_MODE  BGP_ROUTING_MODE  IPV4_RANGE  GATEWAY_IPV4
custom-network1  CUSTOM       REGIONAL

Instances on this network will not be reachable until firewall rules
are created. As an example, you can allow all internal traffic between
instances as well as SSH, RDP, and ICMP by running:

$ gcloud compute firewall-rules create  --network custom-network1 --allow tcp,udp,icmp --source-ranges 
$ gcloud compute firewall-rules create  --network custom-network1 --allow tcp:22,tcp:3389,icmp

作成結果

カスタムの場合はサブネットは勝手に作られない。
vpc03.png

カスタムサブネットのリージョン3つに対してサブネット作成


$ gcloud compute networks subnets create subnets-us-central-192 --network custom-network1 --region us-central1 --range 192.168.1.0/24
$ gcloud compute networks subnets create subnets-europe-west-192 --network custom-network1 --region europe-west1 --range 192.168.5.0/24
$ gcloud compute networks subnets create subnets-asia-east-192 --network custom-network1 --region asia-east1 --range 192.168.7.0/24

Created [https://www.googleapis.com/compute/v1/projects/XXXXXXXX/regions/us-central1/subnetworks/subnets-us-central-192].
NAME                    REGION       NETWORK          RANGE
subnets-us-central-192  us-central1  custom-network1  192.168.1.0/24

Created [https://www.googleapis.com/compute/v1/projects/XXXXXXXX/regions/europe-west1/subnetworks/subnets-europe-west-192].
NAME                     REGION        NETWORK          RANGE
subnets-europe-west-192  europe-west1  custom-network1  192.168.5.0/24

Created [https://www.googleapis.com/compute/v1/projects/XXXXXXXX/regions/asia-east1/subnetworks/subnets-asia-east-192].
NAME                   REGION      NETWORK          RANGE
subnets-asia-east-192  asia-east1  custom-network1  192.168.7.0/24

作成結果確認


$ gcloud compute networks subnets list | grep custom-network1
subnets-asia-east-192    asia-east1               custom-network1  192.168.7.0/24
subnets-europe-west-192  europe-west1             custom-network1  192.168.5.0/24
subnets-us-central-192   us-central1              custom-network1  192.168.1.0/24

$ gcloud compute networks subnets describe subnets-asia-east-192 --region asia-east1
creationTimestamp: '2018-08-09T08:36:58.521-07:00'
fingerprint: XXX-XXXXXXXX
gatewayAddress: 192.168.7.1
id: '1111111111111111111'
ipCidrRange: 192.168.7.0/24
kind: compute#subnetwork
name: subnets-asia-east-192
network: https://www.googleapis.com/compute/v1/projects/XXXXXXXX/global/networks/custom-network1
privateIpGoogleAccess: false
region: https://www.googleapis.com/compute/v1/projects/XXXXXXXX/regions/asia-east1
selfLink: https://www.googleapis.com/compute/v1/projects/XXXXXXXX/regions/asia-east1/subnetworks/subnets-asia-east-192

作成したリージョン毎にサブネットが1つずつ作られる。
vpc04.png

US中央リージョンの詳細

vpc05.png

カスタムサブネットを削除

自動的に作成されたサブネットは個別に削除できない。削除するにはVPCネットワーク全体の削除が必要。


$ gcloud compute networks subnets delete subnets-asia-east-192 --region asia-east1

The following subnetworks will be deleted:
 - [subnets-asia-east-192] in [asia-east1]

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

Deleted [https://www.googleapis.com/compute/v1/projects/XXXXXXXX/regions/asia-east1/subnetworks/subnets-asia-east-192].

削除結果

vpc06.png

VPCネットワークを削除


$ gcloud compute networks delete auto-network1

The following networks will be deleted:
 - [auto-network1]

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

Deleted [https://www.googleapis.com/compute/v1/projects/XXXXXXXX/global/networks/auto-network1].
6
6
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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?