🌐 サブネット設計パターン集 - Webアプリケーション種類別構成

概要

Webアプリケーションの種類によって、最適なサブネット構成は大きく異なります。本記事では、3層アプリケーションからマイクロサービス、データ分析基盤まで、7つの代表的なアプリケーション種類別にサブネット設計パターンとセキュリティ設定を詳しく解説します。

1. 基本的な3層Webアプリケーション

サブネット構成

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
VPC: webapp-vpc (10.0.0.0/16)

Subnets:
  public-subnet: 10.0.1.0/24
    Purpose: Web Server / Load Balancer
    Internet: Yes
    
  private-subnet: 10.0.2.0/24  
    Purpose: Application Server
    Internet: No (NAT Gateway経由)
    
  database-subnet: 10.0.3.0/24
    Purpose: Database Server
    Internet: No

ファイアウォール設定

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Internet → Web層
gcloud compute firewall-rules create allow-web-public \
    --source-ranges=0.0.0.0/0 \
    --target-tags=web-server \
    --allow=tcp:80,tcp:443

# Web層 → App層  
gcloud compute firewall-rules create allow-web-to-app \
    --source-tags=web-server \
    --target-tags=app-server \
    --allow=tcp:8080

# App層 → DB層
gcloud compute firewall-rules create allow-app-to-db \
    --source-tags=app-server \
    --target-tags=database \
    --allow=tcp:3306,tcp:5432

# 外部からDB直接アクセス拒否
gcloud compute firewall-rules create deny-db-external \
    --source-ranges=0.0.0.0/0 \
    --target-tags=database \
    --action=DENY \
    --rules=all

セキュリティ対策

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
Security_Measures:
  Web_Layer:
    - Cloud Armor (DDoS保護)
    - SSL/TLS終端
    - WAF適用
    
  App_Layer:  
    - Private subnet配置
    - 内部Load Balancer使用
    - アプリケーション暗号化
    
  DB_Layer:
    - Private subnet配置
    - SSL/TLS強制
    - 暗号化at rest

2. マイクロサービス・コンテナ基盤

サブネット構成

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
VPC: microservices-vpc (10.0.0.0/16)

Subnets:
  ingress-subnet: 10.0.1.0/24
    Purpose: Load Balancer / API Gateway
    Internet: Yes
    
  container-subnet: 10.0.10.0/22
    Purpose: GKE Cluster / Container Runtime  
    Internet: No
    Size: Large (1024 IPs)
    
  service-mesh-subnet: 10.0.3.0/24
    Purpose: Istio / Service Mesh Control
    Internet: No
    
  database-subnet: 10.0.4.0/24
    Purpose: Database Services
    Internet: No
    
  monitoring-subnet: 10.0.5.0/24
    Purpose: Prometheus / Grafana
    Internet: No

Kubernetesネットワーク設定

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# GKE Cluster作成
apiVersion: container.v1
kind: Cluster
metadata:
  name: microservices-cluster
spec:
  network: microservices-vpc
  subnetwork: container-subnet
  
  ipAllocationPolicy:
    clusterSecondaryRangeName: pods
    servicesSecondaryRangeName: services
    
  privateClusterConfig:
    enablePrivateNodes: true
    masterIpv4CidrBlock: 10.0.20.0/28

Service Mesh設定

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Istio設定
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
spec:
  values:
    pilot:
      env:
        EXTERNAL_ISTIOD: false
    global:
      meshID: mesh1
      multiCluster:
        clusterName: microservices-cluster
      network: container-network

3. データ分析基盤

サブネット構成

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
VPC: analytics-vpc (10.0.0.0/16)

Subnets:
  portal-subnet: 10.0.1.0/24
    Purpose: Analytics Portal / Jupyter
    Internet: Yes (認証必須)
    
  processing-subnet: 10.0.10.0/22
    Purpose: Dataflow / Dataproc
    Internet: No
    Size: Large
    
  storage-subnet: 10.0.3.0/24  
    Purpose: Data Lake / BigQuery
    Internet: No
    
  ml-subnet: 10.0.20.0/22
    Purpose: AI/ML Workloads / GPU
    Internet: No
    Size: Large
    
  dwh-subnet: 10.0.4.0/24
    Purpose: Data Warehouse / OLAP
    Internet: No

データパイプライン設定

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Dataflow パイプライン例
from apache_beam.options.pipeline_options import PipelineOptions

