技術部落格

集結國內外精選文章,掌握最新雲端技術新知與應用

首頁 / 基礎架構 / 【手把手教學】如何透過 HA VPN 連接 GCP 和 AWS VPC

【手把手教學】如何透過 HA VPN 連接 GCP 和 AWS VPC

如何透過 VPN 串接 GCP 和 AWS 的 VPC

接續前一篇 VPC Network:GCP 和 AWS 功能比較 的整理,我們繼續來介紹如何透過 VPN 把 GCP 和 AWS 的 VPC 串接起來,形成 Hybrid Cloud 的架構吧!

架構

整個架構圖如下:

主要動作如下:

  1.  GCP 建立 HA VPN Gateway
  2.  AWS 建立 Customer Gateway
  3.  AWS 建立 Virtual Private Gateway
  4.  AWS 附加 Virtual Private Gateway 至 AWS VPC
  5.  AWS 建立 Site-to-site Connection
  6.  GCP 建立 Site-to-site VPN tunnels
  7.  測試 VPN 連線

1. GCP 建立 Cloud Router

  • GCP > Networking > Hybrid connectivity > Cloud Routers 建立好一組 ASN 為 65001 的 Cloud Router

2. GCP 建立 HA VPN Gateway

在 Networking > Hybrid Connectivity > VPN 中選擇 CREATE VPN CONNECTION

選擇建立 High-availability (HA) VPN

VPN gateway name:HA VPN 名稱

Network:要套用的 VPC 名稱

Region: 要放置 HA VPN 的區域

按下 Create & Continue 後,取得 2 組 VPN Gateway IP

我們 GCP 這邊先停在第二步驟

3. AWS 建立 Customer Gateway

在 VPC > VIRTUAL PRIVATE NETWORK (VPN) > Customer Gateways 中點選 Create customer gateway

我們要建立兩個 customer gateway,以下展示建立第一個的步驟

Name: 客戶網關名稱

Routing: Dynamic (動態路由)

BGP ASN: GCP Cloud Router ASN

IP Address: 在建立1步取得GCP VPN GW IP (2個)

重複以上步驟建立第二個 (BGP ASN 相同)

4. AWS 建立 Virtual Private Gateway

在 VPC > VIRTUAL PRIVATE NETWORK (VPN) > Virtual Private Gateways 中點選 Create virtual private gateway

Name tag: 虛擬私有網關名稱
ASN: 可以使用 Amazon default ASN(default 為 64512),或自定義(如 65002)

 附加到要套用的 VPC

5. AWS 建立 2 條 Site-to-site Connection

在 VPC > VIRTUAL PRIVATE NETWORK (VPN) > Site-to-site VPN connections 中點選 Create VPN connection

Target gateway type: virtual private gateway

Virtual private gateway: 第 4 步創建的 virtual private gateway

Customer gateway: Existing

Customer gateway ID: 第 3 步創建的 customer gateway (2個)

Routing options: Dynamic (requires BGP)

Tunnel 的部分

  • Inside IPv4 CIDR for tunnel 1:如果已經有先規劃好的 AWS BGP IP /30 CIDR,可以自行指定,或者留白,等 connection 建立好時自動會建立兩條 tunnels 並給予 BGP IP CIDR
  • IKE shared-key:如果已經有先規劃好的 IKE shared-key,可以自行指定,或者留白,等 connection 建立好時自動會建立兩條 tunnels 並給予 IKE shared-key
  • Advanced options for tunnel:保留 Use default options

重複以上步驟建立第二個 site-to-site VPN connections

等待幾分鐘,Connecction 的 State 會變成 Available, tunnel 的 status 為 Down

需要記下來的項目:

  • 把兩個 connection 的共 4 組 tunnel 的 Outside IP address 記下來
  • 把兩個 connection 的共 4 組 tunnel 的 Inside IPv4 address 記下來
  • 把兩個 connection 的共 4 組 tunnel 的 IKE pre-shared key 記下來
    • VPN connection > Actions > Modify VPN tunnel option 中查看
    • 也可以透過 Download VPN connection

6. GCP 建立 4 條 VPN tunnels

