
ELB for Envoy を NLB 経由の PrivateLink で別 VPC に公開してみた
はじめに
2026年11月25日に、ELB for Envoy の一般提供開始が発表されました。
ELB for Envoy は、オープンソースの Envoy をプロキシとして動かす、Elastic Load Balancing (ELB) の新しいロードバランサータイプです。この記事では、ELB for Envoy の前段に NLB を置いて PrivateLink で別 VPC から使う構成を作ります。また、プロキシの IP が変わったときの NLB のターゲットの扱いを確認します。
検証環境
- リージョン:東京(ap-northeast-1)
- VPC:同一アカウントの 2 つ
- インターネット接続:なし(どちらの VPC にもインターネットゲートウェイと NAT ゲートウェイを作成していない)
- VPC-A:10.10.0.0/24(1a は 10.10.0.0/26、1c は 10.10.0.64/26)
- VPC-B:10.20.0.0/24(1a は 10.20.0.0/26、1c は 10.20.0.64/26)
- Envoy のバージョン(proxyVersion):1.40
- クライアント EC2:各 VPC に 1 台(t4g.nano、Amazon Linux 2023)
- 操作:AWS Systems Manager の Run Command
構成
エンドポイントサービスに指定できるロードバランサーは、Network Load Balancer(NLB)か Gateway Load Balancer です。create-vpc-endpoint-service-configuration の引数は、NLB が --network-load-balancer-arns、Gateway Load Balancer が --gateway-load-balancer-arns です。
ELB for Envoy のドキュメント(概要、セットアップ、制限)、製品ページ、告知には、PrivateLink の記載がありませんでした。そこで、internal の ELB for Envoy の前段に NLB を置き、その NLB をエンドポイントサービスとして使う構成を作りました。
NLB には、プロキシの IP を ip ターゲットとして登録します。プロキシが active になった後に、VPC-A の EC2 で次のコマンドを実行すると、プロキシの IP が 2 つ返りました。
$ getent ahostsv4 <proxy-dns-name> | awk '{print $1}' | sort -u
<ip-1c-old>
<ip-1a>
経路は次のとおりです。
VPC-B のクライアント
→ インターフェイスエンドポイント
── PrivateLink ──
→ VPC-A の NLB(internal、TCP 80、ip ターゲット)
→ ELB for Envoy(internal、固定応答)
VPC-A のクライアント
→ VPC 内から NLB またはプロキシへ接続
構築
プロキシ用ロール aws-elb-proxy-role とプロキシの作成手順は、次の記事に載っています。この記事では、これらを前提にします。
今回の構築で実行したコマンドは、各項目の折りたたみに載せます。
セキュリティグループ
VPC-A のプロキシ用セキュリティグループ(SG)には、VPC-A の CIDR からの TCP 80 を許可するルールを追加しました。NLB には SG を付けていません。VPC-B のエンドポイント用 SG には、クライアント用 SG からの TCP 80 を許可するルールを追加しました。
セキュリティグループのルールの追加コマンド
aws ec2 authorize-security-group-ingress --group-id <proxy-sg-id> --protocol tcp --port 80 --cidr 10.10.0.0/24
aws ec2 authorize-security-group-ingress --group-id <endpoint-sg-id> --protocol tcp --port 80 --source-group <client-sg-id>
プロキシ
プロキシは internal で作成し、VPC-A の 2 つのサブネットと上記の SG を指定しました。Envoy の設定は、ポート 80 で待ち受け、すべてのパスへのリクエストに direct_response でステータス 200 と固定の本文を返す内容です。
プロキシの設定ファイルと作成コマンド
Envoy の設定を config-01-fixed-response.yaml として保存します。
admin:
address:
socket_address:
address: 127.0.0.1
port_value: 9901
static_resources:
listeners:
- name: listener_0
address:
socket_address:
address: 0.0.0.0
port_value: 80
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match:
prefix: "/"
direct_response:
status: 200
body:
inline_string: "hello from ELB for Envoy\n"
http_filters:
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
入力 JSON を create-proxy-input.json として保存します。
{
"name": "privatelink-proxy",
"type": "envoy",
"proxyVersion": "1.40",
"roleArn": "arn:aws:iam::<account-id>:role/aws-elb-proxy-role",
"networkConfiguration": {
"ipConfiguration": {
"ipAddressingConfiguration": { "ipv4Addressability": "internal", "ipv6Addressability": "off" }
},
"vpcConfiguration": {
"subnets": [ { "subnetId": "<subnet-a1-id>" }, { "subnetId": "<subnet-a2-id>" } ],
"securityGroups": [ { "securityGroupId": "<proxy-sg-id>" } ]
}
}
}
作成コマンドは次のとおりです。
aws elb-proxy create-proxy --cli-input-json file://create-proxy-input.json --cli-binary-format raw-in-base64-out --configuration 'configurationFile={configurationBytes@=file://config-01-fixed-response.yaml}' --output json
作成を開始してから状態が active になるまで、約 3 分 40 秒でした。レスポンスの dnsName は internal- で始まりました。
NLB
プロキシ用 SG の付いた ENI の IP を取得し、ターゲットタイプが ip のターゲットグループ、internal の NLB、リスナーの順に作成しました。NLB のサブネットは、プロキシと同じ 2 つです。
NLB の作成コマンド
aws ec2 describe-network-interfaces --filters Name=group-id,Values=<proxy-sg-id> --query 'NetworkInterfaces[].PrivateIpAddress' --output text
aws elbv2 create-target-group --name elbproxy-pl-tg --protocol TCP --port 80 --target-type ip --vpc-id <vpc-a-id> --health-check-protocol HTTP --health-check-path / --query 'TargetGroups[0].TargetGroupArn' --output text
aws elbv2 register-targets --target-group-arn <tg-arn> --targets Id=<ip-1a>,Port=80 Id=<ip-1c-old>,Port=80
aws elbv2 create-load-balancer --name elbproxy-pl-nlb --type network --scheme internal --subnets <subnet-a1-id> <subnet-a2-id> --query 'LoadBalancers[0].[LoadBalancerArn,DNSName]' --output text
aws elbv2 create-listener --load-balancer-arn <nlb-arn> --protocol TCP --port 80 --default-actions Type=forward,TargetGroupArn=<tg-arn> --query 'Listeners[0].ListenerArn' --output text
NLB の作成から約 3 分で、2 つのターゲットがどちらも healthy になりました。describe-target-health の出力から、Target.Id、Target.AvailabilityZone、TargetHealth.State を抜粋して示します。
{
"TargetHealthDescriptions": [
{
"Target": {
"Id": "<ip-1a>",
"AvailabilityZone": "ap-northeast-1a"
},
"TargetHealth": {
"State": "healthy"
}
},
{
"Target": {
"Id": "<ip-1c-old>",
"AvailabilityZone": "ap-northeast-1c"
},
"TargetHealth": {
"State": "healthy"
}
}
]
}
エンドポイントサービス
NLB をエンドポイントサービスにし、接続を許可するプリンシパルを同一アカウントに限定して、VPC-B にインターフェイスエンドポイントを作成しました。
エンドポイントサービスとエンドポイントの作成コマンド
aws ec2 create-vpc-endpoint-service-configuration --network-load-balancer-arns <nlb-arn> --no-acceptance-required --query 'ServiceConfiguration.[ServiceId,ServiceName]' --output text
aws ec2 modify-vpc-endpoint-service-permissions --service-id <service-id> --add-allowed-principals arn:aws:iam::<account-id>:root --output json
aws ec2 create-vpc-endpoint --vpc-endpoint-type Interface --vpc-id <vpc-b-id> --service-name <service-name> --subnet-ids <subnet-b1-id> <subnet-b2-id> --security-group-ids <endpoint-sg-id> --query VpcEndpoint.VpcEndpointId --output text
エンドポイントは、作成から約 30 秒で available になりました。
動作確認
NLB 経由(VPC-A)
VPC-A の EC2 から、プロキシの DNS 名と NLB の DNS 名へ curl しました。
$ curl -sS -m 10 -w 'HTTP %{http_code}\n' http://<proxy-dns-name>/
hello from ELB for Envoy
HTTP 200
$ curl -sS -m 10 -w 'HTTP %{http_code}\n' http://<nlb-dns-name>/
hello from ELB for Envoy
HTTP 200
PrivateLink 経由(VPC-B)
エンドポイントが available になって約 1 分 20 秒後に、VPC-B の EC2 からエンドポイントのリージョナルの DNS 名へ curl しました。
$ curl -sS -m 8 -w 'HTTP %{http_code}\n' http://<endpoint-dns-name>/
hello from ELB for Envoy
HTTP 200
1a と 1c の DNS 名でも同じ結果でした。
プロキシの IP の変更
サブネットの入れ替え
プロキシが使う 1c のサブネットを、新しいサブネットに入れ替えました。
aws ec2 create-subnet --vpc-id <vpc-a-id> --cidr-block 10.10.0.128/26 --availability-zone ap-northeast-1c
aws elb-proxy update-proxy-network-configuration --proxy-identifier <proxy-arn> --vpc-configuration 'subnets=[{subnetId=<subnet-a1-id>},{subnetId=<subnet-a3-id>}],securityGroups=[{securityGroupId=<proxy-sg-id>}]'
更新の約 1 分後に、1c に <ip-1c-new> の ENI が増えました。1a の IP は変わりませんでした。
サブネットの入れ替えのほかに、負荷でもプロキシの IP は変わります。
ターゲットの登録し直し
ip ターゲットの NLB では、ターゲットの IP が変わったら、手動で登録し直す必要があります。<ip-1c-new> を NLB のターゲットに登録し、healthy になってから、旧 IP を登録解除しました。
aws elbv2 register-targets --target-group-arn <tg-arn> --targets Id=<ip-1c-new>,Port=80
aws elbv2 wait target-in-service --target-group-arn <tg-arn> --targets Id=<ip-1c-new>,Port=80
aws elbv2 deregister-targets --target-group-arn <tg-arn> --targets Id=<ip-1c-old>,Port=80
まとめ
ELB for Envoy は、プロキシの IP を NLB の ip ターゲットに登録し、その NLB をエンドポイントサービスにすることで、PrivateLink 経由で利用できました。
ただし、プロキシの IP は動的に変わることがあるため、NLB のターゲットに登録した IP を更新する仕組みが必要です。
特に負荷が増減する環境では、プロキシの IP が頻繁に変わる可能性が高いため、NLB 経由の PrivateLink の利用は、運用できるかを含めて評価することをおすすめします。
PrivateLink 以外で VPC をまたいでプロキシを利用する方法(Transit Gateway や 1:1 NAT を使った中継など)は、別の記事で紹介したいと思います。