pipeline_options = PipelineOptions([
    '--project=analytics-project',
    '--region=asia-northeast1',
    '--subnetwork=regions/asia-northeast1/subnetworks/processing-subnet',
    '--use_public_ips=false',
    '--enable_streaming_engine'
])

セキュリティ設定

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Security_Configuration:
  VPC_Service_Controls:
    - BigQuery API制限
    - Cloud Storage制限  
    - 承認済みネットワークのみアクセス
    
  IAM_Policies:
    - 最小権限の原則
    - データ分類別アクセス制御
    - 監査ログ完全記録

4. E-commerce・高トラフィック

サブネット構成

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
VPC: ecommerce-vpc (10.0.0.0/16)

Subnets:
  cdn-subnet: 10.0.1.0/24
    Purpose: CDN Edge / Cloud Armor
    Internet: Yes
    
  frontend-subnet: 10.0.2.0/24
    Purpose: Web Frontend
    Internet: Yes
    
  api-subnet: 10.0.10.0/22
    Purpose: API Gateway / Backend
    Internet: No
    Size: Large
    
  cache-subnet: 10.0.3.0/24
    Purpose: Redis / Memcached
    Internet: No
    
  search-subnet: 10.0.4.0/24  
    Purpose: Elasticsearch
    Internet: No
    
  payment-subnet: 10.0.5.0/24
    Purpose: Payment Gateway (Isolated)
    Internet: No
    
  db-master-subnet: 10.0.6.0/24
    Purpose: Primary Database
    Internet: No
    
  db-replica-subnet: 10.0.7.0/24
    Purpose: Read Replicas
    Internet: No

高可用性設定

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Global Load Balancer
gcloud compute backend-services create ecommerce-backend \
    --global \
    --protocol=HTTP \
    --health-checks=health-check-http

# Auto Scaling設定
gcloud compute instance-groups managed set-autoscaling \
    ecommerce-ig \
    --max-num-replicas=100 \
    --min-num-replicas=5 \
    --target-cpu-utilization=0.6

決済系セキュリティ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
Payment_Security:
  PCI_DSS_Compliance:
    - 専用サブネット分離
    - 暗号化通信必須
    - アクセスログ詳細記録
    - 定期的な脆弱性スキャン
    
  Network_Isolation:
    - Payment subnet完全分離
    - Firewall rule最小限
    - VPC Flow Logs有効

5. SaaS・マルチテナント

サブネット構成

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
VPC: saas-vpc (10.0.0.0/16)

Subnets:
  lb-subnet: 10.0.1.0/24
    Purpose: Global Load Balancer
    Internet: Yes
    
  tenant-a-subnet: 10.0.10.0/22
    Purpose: Tenant A Services
    Internet: No
    Isolation: High
    
  tenant-b-subnet: 10.0.20.0/22  
    Purpose: Tenant B Services
    Internet: No
    Isolation: High
    
  shared-subnet: 10.0.2.0/24
    Purpose: Shared Services (Auth/Logging)
    Internet: No
    
  tenant-a-db-subnet: 10.0.3.0/24
    Purpose: Tenant A Database
    Internet: No
    
  tenant-b-db-subnet: 10.0.4.0/24
    Purpose: Tenant B Database  
    Internet: No
    
  admin-subnet: 10.0.6.0/24
    Purpose: Management / Admin
    Internet: No

テナント分離ルール

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# テナント間通信完全禁止
gcloud compute firewall-rules create deny-tenant-cross \
    --source-tags=tenant-a \
    --target-tags=tenant-b \
    --action=DENY \
    --rules=all \
    --priority=1000

# テナントA → 専用DB
gcloud compute firewall-rules create allow-tenant-a-db \
    --source-tags=tenant-a \
    --target-tags=tenant-a-db \
    --allow=tcp:5432

# Cross-tenant DB access拒否  
gcloud compute firewall-rules create deny-tenant-cross-db \
    --source-tags=tenant-a \
    --target-tags=tenant-b-db \
    --action=DENY \
    --rules=all \
    --priority=1000

6. IoT・リアルタイム処理

サブネット構成

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
VPC: iot-platform-vpc (10.0.0.0/16)