回來 GCP 這邊,繼續建立 VPN tunnels,選擇 Create new peer VPN gateway

Name: 對等互連 VPN 閘道名稱

Interfaces: 選擇 for interfaces,並分別填上第 5 步驟取得的 4 組 AWS VPN tunnels 的外部 IP

Routing options: 選擇第 1 步驟的 cloud router

四個 tunnel 需要設定的:

  • 相關聯的 Cloud VPN 閘道介面: GCP VPN GW
  • 相關聯的對等互連 VPN 閘道介面: AWS VPN GW
  • 名稱: VPN tunnel name
  • IKE 版本: IKEv2
  • IKE pre-shared key:請到 AWS tunnel 那邊查詢每個 tunnel 的 IKE pre-shared key,AWS 和 GCP 同一個 tunnel 使用的 key 需要相同

四個 BGP 工作階段需要設定的:

  • Name: BGP 連線名稱
  • Peer ASN 要是 AWS VPG 的 ASN,建立時沒有設定 custom ASN 的話,就是 64512
  • Cloud router BGP IP:GCP side 的 inside IP
  • BGP peer IP:AWS side 的 inside IP
  • BGP peer: Enable


重複四個步驟完成 BGP session 的設定

確認VPN tunnel & BGP session 狀態

等待 BGP session status 完成

7. AWS 啟用 virtual private gateway 的 route table 的 propagation

確認 VPN tunnel & BGP session 狀態 

(如果 GCP 那端已經是 established,AWS 這邊可能會需要等一下才更新為 Up)

Connection 1

Connection 2

啟用 virtual private gateway 的 VPC 的 Route table 的 Route propagation

確認有多了 Virtual private gateway 的網段

8. 測試 VPN 連線 

AWS VM instance

Access GCP VM instance from AWS VM instance

Access AWS instance from GCP VM instance

Troubleshooting

  1. VPN Connection

如果無法連通,請先確認兩邊的 VPN connection 狀態皆為綠色的:

AWS: tunnels status 應為 Up

GCP: tunnels status 應為 Established

  1. BGP ASN

應確保兩邊的 BGN ASN 能夠對上

  1. IP address and CIDR
  2. Firewall

AWS: 請檢查 Security group

GCP: 請檢查套用至 VM instance 上的 Firewall rule

結論

本文整理如何用 GCP 的 HA VPN 串接 GCP 和 AWS 的 VPC,確認技術的可行性,實際上的應用要考慮的更多。

現在 SaaS 越來越流行,很多人會以為 IaaS 不重要,或者忽略。但是企業整體營運還是要面對 IT 基礎設施 (Infrastructure),而最根本的就是 Network Topology 的問題,這些問題包含了 1) 規劃、2) 可控性、3) 執行政策 三個面向,本質上是沒有改變,不會因此而 NoOps。用生活的例子來說:
1. 規劃:公路要先規劃有哪些主幹線、支線,哪些主幹道中哪一些會交錯?
2. 可控性:這些道路可否管控流量?閘道?紅綠燈?單行道?紅綠燈多遠距離設計一個?
3. 執行政策:哪些車可以上快速道路?假日車流如何疏導?活動如何管制車輛?罰款如何?酒駕怎麼辦?

交通建設的技術,會隨時代改變、進步,但是這三個問題不會隨著技術前進而消失,而是會轉化成其他的形式。

會使用 Hybrid Cloud 通常都是要把服務從既有的 Data Center 搬到 Cloud 的中、大型企業,當把服務搬到 Cloud 時,勢必都需要考慮原本的網路和 Cloud Networking 的整合與串接,串好後就會面臨前面提的三個問題。更多相關的經驗,請參考:Plan and Design Multiple VPCs in Different Regions 的分享,未來有機會再整理 GCP VPC Networking 規劃心得。

延伸閱讀

•  Experience GCP
•   Compare GCP VPC Network with AWS
•   Plan and Design Multiple VPCs in Different Regions
•   Ops as Code using Serverless

參考資料

•   Automated Network Deployment: Building a VPN Between GCP and AWS
•  AWS Managed VPN Connections 

分享本文:
FacebookLineTwitter
回到頂端