0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MetalLB BGPモードを試す(VyOSルータと連携)

Posted at

前回に引き続きMetalLBについてです。今回は、BGPモードを使ってVyOSルータと連携し、オンプレ環境で高可用なロードバランサー構築を試しましたので、VyOSの設定手順も含めて手順を記載します。

なお、MetalLBインストールのインストールについては、前回の記事を確認してください。

構成イメージ

  • Kubernetesクラスタ(MetalLB導入済み)
  • VyOSルータ(BGP)
  • MetalLBはBGPモードでルータに経路をアナウンス

image.png

L2モード vs BGPモード 比較

手順に入る前に、L2モードとBGPモードの違いを簡単に記載します。

項目 L2モード BGPモード
仕組み ARP/NDPで同一L2ネットワークにIPをアナウンス BGPでルータに経路をアナウンス
メリット 構成が簡単、追加ルータ設定不要、小規模向け 高可用性、冗長化、大規模環境に適合
デメリット L2セグメント依存、スケールに弱い BGPルータ設定必須、ネットワーク知識が必要
利用シーン 単一サブネットで簡易構成 データセンターや大規模環境で冗長性重視

特に、トラフィックの分散の部分が大きく異なります。L2モードの場合は、単一ノードにトラフィックが流れるので、利用には注意が必要です。
image.png

設定手順

VyOS設定

まずは、VyOSの設定から。

  1. BGP Router Configuration

    $ set protocols bgp system-as 65000
    
  2. Peers Configuration

    $ set protocols bgp neighbor 192.168.18.15 remote-as 65001
    $ set protocols bgp neighbor 192.168.18.16 remote-as 65001
    $ set protocols bgp neighbor 192.168.18.15 address-family ipv4-unicast
    $ set protocols bgp neighbor 192.168.18.16 address-family ipv4-unicast
    
  3. Redistribution Configuration

    $ set protocols bgp address-family ipv4-unicast redistribute connected
    
  4. Confirm Configuration

    $ show protocols bgp
     address-family {
         ipv4-unicast {
             redistribute {
                 connected {
                 }
             }
         }
     }
     neighbor 192.168.18.15 {
         address-family {
             ipv4-unicast {
             }
         }
         remote-as 65001
     }
     neighbor 192.168.18.16 {
         address-family {
             ipv4-unicast {
             }
         }
         remote-as 65001
     system-as 65000
    
    

MetalLB設定(BGPモード)

続いて、MetalLBの設定をしていきます。

  1. IPAddressPool作成

    ipaddresspool.yaml
    apiVersion: metallb.io/v1beta1
    kind: IPAddressPool
    metadata:
      name: second-pool
      namespace: metallb
    spec:
      addresses:
      - 192.168.19.0/24
      autoAssign: true
    

    適用:

    $ kubectl apply -f ipaddresspool.yaml
    
  2. BGPPeer設定

    bgppeer.yaml
    apiVersion: metallb.io/v1beta1
    kind: BGPPeer
    metadata:
      name: peer-to-router
      namespace: metallb
    spec:
      peerAddress: 192.168.18.253
      peerASN:      65000
      myASN:        65001
      holdTime:      "180s"
    

    適用:

    $ kubectl apply -f bgppeer.yaml
    
  3. BGPAdvertisement設定

    bgpadvertisement.yaml
    apiVersion: metallb.io/v1beta1
    kind: BGPAdvertisement
    metadata:
      name: local
      namespace: metallb
    spec:
      ipAddressPools:
      - second-pool
      aggregationLength: 24
    

    適用:

    $ kubectl apply -f bgpadvertisement.yaml
    

テスト: nginx podのデプロイ

nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx-metallb
  name: nginx-metallb
spec:
  selector:
    matchLabels:
      app: nginx-metallb
  template:
    metadata:
      labels:
        app: nginx-metallb
    spec:
      containers:
      - image: nginx
        name: nginx-metallb
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-metallb
spec:
  type: LoadBalancer
  selector:
    app: nginx-metallb
  ports:
    - name: http
      port: 80
      targetPort: 80

適用:

kubectl apply -f nginx.yml

確認:

  1. serviceの確認

    $ kubectl get svc
    NAME              TYPE           CLUSTER-IP      EXTERNAL-IP    PORT(S)        AGE
    external-master   ExternalName   <none>          master         80/TCP         20d
    kubernetes        ClusterIP      10.150.0.1      <none>         443/TCP        20d
    nginx-metallb     LoadBalancer   10.150.197.11   192.168.19.0   80:32606/TCP   18s
    

    => nginxにIPAddressPoolで指定したIPアドレスがアサインされています。

  2. VyOSでBGP及びルーティング情報の確認

    $ show bgp summary
    IPv4 Unicast Summary (VRF default):
    BGP router identifier 192.168.44.253, local AS number 65000 vrf-id 0
    BGP table version 8
    RIB entries 13, using 2496 bytes of memory
    Peers 2, using 41 KiB of memory
    
    Neighbor        V         AS   MsgRcvd   MsgSent   TblVer  InQ OutQ  Up/Down State/PfxRcd   PfxSnt Desc
    192.168.18.15   4      65001       123       153        8    0    0 01:57:26            1        8 N/A
    192.168.18.16   4      65001       123       153        8    0    0 01:57:25            1        8 N/A
    
    Total number of neighbors 2
    
    $ show ip route
    Codes: K - kernel route, C - connected, S - static, R - RIP,
       O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP,
       T - Table, v - VNC, V - VNC-Direct, A - Babel, F - PBR,
       f - OpenFabric,
       > - selected route, * - FIB route, q - queued, r - rejected, b - backup
       t - trapped, o - offload failure
    
    S>* 0.0.0.0/0 [1/0] via 192.168.16.253, eth0, weight 1, 26w3d03h
    ・・・
    C>* 192.168.18.0/24 is directly connected, eth3, 26w3d03h
    B>* 192.168.19.0/24 [20/0] via 192.168.18.15, eth3, weight 1, 01:52:01  <-MetalLB BGP
      *                        via 192.168.18.16, eth3, weight 1, 01:52:01 <-MetalLB BGP
    C>* 192.168.44.0/24 is directly connected, eth5, 26w3d03h
    

    => 192.168.18.15-16とBGPセッションが張れており、ルーティング情報も正しく登録されていることを確認できました。

  3. アクセス確認
    最後に、nginxにアクセスできることを確認します。

    $ curl --head 192.168.19.0
    HTTP/1.1 200 OK
    Server: nginx/1.29.3
    Date: Thu, 20 Nov 2025 15:19:29 GMT
    Content-Type: text/html
    Content-Length: 615
    Last-Modified: Tue, 28 Oct 2025 12:05:10 GMT
    Connection: keep-alive
    ETag: "6900b176-267"
    Accept-Ranges: bytes
    

    => 問題なくアクセスできました。

まとめ

  • MetalLBのBGPモードを使うことで、オンプレ環境でもクラウド同様にLoadBalancerタイプのServiceを利用可能。
  • VyOSなどのBGP対応ルータと連携することで、経路冗長化や高可用性を実現。
  • L2モードとの違い:
    • L2モードは構成が簡単で小規模向け。
    • BGPモードはネットワーク知識が必要だが、大規模環境や冗長性を求める場合に最適。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?