Files
Aaron Patten 5c86b4879d refactor(dev): name the controller's Tilt resource nvke-controller (#1770)
The controller's Tilt resource is nvke-controller and its build step is
nvke-controller-compile. tilt_config.json sets the controller image with
nvke_controller_image, and Tilt providers return controller_resource_deps,
controller_env_overrides and controller_chart_flags. The cwe_image key and
the cwe_* provider fields are still read for one release, with a warning.

Signed-off-by: Aaron Patten <apatten@nvidia.com>
2026-10-19 10:37:26 -07:00
..
2026-08-15 19:32:05 -04:00

bgp-containers: FRR BGP peer for local container-node kube-vip testing

Stand up a host-mode FRR BGP speaker so CAPD and NICo control-plane containers can run kube-vip in active/active BGP mode locally. This is useful for testing control-plane teardown behavior, including the CWE drain-kube-vip runbook, before using a real NVKE site.

CAPD does not normally have a router on the Docker bridge for kube-vip to peer with. This harness runs FRR with --network host, so FRR listens from the same network namespace as the kind bridge gateway. The kube-vip manifest generated by the normal CWE runbook can keep auto-detecting its BGP peer from the default route; no manifest patching or worker static routes are required.

Files

File Purpose
frr.conf.tmpl FRR routing template. up.sh substitutes the detected kind gateway and subnet. Local AS is 4294967000 and remote AS is 65100, matching the NVKE kube-vip setup.
daemons FRR daemons file. Enables only zebra and bgpd.
up.sh Starts host-mode FRR and waits for bgpd to become ready.
down.sh Gracefully stops and removes the FRR container. Zebra retracts installed routes during clean shutdown.
verify-routes.sh Prints FRR BGP state: peer summary, learned routes, and neighbor details.
INCIDENT_README.md Describes how the production kube-vip/BGP traffic path maps to the local bgp-containers helper.

Typical test loop

# 1. Bring up the local CAPD management cluster.
make capd-up

# 2. Start the management plane. The bgp-containers Tilt provider starts
#    bgp-containers by default before CWE becomes ready.
tilt up

# 3. Create the workload cluster. The script auto-detects bgp-containers:
#    - bgp-containers running: controlPlaneVIP is the first address in
#      DEFAULT_VIP_RANGE not used by a cluster returned by NVKE.
#    - bgp-containers absent: controlPlaneVIP is omitted, preserving the plain CAPD path.
make capd-create-cluster

# 4. Watch BGP convergence. Expect one established peer per CP and the
#    controlPlaneVIP /32 learned through the CP nexthops.
make bgp-containers-verify
watch -n1 make bgp-containers-verify

# 5. Trigger a CP node removal via CWE or nvkectl. FRR should drop the target
#    peer's nexthop, and the drain-kube-vip runbook should complete cleanly.

# 6. Tear down when done.
make bgp-containers-down

Useful overrides:

DEFAULT_VIP_RANGE=172.31.1.0/24 make capd-create-cluster

# Use a specific VIP instead of automatic selection.
CONTROL_PLANE_VIP=172.31.1.10 make capd-create-cluster

# Disable the Tilt-managed speaker for a plain CAPD environment.
# Add this to tilt_config.json:
# "bgp_containers_enabled": false

# Force kube-vip on even if bgp-containers is not currently running.
CAPD_ENABLE_KUBE_VIP=true hack/create-capd-cluster.sh

# Force kube-vip off even if bgp-containers is running.
CAPD_ENABLE_KUBE_VIP=false hack/create-capd-cluster.sh

Why host mode only

In prod, the ToR runs BGP and sits in the actual data path between workers and control-plane nodes. Host mode mirrors that shape: FRR installs routes on the host kernel, which is the kernel the kind bridge uses for forwarding. Worker containers naturally route VIP traffic through their default gateway, and failover is driven by BGP route changes.

The older container-mode approach kept FRR in a separate container namespace. That required manually adding static routes on worker containers and patching kube-vip static pod manifests to point at the FRR container IP. That is easy to forget, differs from the generated manifest flow, and is no longer part of this MR.

How the routing works

CAPD control-plane and worker nodes are Docker containers attached to the kind bridge network. FRR runs in the Colima/Linux host network namespace, which is also where the kind bridge gateway lives.

When kube-vip is healthy on each control-plane node, each kube-vip pod opens a BGP session to the auto-detected peer address: the kind bridge gateway.

