1. はじめに
概要
このラボでは、Network Connectivity Center(NCC)を使用して、VPC スポークと動的ルート交換をサポートすることで、オンプレミス接続を大規模に確立する方法について説明します。VPC を VPC スポークとして定義すると、NCC ハブを介して複数の VPC ネットワークに接続できます。ユーザーのオンプレミス ネットワークとのネットワーク接続を確立するには、ルーター アプライアンスの仮想 NIC、HA_VPN トンネル、または Interconnect VLAN アタッチメントを、NCC VPC スポークと同じ NCC ハブに接続します。
ハブリソースは、スポークを相互接続するための一元化された接続管理モデルを提供します。
作成するアプリの概要
この Codelab では、オンプレミス ネットワークとワークロード VPC 間のハイブリッド接続を実装する NCC ハブを使用して、論理的なハブアンドスポーク トポロジを構築します。
学習内容
- ワークロード VPC とルーティング VPC を区別する
- VPC スポークとハイブリッド スポークの NCC 統合
必要なもの
- GCP VPC ネットワークの知識
- Cloud Router と BGP ルーティングに関する知識
- Google Cloud プロジェクト
- [割り当て: ネットワーク] を確認し、必要に応じてネットワークを追加リクエストします(下のスクリーンショットをご覧ください)。
目標
- GCP 環境を設定する
- VPC をスポークとして使用して Network Connectivity Center を構成する
- HA-VPN トンネルをハイブリッド スポークとして使用するように Network Connectivity Center を構成する
- データパスを検証する
- NCC の保守性機能を確認する
- 使用済みリソースをクリーンアップする
始める前に
Google Cloud コンソールと Cloud Shell
このラボでは、GCP を操作するために、Google Cloud コンソールと Cloud Shell の両方を使用します。
NCC Hub プロジェクト Google Cloud コンソール
Cloud コンソールには、https://console.cloud.google.com からアクセスできます。
Google Cloud で次の項目を設定すると、ネットワーク接続センターを簡単に構成できます。
Google Cloud Console の [プロジェクト セレクタ] ページで、Google Cloud プロジェクトを選択または作成します。
Cloud Shell を起動します。この Codelab では、$variables を使用して、Cloud Shell での gcloud 構成の実装を支援します。
gcloud auth list
gcloud config list project
gcloud config set project [YOUR-PROJECT-NAME]
projectname=[YOUR-PROJECT-NAME]
echo $projectname
region="us-central1"
zone="us-central1-a"
IAM ロール
NCC では、特定の API にアクセスするために IAM ロールが必要です。必要に応じて、NCC IAM ロールを持つユーザーを構成してください。
役割/説明 | 権限 |
networkconnectivity.networkAdmin - ネットワーク管理者がハブとスポークを管理できるようにします。 | networkconnectivity.hubs.networkconnectivity.spokes. |
networkconnectivity.networkSpokeManager - ハブ内のスポークの追加と管理を可能にします。ホスト プロジェクトがハブを所有し、他のプロジェクトの他の管理者がハブへのアタッチメント用のスポークを追加できる共有 VPC で使用します。 | networkconnectivity.spokes.** |
networkconnectivity.networkUsernetworkconnectivity.networkViewer - ネットワーク ユーザーがハブとスポークのさまざまな属性を表示できるようにします。 | networkconnectivity.hubs.getnetworkconnectivity.hubs.listnetworkconnectivity.spokes.getnetworkconnectivity.spokes.listnetworkconnectivity.spokes.aggregatedList |
2. ネットワーク環境を設定する
概要
このセクションでは、3 つの VPC ネットワークとファイアウォール ルールを 1 つのプロジェクトにデプロイします。次の論理図は、この手順で設定するネットワーク環境を示しています。この Codelab では、VPC を使用してオンプレミス ネットワークをシミュレートします。
主なコンセプト 1
Google Cloud グローバル VPC は、44 を超える GCP リージョン間のデータパス接続を提供します。リージョン サービスである Cloud Router は、サブネットを動的にアドバタイズし、ルーターが構成されているリージョンまたは VPC ネットワーク全体で学習したルートを伝播します。ルートをリージョンまたはグローバルに伝播する Cloud Router は、動的ルーティング モード(リージョンまたはグローバル)を定義するユーザーによって異なります。
このセクションでは、まずリージョン ルーティング モードで各 VPC を構成します。この Codelab の残りの部分では、次のことを行います。
- [ルーティング VPC] は、NCC VPC スポークとして構成されていない VPC を示します。
- 「Workload VPC」は、NCC スポークとして構成された VPC を表します。
ワークロード VPC とサブネットを作成する
VPC ネットワークには、データパス検証用に GCE VM をインストールするサブネットが含まれています。
vpc_spoke_network_name="workload-vpc"
vpc_spoke_subnet_name="workload-subnet"
vpc_spoke_subnet_ip_range="10.0.1.0/24"
vpc_spoke_name="workload-vpc-spoke"
region="us-central1"
zone="us-central1-a"
gcloud compute networks create "${vpc_spoke_network_name}" \
--subnet-mode=custom
gcloud compute networks subnets create "${vpc_spoke_subnet_name}" \
--network="${vpc_spoke_network_name}" \
--range="${vpc_spoke_subnet_ip_range}" \
--region="${region}"
ルーティング VPC とサブネットを作成する
NCC は、プライベートで使用されるパブリック IP アドレスを除く、すべての有効な IPv4 サブネット範囲をサポートしています。
routing_vpc_network_name="routing-vpc"
routing_vpc_subnet_name="routing-vpc-subnet"
routing_vpc_subnet_range="10.0.2.0/24"
gcloud compute networks create "${routing_vpc_network_name}" \
--subnet-mode=custom
gcloud compute networks subnets create "${routing_vpc_subnet_name}" \
--region="${region}" \
--network="${routing_vpc_network_name}" \
--range="${routing_vpc_subnet_range}"
オンプレミス VPC とサブネットを作成する
NCC は、プライベートで使用されるパブリック IP アドレスを除く、すべての有効な IPv4 サブネット範囲をサポートしています。
on_prem_network_name="on-prem-net-vpc"
on_prem_subnet_name="on-prem-subnet"
on_prem_subnet_range="10.0.3.0/24"
gcloud compute networks create "${on_prem_network_name}" \
--subnet-mode=custom
gcloud compute networks subnets create "${on_prem_subnet_name}" \
--region="${region}" \
--network="${on_prem_network_name}" \
--range="${on_prem_subnet_range}"
ワークロード VPC ファイアウォール ルールを構成する
workload_vpc_firewall_name="workload-protocol-fw-vpc"
workload_port_firewall_name="workload-port-firewall-vpc"
gcloud compute firewall-rules create "${workload_vpc_firewall_name}" \
--network=${vpc_spoke_network_name} \
--allow="tcp,udp,icmp"
gcloud compute firewall-rules create "${workload_port_firewall_name}" \
--network=${vpc_spoke_network_name} \
--allow="tcp:22,tcp:3389,tcp:11180,icmp"
ルーティング VPC と VPC ファイアウォール ルールを構成する
routing_vpc_fw_name="routing-vpc-protocol-fw"
routing_vpc_port_fw_name="routing-vpc--port-fw"
gcloud compute firewall-rules create "${routing_vpc_fw_name}" \
--network=${routing_vpc_network_name} \
--allow="tcp,udp,icmp"
gcloud compute firewall-rules create "${routing_vpc_port_fw_name}" \
--network=${routing_vpc_network_name} \
--allow="tcp:22,tcp:3389,tcp:11180,icmp"
オンプレミス VPC と VPC ファイアウォール ルールを構成する
prem_protocol_fw_name="onprem-vpc-protocol-firewall"
prem_port_firewall_name="onprem-vpc-port-firewall-prem"
gcloud compute firewall-rules create "${prem_protocol_fw_name}" \
--network=${on_prem_network_name} \
--allow="tcp,udp,icmp"
gcloud compute firewall-rules create "${prem_port_firewall_name}" \
--network=${on_prem_network_name} \
--allow="tcp:22,tcp:3389,tcp:11180,icmp"
各 VPC で GCE VM を構成する
「vm1-vpc1-ncc」にパッケージをインストールするには、一時的にインターネットにアクセスする必要があります。
3 つの仮想マシンを作成し、各 VM を前に作成した VPC のいずれかに割り当てます。
gcloud compute instances create vm1-vpc-workload \
--zone us-central1-a \
--subnet="${vpc_spoke_subnet_name}" \
--metadata=startup-script='#!/bin/bash
apt-get update
apt-get install apache2 -y
apt-get install tcpdump -y
service apache2 restart
echo "
<h3>Web Server: www-vm1</h3>" | tee /var/www/html/index.html'
gcloud compute instances create vm2-vpc-routing \
--zone us-central1-a \
--subnet="${routing_vpc_subnet_name}" \
--no-address
gcloud compute instances create vm3-onprem \
--zone us-central1-a \
--subnet="${on_prem_subnet_name}" \
--no-address
3. ハイブリッド接続を設定する
このセクションでは、オンプレミスとルーティング VPC ネットワークを接続するように HA VPN トンネルを構成します。
ルーティング VPC で BGP を使用して Cloud Router を構成する
routing_vpc_router_name="routing-vpc-cr"
routing_vpc_router_asn=64525
gcloud compute routers create "${routing_vpc_router_name}" \
--region="${region}" \
--network="${routing_vpc_network_name}" \
--asn="${routing_vpc_router_asn}"
オンプレミス VPC で BGP を使用して Cloud Router を構成する
on_prem_router_name="on-prem-router"
on_prem_router_asn=64526
gcloud compute routers create "${on_prem_router_name}" \
--region="${region}" \
--network="${on_prem_network_name}" \
--asn="${on_prem_router_asn}"
ルーティング VPC で VPN ゲートウェイを構成する
routing_vpn_gateway_name="routing-vpc-vpn-gateway"
gcloud compute vpn-gateways create "${routing_vpn_gateway_name}" \
--region="${region}" \
--network="${routing_vpc_network_name}"
オンプレミス VPC で VPN ゲートウェイを構成する
on_prem_gateway_name="on-prem-vpn-gateway"
gcloud compute vpn-gateways create "${on_prem_gateway_name}" \
--region="${region}" \
--network="${on_prem_network_name}"
ルーティング VPC とオンプレミス VPC で VPN トンネルを構成する
secret_key=$(openssl rand -base64 24)
routing_vpc_tunnel_name="routing-vpc-tunnel"
on_prem_tunnel_name="on-prem-tunnel"
gcloud compute vpn-tunnels create "${routing_vpc_tunnel_name}" \
--vpn-gateway="${routing_vpn_gateway_name}" \
--peer-gcp-gateway="${on_prem_gateway_name}" \
--router="${routing_vpc_router_name}" \
--region="${region}" \
--interface=0 \
--shared-secret="${secret_key}"
gcloud compute vpn-tunnels create "${on_prem_tunnel_name}" \
--vpn-gateway="${on_prem_gateway_name}" \
--peer-gcp-gateway="${routing_vpn_gateway_name}" \
--router="${on_prem_router_name}" \
--region="${region}" \
--interface=0 \
--shared-secret="${secret_key}"
ルーティング VPC とオンプレミス クラウド ルーターを BGP ピアリングする BGP セッションを作成する
interface_hub_name="if-hub-to-prem"
hub_router_ip="169.254.1.1"
gcloud compute routers add-interface "${routing_vpc_router_name}" \
--interface-name="${interface_hub_name}" \
--ip-address="${hub_router_ip}" \
--mask-length=30 \
--vpn-tunnel="${routing_vpc_tunnel_name}" \
--region="${region}"
bgp_hub_name="bgp-hub-to-prem"
prem_router_ip="169.254.1.2"
gcloud compute routers add-bgp-peer "${routing_vpc_router_name}" \
--peer-name="${bgp_hub_name}" \
--peer-ip-address="${prem_router_ip}" \
--interface="${interface_hub_name}" \
--peer-asn="${on_prem_router_asn}" \
--region="${region}"
interface_prem_name="if-prem-to-hub"
gcloud compute routers add-interface "${on_prem_router_name}" \
--interface-name="${interface_prem_name}" \
--ip-address="${prem_router_ip}" \
--mask-length=30 \
--vpn-tunnel="${on_prem_tunnel_name}" \
--region="${region}"
bgp_prem_name="bgp-prem-to-hub"
gcloud compute routers add-bgp-peer "${on_prem_router_name}" \
--peer-name="${bgp_prem_name}" \
--peer-ip-address="${hub_router_ip}" \
--interface="${interface_prem_name}" \
--peer-asn="${routing_vpc_router_asn}" \
--region="${region}"
デフォルトでは、NCC ハブのサブネットはハイブリッド スポークにアドバタイズされません。次のステップでは、オンプレミス ネットワークに NCC サブネット ルートを通知するように Cloud Router を構成します。
VPC スポーク サブネットをオンプレミス クラウド ルーターにアドバタイズする
gcloud compute routers update "${routing_vpc_router_name}" \
--advertisement-mode custom \
--set-advertisement-groups=all_subnets \
--set-advertisement-ranges="${vpc_spoke_subnet_ip_range}" \
--region="${region}"
オンプレミス サブネットをルーティング VPC Cloud Router にアドバタイズする
gcloud compute routers update "${on_prem_router_name}" \
--advertisement-mode custom \
--set-advertisement-groups=all_subnets \
--region="${region}"
MED 値が「111」のプレフィックスをアドバタイズするように、オンプレミス クラウド ルーターの BGP ピアリング構成を更新します。後のセクションでは、BGP Med 値を使用した NCC の動作を確認します。
on_prem_router_name="on-prem-router"
bgp_prem_name="bgp-prem-to-hub"
gcloud compute routers update-bgp-peer "${on_prem_router_name}" \
--peer-name="${bgp_prem_name}" \
--advertised-route-priority="111" \
--region="${region}"
ルーティング VPC トンネルのステータスを確認する
gcloud compute vpn-tunnels describe routing-vpc-tunnel \
--region=us-central1 \
--format='flattened(status,detailedStatus)'
ルーティング VPC Cloud Router のステータスを確認する
gcloud コマンドを使用して、ルーティング VPC Cloud Router の BGP 学習ルートを一覧表示します。
gcloud compute routers get-status routing-vpc-cr \
--region=us-central1
4. Network Connectivity Center ハブ
概要
このセクションでは、gcloud コマンドを使用して NCC Hub を構成します。NCC ハブは、各 VPC スポーク間のルーティング構成の構築を担当するコントロール プレーンとして機能します。
API サービスを有効にする
ネットワーク接続 API がまだ有効になっていない場合は、有効にします。
gcloud services enable networkconnectivity.googleapis.com
NCC ハブを作成する
gCloud コマンドを使用して NCC ハブを作成する
hub_name="mesh-hub"
gcloud network-connectivity hubs create "${hub_name}"
出力例
Create request issued for: [mesh-hub]
Waiting for operation [projects/ncc/locations/global/operations/operation-1719930559145-61c448a0426e4-2d18c8dd-7107edbe] to complete...done.
Created hub [mesh-hub].
新しく作成した NCC ハブを記述します。名前と関連付けられたパスをメモします。
gcloud network-connectivity hubs describe mesh-hub
createTime: '2024-07-02T14:29:19.260054897Z'
exportPsc: false
name: projects/ncc/locations/global/hubs/mesh-hub
policyMode: PRESET
presetTopology: MESH
routeTables:
- projects/ncc/locations/global/hubs/mesh-hub/routeTables/default
state: ACTIVE
uniqueId: 08f9ae88-f76f-432b-92b2-357a85fc83aa
updateTime: '2024-07-02T14:29:32.583206925Z'
NCC Hub では、データ接続の作成に使用するコントロール プレーンを定義するルーティング テーブルが導入されました。NCC ハブのルーティング テーブルの名前を確認する
gcloud network-connectivity hubs route-tables list --hub=mesh-hub
NAME HUB DESCRIPTION
default mesh-hub
NCC デフォルトのルートテーブルの URI を確認します。
gcloud network-connectivity hubs route-tables describe default --hub=mesh-hub
createTime: '2024-07-02T14:29:22.340190411Z'
name: projects/ncc/locations/global/hubs/mesh-hub/routeTables/default
state: ACTIVE
uid: fa2af78b-d416-41aa-b442-b8ebdf84f799
NCC Hub のデフォルトのルーティング テーブルの内容を一覧表示します。注* NCC ハイブリッド スポークまたは VPC スポークが定義されるまで、NCC ハブのルート テーブルは空になります。
gcloud network-connectivity hubs route-tables routes list --hub=mesh-hub --route_table=default
NCC ハブのルート テーブルは空にする必要があります。
5. ハイブリッド スポークと VPC スポークを使用した NCC
概要
このセクションでは、gCloud コマンドを使用して 2 つの NCC スポークを構成します。1 つのスポークは VPC スポークで、もう 1 つのスポークはハイブリッド(VPN)スポークになります。
ワークロード VPC を NCC スポークとして構成する
ワークロード VPC を NCC スポークとして構成し、前に作成した NCC ハブに割り当てます。NCC スポーク API 呼び出しでは、位置情報を指定する必要があります。フラグ「–global」を使用すると、新しい NCC スポークを構成するときに URI パス全体を指定する必要がなくなります。
vpc_spoke_name="workload-vpc-spoke"
vpc_spoke_network_name="workload-vpc"
gcloud network-connectivity spokes linked-vpc-network create "${vpc_spoke_name}" \
--hub="${hub_name}" \
--vpc-network="${vpc_spoke_network_name}" \
--global
Create request issued for: [workload-vpc-spoke]
Waiting for operation [projects/ncc/locations/global/operations/operation-1719931097138-61c44aa15463f-90de22c7-40c10e6b] to complete...done.
Created spoke [workload-vpc-spoke].
createTime: '2024-07-02T14:38:17.315200822Z'
group: projects/ncc/locations/global/hubs/mesh-hub/groups/default
hub: projects/ncc/locations/global/hubs/mesh-hub
linkedVpcNetwork:
uri: https://www.googleapis.com/compute/v1/projects/ncc/global/networks/workload-vpc
name: projects/ncc/locations/global/spokes/workload-vpc-spoke
spokeType: VPC_NETWORK
state: ACTIVE
uniqueId: 33e50612-9b62-4ec7-be6c-962077fd47dc
updateTime: '2024-07-02T14:38:44.196850231Z'
ルーティング VPC で VPN トンネルをハイブリッド スポークとして構成する
この gcloud コマンドを使用して、VPN トンネルをハイブリッド スポークとして構成し、メッシュハブに参加します。
vpn_spoke_name="hybrid-spoke"
routing_vpc_tunnel_name="routing-vpc-tunnel"
region="us-central1"
hub_name="mesh-hub"
gcloud network-connectivity spokes linked-vpn-tunnels create "${vpn_spoke_name}" \
--region="${region}" \
--hub="${hub_name}" \
--vpn-tunnels="${routing_vpc_tunnel_name}"
出力例:
Create request issued for: [hybrid-spoke]
Waiting for operation [projects/ncc/locations/us-central1/operations/operation-1719932916561-61c45168774be-0a06ae03-88192175] to complete...done.
Created spoke [hybrid-spoke].
メッシュハブのスポークの構成を確認する
gcloud コマンドを使用して、NCC Hub のデフォルトのルーティング テーブルの内容を一覧表示します。
gcloud network-connectivity hubs list-spokes mesh-hub
メッシュハブのデフォルトのルーティング テーブルを分析する
gcloud コマンドを使用して、NCC Hub のデフォルトのルーティング テーブルの内容を一覧表示します。
gcloud network-connectivity hubs route-tables routes list --hub=mesh-hub \
--route_table=default
NCC ハイブリッド スポークで動的ルート交換を使用する場合、BGP MED 値を持つ Cloud Router が学習したプレフィックスは NCC スポーク間で伝播されます。
gcloud コマンドを使用して、優先度値「111」を表示します。
gcloud network-connectivity hubs route-tables routes list \
--hub=mesh-hub \
--route_table=default \
--effective-location=us-central1 \
--filter=10.0.3.0/24
6. データパスを確認する
この手順では、NCC ハイブリッドと VPC スポーク間のデータパスを検証します。
これらの gcloud コマンドの出力を使用して、オンプレミス VM にログオンします。
gcloud compute instances list --filter="name=vm3-onprem"
オンプレミス ネットワークに存在する VM インスタンスにログオンします。
gcloud compute ssh vm3-onprem --zone=us-central1-a
vm3-onprem のターミナルで、curl コマンドを使用して、workload-vpc でホストされている VM へのウェブ セッションを確立します。
curl 10.0.1.2 -v
* Trying 10.0.1.2:80...
* Connected to 10.0.1.2 (10.0.1.2) port 80 (#0)
> GET / HTTP/1.1
> Host: 10.0.1.2
> User-Agent: curl/7.74.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Wed, 03 Jul 2024 15:41:34 GMT
< Server: Apache/2.4.59 (Debian)
< Last-Modified: Mon, 01 Jul 2024 20:36:16 GMT
< ETag: "1e-61c358c8272ba"
< Accept-Ranges: bytes
< Content-Length: 30
< Content-Type: text/html
<
<h3>Web Server: www-vm1</h3>
* Connection #0 to host 10.0.1.2 left intact
7. クリーンアップ
Cloud Shell にログインして、GCP リソースを削除します。
NCC スポークを削除する
gcloud network-connectivity spokes delete workload-vpc-spoke --global \
--quiet
gcloud network-connectivity spokes delete hybrid-spoke \
--quiet \
--region us-central1
NCC ハブを削除する
gcloud network-connectivity hubs delete mesh-hub --quiet
ファイアウォール ルールを削除する
gcloud compute firewall-rules delete onprem-vpc-port-firewall-prem onprem-vpc-protocol-firewall routing-vpc--port-fw routing-vpc-protocol-fw workload-port-firewall-vpc workload-protocol-fw-vpc --quiet
HA-VPN トンネルを削除する
gcloud compute vpn-tunnels delete on-prem-tunnel \
--region=us-central1 \
--quiet
gcloud compute vpn-tunnels delete routing-vpc-tunnel \
--region=us-central1 \
--quiet
VPN ゲートウェイを削除する
gcloud compute vpn-gateways delete on-prem-vpn-gateway \
--region=us-central1 --quiet
gcloud compute vpn-gateways delete routing-vpc-vpn-gateway \
--region us-central1 --quiet
Cloud Router を削除する
gcloud compute routers delete routing-vpc-cr --region us-central1 --quiet
gcloud compute routers delete on-prem-router --region us-central1 --quiet
GCE インスタンスを削除する
gcloud compute instances delete vm1-vpc-workload \
--zone=us-central1-a \
--quiet
gcloud compute instances delete vm2-vpc-routing \
--zone=us-central1-a \
--quiet
gcloud compute instances delete vm3-onprem \
--zone=us-central1-a \
--quiet
VPC サブネットを削除する
gcloud compute networks subnets delete workload-subnet --region us-central1 --quiet
gcloud compute networks subnets delete on-prem-subnet --region us-central1 --quiet
gcloud compute networks subnets delete routing-vpc-subnet --region us-central1 --quiet
VPC を削除する
gcloud compute networks delete on-prem-net-vpcworkload-vpc routing-vpc
--quiet
8. 完了
動的ルート交換 Network Connectivity Center ラボが完了しました。
学習した内容
- Network Connectivity Center を使用した動的ルート交換
次のステップ
©Google, LLC or its affiliates. All rights reserved. Do not distribute.