Subnets:
  iot-gateway-subnet: 10.0.1.0/24
    Purpose: IoT Gateway / MQTT Broker
    Internet: Yes (TLS必須)
    
  message-queue-subnet: 10.0.2.0/24
    Purpose: Pub/Sub / Apache Kafka
    Internet: No
    
  stream-processing-subnet: 10.0.10.0/22
    Purpose: Dataflow / Apache Beam
    Internet: No
    Size: Large
    
  realtime-analytics-subnet: 10.0.3.0/24
    Purpose: Real-time Dashboard
    Internet: No
    
  timeseries-db-subnet: 10.0.4.0/24
    Purpose: InfluxDB / Cloud Bigtable
    Internet: No
    
  batch-processing-subnet: 10.0.20.0/22
    Purpose: Batch Analytics / ML
    Internet: No
    Size: Large

IoTセキュリティ設定

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
IoT_Security:
  Device_Authentication:
    - X.509証明書認証
    - デバイス個別証明書
    - 証明書自動ローテーション
    
  Communication_Security:
    - MQTT over TLS (8883)
    - CoAP over DTLS (5684)
    - End-to-end暗号化
    
  Access_Control:
    - デバイス別権限管理
    - Topic level access control
    - Rate limiting

7. 金融・高セキュリティ

サブネット構成

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
VPC: financial-vpc (10.0.0.0/16)

Subnets:
  dmz-subnet: 10.0.1.0/24
    Purpose: WAF / Reverse Proxy
    Internet: Yes (制限的)
    
  app-subnet: 10.0.2.0/24
    Purpose: Application (Encrypted)
    Internet: No
    
  core-banking-subnet: 10.0.3.0/24
    Purpose: Core Banking Systems
    Internet: No (完全分離)
    
  database-subnet: 10.0.4.0/24
    Purpose: Database (TDE有効)
    Internet: No
    
  hsm-subnet: 10.0.5.0/24
    Purpose: HSM / Key Management
    Internet: No (最高機密)
    
  audit-subnet: 10.0.6.0/24
    Purpose: Audit / Compliance
    Internet: No
    
  backup-subnet: 10.0.7.0/24
    Purpose: Backup (Air-gapped)
    Internet: No (物理分離)

金融規制対応設定

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# HSM接続(最高機密)
gcloud compute firewall-rules create allow-core-to-hsm \
    --source-tags=core-banking \
    --target-tags=hsm \
    --allow=tcp:443 \
    --priority=1000

# 全通信ログ記録
gcloud compute firewall-rules create log-all-core \
    --source-tags=core-banking \
    --target-tags=all \
    --action=ALLOW \
    --rules=all \
    --enable-logging

コンプライアンス設定

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
Compliance_Requirements:
  PCI_DSS_Level_1:
    - カード情報完全暗号化
    - アクセスログ詳細記録
    - 定期的侵入テスト
    
  SOX_404:
    - 財務システム分離
    - 変更管理厳格化
    - 監査証跡完全保存
    
  GDPR:
    - 個人データ暗号化
    - Right to be forgotten対応
    - Data breach通知体制

サブネット設計の共通原則

セキュリティ階層化

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
Security_Layers:
  Layer_1_DMZ:
    - Internet直接アクセス
    - WAF + DDoS保護
    - 最小限のサービスのみ
    
  Layer_2_Application:
    - Private subnet
    - Load Balancer経由のみ
    - 内部通信暗号化
    
  Layer_3_Data:
    - 完全分離
    - Application layer経由のみ
    - 暗号化 + 監査ログ

運用効率化

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
Operational_Excellence:
  Naming_Convention:
    Format: "{env}-{tier}-{region}-subnet"
    Examples:
      - prod-web-asia-northeast1-subnet
      - dev-app-asia-northeast1-subnet
      
  IP_Address_Planning:
    - 環境別CIDR分離
    - 将来拡張考慮
    - 重複回避徹底
    
  Monitoring_Setup:
    - VPC Flow Logs
    - Cloud Monitoring
    - Custom metrics

まとめ

アプリケーション種類別の最適サブネット設計:

基本原則:

  • セキュリティ階層: DMZ → App → Data の3層分離
  • トラフィック分析: 通信パターンに基づく分離
  • 将来拡張性: 十分なIPアドレス空間確保

設計パターン選択:

  • シンプル: 3層アプリケーション
  • スケーラブル: マイクロサービス・E-commerce
  • セキュリティ重視: 金融・SaaS

適切なサブネット設計により、セキュリティ、性能、運用効率を同時に最適化できます。


📅 作成日: 2025年09月09日

参考リンク:

技術ネタ、趣味や備忘録などを書いているブログです
Hugo で構築されています。
テーマ StackJimmy によって設計されています。