Route advertisement
===================

  CAPD control-plane containers                      Colima/Linux host netns
  -----------------------------                      -----------------------

  cp-1 kube-vip  -- BGP advertise VIP/32 ----------+
                                                     \
  cp-2 kube-vip  -- BGP advertise VIP/32 ------------>  FRR bgpd
                                                     /       |
  cp-3 kube-vip  -- BGP advertise VIP/32 ----------+        |
                                                             v
                                                        FRR zebra
                                                             |
                                                             v
                                                Linux kernel route table

  Example installed route shape:

    <controlPlaneVIP>/32 proto bgp
      nexthop via <cp-1-container-ip>
      nexthop via <cp-2-container-ip>
      nexthop via <cp-3-container-ip>

For packets from a worker to the control-plane VIP, the worker does not need a manual route. The VIP range is intentionally outside the kind bridge subnet, so the worker sends the packet to its normal default gateway: the kind bridge gateway. That gateway is in the same host network namespace where FRR's zebra installed the BGP-learned VIP route.

Packet routing while all CPs advertise the VIP
==============================================

  worker container
       |
       | dst=<controlPlaneVIP>
       | worker route lookup: VIP is off-subnet
       v
  default gateway: kind bridge gateway
       |
       | host route lookup:
       |   <controlPlaneVIP>/32 -> one of the CP container nexthops
       v
  selected CP container
       |
       v
  kube-vip / kube-apiserver

During a control-plane drain, the CWE drain-kube-vip runbook removes kube-vip from the target CP. That CP's BGP session closes or withdraws the VIP route. FRR removes that CP's path from its BGP table, and zebra updates the host kernel route.

Route withdrawal
================

  cp-2 drain starts
       |
       v
  cp-2 kube-vip stops advertising <controlPlaneVIP>/32
       |
       v
  FRR bgpd removes cp-2 as a path for the VIP
       |
       v
  FRR zebra updates the host kernel route table

  Before:
    <controlPlaneVIP>/32 -> cp-1, cp-2, cp-3

  After cp-2 withdrawal:
    <controlPlaneVIP>/32 -> cp-1, cp-3

After withdrawal, new worker packets to the VIP still go through the same default gateway, but the host route no longer chooses the drained CP as a nexthop. If every CP withdraws the VIP, the BGP-learned VIP route disappears and packets to the VIP stop routing successfully, which is the expected failure mode.

Packet routing after one CP withdraws
=====================================

  worker container
       |
       | dst=<controlPlaneVIP>
       v
  default gateway: kind bridge gateway
       |
       | host route lookup:
       |   <controlPlaneVIP>/32 -> remaining CP nexthops only
       v
  cp-1 or cp-3

  cp-2 is no longer selected for new packets to the VIP.

Production has the same BGP control-plane shape, but the router is real network infrastructure instead of FRR in the Colima/Linux host namespace.

CAPD host-mode test                         Production
-------------------                         ----------

cp kube-vip peers with FRR                  CP kube-vip peers with ToR/router
FRR runs in host netns                      ToR/router runs in network fabric
zebra programs host kernel routes           router programs hardware/kernel FIB
workers use Docker bridge gateway           workers use real network gateway
packets stay inside one dev host            packets cross the physical fabric

This setup does not model every production detail: physical underlay routing, multiple ToRs, switch ECMP behavior, or router failure modes. It does exercise the behavior this MR needs: kube-vip BGP session establishment, VIP route advertisement, route withdrawal during drain-kube-vip, and worker traffic moving away from a drained control-plane node.

Things to watch during a drain-kube-vip test

  • show bgp summary: the target CP session moves from Established to Active or Idle within a few seconds of drain-kube-vip executing.
  • show bgp ipv4 unicast for the control-plane VIP /32: the target CP nexthop disappears and stays withdrawn.
  • ip route get <controlPlaneVIP> from a worker container: the route should still resolve through the bridge gateway and one of the surviving CP nexthops.
  • CWE runbook execution: exit code 0, kube-vip container gone, no local TCP/179 listener, and no external apiserver connections on the drained CP.

Notes

  • --network host works on Linux Docker and Colima. Docker Desktop for macOS has more limited host networking semantics; this harness intentionally does not carry a container-mode fallback.
  • FRR binds TCP/179 in the host network namespace. Stop any conflicting local BGP speaker before running make bgp-containers-up.
  • down.sh does not delete host routes directly. It relies on FRR's graceful shutdown path so zebra can retract the BGP-learned routes it installed.