1. はじめに
Private Service Connect(PSC)ネットワーク エンドポイント グループ(NEG)は、内部 HTTPS ロードバランサと外部 HTTPS ロードバランサのチェーンをサポートしています。これにより、顧客が定義した範囲を使用して、分散ヘルスチェックとデータプレーン トラフィックがオンプレミスに提供されます。また、このトポロジでは、複数のリージョン InterConnect を介してオンプレミスに接続する複数の VPC もサポートされています。
この Codelab では、次のトポロジに基づいてこのエンドツーエンドを構成する方法について説明します。左から右に、オンプレミスの顧客は HTTP サービスをシミュレートする VM を持ち、ハイブリッド接続(HA-VPN または InterConnect)とハイブリッド NEG を活用して、内部 HTTPS ロードバランサ経由で公開します。PSC は、サービス アタッチメントとして内部 HTTPS LB を使用します。PSC NEG は、アタッチメントをバックエンド サービスとして使用し、外部 HTTPS LB に公開します。インターネット ユーザーは、Google グローバル ネットワークを使用して、オンプレミス HTTP サービスへのアクセスを高速化できます。

図 1. Private Service Connect は、ネットワーク エンドポイント グループとサービス アタッチメントを使用して、外部 HTTPS ロードバランサを内部 HTTPS ロードバランサに接続し、バックエンドをオンプレミスに拡張します。
学習内容
- ハイブリッド NEG と分散ヘルスチェックを使用する内部 HTTPS ロードバランサ
- 内部 HTTPS ロードバランサを使用した PSC サービス アタッチメント
- PSC ネットワーク エンドポイント グループの設定
- 外部 HTTPS ロードバランサで PSC NEG を公開する
必要なもの
- HA-VPN などのハイブリッド接続に関する知識
- 内部/外部 HTTPS ロード バランシングの知識
- Private Service Connect の知識
2. 始める前に
注: この Codelab では、図示されたトポロジに基づく構成と検証の手順が提供されています。組織の要件に合わせて必要に応じて手順を変更してください。IAM 権限は、この Codelab の範囲外です。
この Codelab では、1 つのプロジェクトを使用してプロセス全体をシミュレートします。複数のプロジェクトもサポートされています。
単一プロジェクト - プロデューサー ネットワークとコンシューマー ネットワークをサポートするようにプロジェクトを更新
Cloud Shell で、プロジェクト ID が設定されていることを確認します。
gcloud config list project gcloud config set project [YOUR-PROJECT-NAME] prodproject=YOUR-PROJECT-NAME echo $prodproject
3. オンプレミス リソースを作成する
次のセクションでは、お客様のオンプレミス サービスをシミュレートするために、オンプレミス VPC と VM を設定します。
VPC ネットワーク
Cloud Shell から
gcloud compute networks create vpc-demo-onprem --project=$prodproject --subnet-mode=custom
サブネットの作成
Cloud Shell から
gcloud compute networks subnets create vpc-demo-onprem-asia-southeast1 --project=$prodproject --range=10.0.0.0/24 --network=vpc-demo-onprem --region=asia-southeast1
ファイアウォール ルールを作成します。
内部 HTTPS ロードバランサは分散ヘルスチェックをサポートしているため、ファイアウォール ルールでプロキシ サブネットの IP 範囲のみを許可する必要があります。ドキュメントに沿って、プロジェクトを許可リストに登録します。
Cloud Shell で、プロキシ サブネットからのバックエンド ヘルスチェックとデータプレーン トラフィックを有効にするファイアウォール ルールを作成します。
gcloud compute firewall-rules create vpc-demo-health-checks --allow tcp:80,tcp:443 --network vpc-demo-onprem --source-ranges 10.0.3.0/24 --enable-logging
Cloud Shell で、IAP が VM インスタンスに接続できるようにするファイアウォール ルールを作成します。
gcloud compute firewall-rules create psclab-iap-prod --network vpc-demo-onprem --allow tcp:22 --source-ranges=35.235.240.0/20 --enable-logging
4. オンプレミス VM インスタンスを作成する
この VM はオンプレミス サービスをシミュレートし、ハイブリッド NEG を使用して内部 HTTPS ロードバランサで公開する必要があります。
Cloud Shell からインスタンス www01 を作成する
gcloud compute instances create www01 \
--zone=asia-southeast1-b \
--image-family=debian-11 \
--image-project=debian-cloud \
--network-interface=network-tier=PREMIUM,nic-type=GVNIC,stack-type=IPV4_ONLY,subnet=vpc-demo-onprem-asia-southeast1 \
--shielded-secure-boot \
--shielded-vtpm \
--shielded-integrity-monitoring \
--metadata=startup-script='#! /bin/bash
sudo apt-get update
sudo apt-get install nginx -y
vm_hostname="$(curl -H "Metadata-Flavor:Google" \
http://169.254.169.254/computeMetadata/v1/instance/name)"
filter="{print \$NF}"
vm_zone="$(curl -H "Metadata-Flavor:Google" \
http://169.254.169.254/computeMetadata/v1/instance/zone \
| awk -F/ "${filter}")"
echo "Page on $vm_hostname in $vm_zone" | \
tee /var/www/html/index.nginx-debian.html
sudo systemctl restart nginx'
次のセクションでは、letsencrypt を使用して証明書を生成し、Nginx にインストールします。次の手順のために、公開鍵ファイルと秘密鍵ファイルをダウンロードします。証明書を生成するには、TCP ポート 80 を一時的にインターネットに開く必要があります。
この VM に公開解決済みのドメイン名があることを確認します。たとえば、Cloud DNS で A レコード [www01.yinghli.demo.altostrat.com](http://www01.yinghli.demo.altostrat.com) を追加し、VM のパブリック IP アドレスを指すようにします。
gcloud dns --project=$prodproject record-sets create www01.yinghli.demo.altostrat.com. --zone="yinghli-demo" --type="A" --ttl="300" --rrdatas="34.87.77.186"
VM www01 コンソールで、ガイダンスに沿って Nginx に証明書をインストールし、次の手順のために fullchain.pem と private.pem のコピーを作成します。
sudo apt install snapd sudo snap install core; sudo snap refresh core sudo snap install --classic certbot sudo ln -s /snap/bin/certbot /usr/bin/certbot sudo certbot --nginx
5. プロデューサー VPC ネットワークを作成する
注: ハイブリッド ネットワーキング構成はこの構成に含まれません。
VPC ネットワーク
Cloud Shell から
gcloud compute networks create vpc-demo-producer --project=$prodproject --subnet-mode=custom
サブネットの作成
Cloud Shell から
gcloud compute networks subnets create vpc-demo-asia-southeast1 --project=$prodproject --range=10.0.2.0/24 --network=vpc-demo-producer --region=asia-southeast1
プロキシ サブネットを作成する
Cloud Shell から
gcloud compute networks subnets create proxy-subnet-asia-southeast1 \ --purpose=REGIONAL_MANAGED_PROXY \ --role=ACTIVE \ --region=asia-southeast1 \ --network=vpc-demo-producer \ --range=10.0.3.0/24
ハイブリッド接続
Cloud VPN のドキュメントに沿って、オンプレミスとプロデューサー VPC 間の HA-VPN 接続を実装します。Cloud Router のデフォルト構成を維持します。130.211.0.0/22、35.191.0.0/16 を BGP アドバタイズに追加する必要はありません。
6. プロデューサー ハイブリッド NEG を作成する
ハイブリッド ネットワーク エンドポイント グループを作成し、オンプレミス VM の IP:PORT を NEG に追加します。
Cloud Shell から
gcloud compute network-endpoint-groups create on-prem-service-neg \
--network-endpoint-type=NON_GCP_PRIVATE_IP_PORT \
--zone=asia-southeast1-b \
--network=vpc-demo-producer
gcloud compute network-endpoint-groups update on-prem-service-neg \
--zone=asia-southeast1-b \
--add-endpoint="ip=10.0.0.2,port=443"
7. プロデューサーの内部 HTTPS ロードバランサを作成する
現在、外部 HTTPS ロードバランサは PSC NEG への HTTPS プロトコルのみをサポートしています(ドキュメント)。公開サービスの場合、内部 HTTPS ロードバランサを使用し、転送ルールのグローバル アクセスを有効にする必要があります。
Cloud Shell からリージョン ヘルスチェックを作成します。
gcloud compute health-checks create https on-prem-service-hc \
--region=asia-southeast1 \
--use-serving-port
Cloud Shell からバックエンド サービスを作成し、ハイブリッド NEG を追加します。
gcloud compute backend-services create on-premise-service-backend \ --load-balancing-scheme=INTERNAL_MANAGED \ --protocol=HTTPS \ --region=asia-southeast1 \ --health-checks=on-prem-service-hc \ --health-checks-region=asia-southeast1 gcloud compute backend-services add-backend on-premise-service-backend \ --network-endpoint-group=on-prem-service-neg \ --network-endpoint-group-zone=asia-southeast1-b \ --region=asia-southeast1 \ --balancing-mode=RATE \ --max-rate-per-endpoint=100
Cloud Shell から URL マップを作成する
gcloud compute url-maps create on-premise-url \
--default-service on-premise-service-backend \
--region=asia-southeast1
Cloud Shell からリージョン SSL 証明書を作成します。VM から 2 つの証明書ファイルがダウンロードされます。
gcloud compute ssl-certificates create www01 \
--certificate=fullchain.pem \
--private-key=private.pem \
--region=asia-southeast1
Cloud Shell から https-target-proxy を作成する
gcloud compute target-https-proxies create on-premise-httpsproxy \
--ssl-certificates=www01 \
--url-map=on-premise-url \
--url-map-region=asia-southeast1 \
--region=asia-southeast1
Cloud Shell から内部静的 IP を予約し、転送ルールを作成します。
gcloud compute addresses create ilbaddress \
--region=asia-southeast1 \
--subnet=vpc-demo-asia-southeast1 \
--addresses=10.0.2.100
gcloud compute forwarding-rules create https-ilb-psc \
--load-balancing-scheme=INTERNAL_MANAGED \
--network=vpc-demo-producer \
--subnet=vpc-demo-asia-southeast1 \
--address=ilbaddress \
--ports=443 \
--region=asia-southeast1 \
--target-https-proxy=on-premise-httpsproxy \
--target-https-proxy-region=asia-southeast1
--allow-global-access
8. プロデューサー VM インスタンスを作成する
検証用のプロデューサー VM を作成します。
Cloud Shell から
gcloud compute instances create test01 \
--zone=asia-southeast1-b \
--image-family=debian-11 \
--image-project=debian-cloud \
--network-interface=network-tier=PREMIUM,nic-type=GVNIC,stack-type=IPV4_ONLY,subnet=vpc-demo-asia-southeast1 \
--shielded-secure-boot \
--shielded-vtpm \
--shielded-integrity-monitoring
IAP に VM インスタンスへの接続を許可するには、次のファイアウォール ルールを作成します。
Cloud Shell から
gcloud compute firewall-rules create psclab-iap-prod --network vpc-demo-producer --allow tcp:22 --source-ranges=35.235.240.0/20 --enable-logging
プロデューサー VM コンソールから [www01.yinghli.demo.altostrat.com](https://www01.yinghli.demo.altostrat.com) にアクセスし、内部 HTTPS ロードバランサの IP アドレスを解決します。HTTP 200 は、構成が想定どおりに動作したことを示しています。
curl -v --resolve www01.yinghli.demo.altostrat.com:443:10.0.2.100 https://www01.yinghli.demo.altostrat.com * Added www01.yinghli.demo.altostrat.com:443:10.0.2.100 to DNS cache * Hostname www01.yinghli.demo.altostrat.com was found in DNS cache * Trying 10.0.2.100:443... * Connected to www01.yinghli.demo.altostrat.com (10.0.2.100) port 443 (#0) * ALPN, offering h2 * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /etc/ssl/certs/ca-certificates.crt * CApath: /etc/ssl/certs * TLSv1.3 (OUT), TLS handshake, Client hello (1): * TLSv1.3 (IN), TLS handshake, Server hello (2): * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8): * TLSv1.3 (IN), TLS handshake, Certificate (11): * TLSv1.3 (IN), TLS handshake, CERT verify (15): * TLSv1.3 (IN), TLS handshake, Finished (20): * TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1): * TLSv1.3 (OUT), TLS handshake, Finished (20): * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 * ALPN, server accepted to use h2 * Server certificate: * subject: CN=www01.yinghli.demo.altostrat.com * start date: Jun 4 10:36:43 2023 GMT * expire date: Sep 2 10:36:42 2023 GMT * subjectAltName: host "www01.yinghli.demo.altostrat.com" matched cert's "www01.yinghli.demo.altostrat.com" * issuer: C=US; O=Let's Encrypt; CN=R3 * SSL certificate verify ok. * Using HTTP2, server supports multi-use * Connection state changed (HTTP/2 confirmed) * Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0 * Using Stream ID: 1 (easy handle 0x55865ef982e0) > GET / HTTP/2 > Host: www01.yinghli.demo.altostrat.com > user-agent: curl/7.74.0 > accept: */* > * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4): * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4): * old SSL session ID is stale, removing * Connection state changed (MAX_CONCURRENT_STREAMS == 100)! < HTTP/2 200 < server: nginx/1.18.0 < date: Mon, 05 Jun 2023 02:29:38 GMT < content-type: text/html < content-length: 35 < last-modified: Sun, 04 Jun 2023 09:02:16 GMT < etag: "647c5318-23" < accept-ranges: bytes < via: 1.1 google < Page on www01 in asia-southeast1-b * Connection #0 to host www01.yinghli.demo.altostrat.com left intact
注: オンプレミス ファイアウォールではプロキシ サブネット 10.0.3.0/24 のアクセスのみが許可されているため、VM 10.0.0.2 の HTTPS サービスに直接アクセスすることはできません。
9. PSC NAT サブネットを作成する
Cloud Shell から
gcloud compute networks subnets create psc-nat-subnet \ --network=vpc-demo-producer \ --region=asia-southeast1 \ --range=10.0.5.0/24 \ --purpose=private-service-connect
10. HTTPS サービス アタッチメントを作成する
Cloud Shell から HTTPS サービス アタッチメントを作成する
gcloud compute service-attachments create ilbserviceattach \ --region=asia-southeast1 \ --producer-forwarding-rule=https-ilb-psc \ --connection-preference=ACCEPT_AUTOMATIC \ --nat-subnets=psc-nat-subnet
HTTPS サービス アタッチメントを検証する
gcloud compute service-attachments describe ilbserviceattach --region asia-southeast1
サービス アタッチメント名を記録します。
projects/<project>/regions/asia-southeast1/serviceAttachments/ilbserviceattach
11. コンシューマー VPC ネットワークを作成する
次のセクションでは、コンシューマー VPC は同じプロジェクトで構成されていますが、別のプロジェクトもサポートされています。コンシューマー ネットワークとプロデューサー ネットワークの間の通信は、プロデューサー ネットワークで定義されたサービス アタッチメントを通じて行われます。
VPC ネットワーク
Cloud Shell から
gcloud compute networks create vpc-demo-consumer --project=$prodproject --subnet-mode=custom
サブネットの作成
Cloud Shell から
gcloud compute networks subnets create consumer-subnet --project=$prodproject --range=10.0.6.0/24 --network=vpc-demo-consumer --region=asia-southeast1
12. PSC ネットワーク エンドポイント グループを作成する
PSC NEG を作成する
以前の https サービス アタッチメント名をコピーして、パラメータ --psc-target-service に貼り付けます。
Cloud Shell から
gcloud beta compute network-endpoint-groups create consumerpscneg \ --project=$prodproject \ --region=asia-southeast1 \ --network-endpoint-type=PRIVATE_SERVICE_CONNECT \ --psc-target-service=projects/<project>/regions/asia-southeast1/serviceAttachments/ilbserviceattach \ --network=vpc-demo-consumer \ --subnet=consumer-subnet
PSC NEG の設定が正常に完了したら、UI で Private Service Connect -> Published Services の順に選択します。公開された ilbserviceattach 接続に 1 つの転送ルールが示されていることを確認します。

13. コンシューマー外部 HTTPS ロードバランサを作成する
外部 HTTPS ロードバランサを作成し、PSC NEG をバックエンド サービスとして使用します(ドキュメント)。
Cloud Shell から
gcloud compute addresses create httpspsclb \
--ip-version=IPV4 --global
gcloud compute backend-services create consumer-bs \
--load-balancing-scheme=EXTERNAL_MANAGED \
--protocol=HTTPS \
--global
gcloud compute backend-services add-backend consumer-bs \
--network-endpoint-group=consumerpscneg \
--network-endpoint-group-region=asia-southeast1 \
--global
gcloud compute url-maps create consumer-url \
--default-service=consumer-backend-service \
--global
gcloud compute ssl-certificates create wwwglobal \
--certificate=fullchain.pem \
--private-key=private.pem \
--global
gcloud compute target-https-proxies create consumer-url-target-proxy \
--url-map=consumer-url \
--ssl-certificates=wwwglobal
gcloud compute forwarding-rules create consumer-url-forwarding-rule \
--load-balancing-scheme=EXTERNAL_MANAGED \
--network-tier=PREMIUM \
--address=httpspsclb \
--target-https-proxy=consumer-url-target-proxy \
--ports=443 \
--global
www01.yinghli.demo.altostrat.com の DNS レコードを更新して、外部 HTTPS ロードバランサのパブリック IP アドレスを指すようにする
gcloud dns --project=$prodproject record-sets update www01.yinghli.demo.altostrat.com. --type="A" --zone="yinghli-demo" --rrdatas="34.102.178.214" --ttl="300"
14. 検証
ノートパソコンから、curl を使用して https://www01.yinghli.demo.altostrat.com にアクセスします。
curl -v https://www01.yinghli.demo.altostrat.com * Trying 34.102.178.214:443... * Connected to www01.yinghli.demo.altostrat.com (34.102.178.214) port 443 (#0) * ALPN: offers h2,http/1.1 * TLSv1.3 (OUT), TLS handshake, Client hello (1): * TLSv1.3 (IN), TLS handshake, Server hello (2): * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8): * TLSv1.3 (IN), TLS handshake, Certificate (11): * TLSv1.3 (IN), TLS handshake, CERT verify (15): * TLSv1.3 (IN), TLS handshake, Finished (20): * TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1): * TLSv1.3 (OUT), TLS handshake, Finished (20): * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 * ALPN: server accepted h2 * Server certificate: * subject: CN=www01.yinghli.demo.altostrat.com * start date: Jun 4 10:36:43 2023 GMT * expire date: Sep 2 10:36:42 2023 GMT * subjectAltName: host "www01.yinghli.demo.altostrat.com" matched cert's "www01.yinghli.demo.altostrat.com" * issuer: C=US; O=Let's Encrypt; CN=R3 * SSL certificate verify ok. * using HTTP/2 * h2h3 [:method: GET] * h2h3 [:path: /] * h2h3 [:scheme: https] * h2h3 [:authority: www01.yinghli.demo.altostrat.com] * h2h3 [user-agent: curl/8.0.0] * h2h3 [accept: */*] * Using Stream ID: 1 (easy handle 0x149019a00) > GET / HTTP/2 > Host: www01.yinghli.demo.altostrat.com > user-agent: curl/8.0.0 > accept: */* > * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4): * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4): * old SSL session ID is stale, removing < HTTP/2 200 < server: nginx/1.18.0 < date: Mon, 05 Jun 2023 02:48:43 GMT < content-type: text/html < content-length: 35 < last-modified: Sun, 04 Jun 2023 09:02:16 GMT < etag: "647c5318-23" < accept-ranges: bytes < via: 1.1 google, 1.1 google < alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000 < Page on www01 in asia-southeast1-b * Connection #0 to host www01.yinghli.demo.altostrat.com left intact
15. クリーンアップ手順
プロデューサー ネットワークのクリーンアップ手順
注: クリーンアップ手順には、ロードバランサと PSC 関連の構成のみが示されています。VPC とハイブリッド接続は含まれていません。
ターミナルの単一の Cloud Shell からラボ コンポーネントを削除する
gcloud compute forwarding-rules delete consumer-url-forwarding-rule --global gcloud compute target-https-proxies delete consumer-url-target-proxy gcloud compute ssl-certificates delete wwwglobal --global gcloud compute url-maps delete consumer-url gcloud compute backend-services delete consumer-bs --global gcloud compute addresses delete httpspsclb --global gcloud beta compute network-endpoint-groups delete consumerpscneg --region=asia-southeast1 gcloud compute service-attachments delete ilbserviceattach --region=asia-southeast1 gcloud compute networks subnets delete psc-nat-subnet --region=asia-southeast1 gcloud compute forwarding-rules delete https-ilb-psc --region=asia-southeast1 gcloud compute addresses delete ilbaddress --region=asia-southeast1 gcloud compute target-https-proxies delete on-premise-httpsproxy --region=asia-southeast1 gcloud compute ssl-certificates delete www01 --region=asia-southeast1 gcloud compute url-maps delete on-premise-url --region=asia-southeast1 gcloud compute backend-services delete on-premise-service-backend --region=asia-southeast1 gcloud compute health-checks delete on-prem-service-hc --region=asia-southeast1 gcloud compute network-endpoint-groups delete on-prem-service-neg --zone=asia-southeast1-b gcloud compute networks subnets delete proxy-subnet-asia-southeast1 --region=asia-southeast1
16. 完了
以上で、この Codelab は完了です。
学習した内容
- ハイブリッド NEG と分散ヘルスチェックを使用する内部 HTTPS ロードバランサ
- 内部 HTTPS ロードバランサを使用した PSC サービス アタッチメント
- PSC ネットワーク エンドポイント グループの設定
- 外部 HTTPS ロードバランサで PSC NEG を公開する