Module: Pangea::Kubernetes::LoadBalancer

Defined in:
lib/pangea/kubernetes/load_balancer.rb

Overview

Elastic load balancer tier composition.

Two-tier architecture:

Tier 1 (External): Fleet of NixOS HAProxy VMs behind Hetzner Cloud LB
Tier 2 (In-Cluster): Cilium eBPF (L4) + Istio Gateway (L7)

Traffic flow:

DNS  Hetzner Cloud LB  NixOS HAProxy fleet  K8s NodePort  Istio Gateway

For bare metal: replace Hetzner Cloud LB with NixOS BIRD BGP + keepalived VRRP

Instance Method Summary collapse

Instance Method Details

#elastic_load_balancer(name, attributes = {}) ⇒ Hash

Create an elastic load balancer tier for a Kubernetes cluster.

Parameters:

  • name (Symbol)

    LB tier name

  • attributes (Hash) (defaults to: {})

    Load balancer configuration (see Types::LoadBalancerConfig)

Returns:

  • (Hash)

    Created resource references



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/pangea/kubernetes/load_balancer.rb', line 38

def elastic_load_balancer(name, attributes = {})
  config = Types::LoadBalancerConfig.new(attributes)
  result = {}

  tags = {
    LoadBalancer: name.to_s,
    Mode: config.mode,
    ManagedBy: 'Pangea'
  }.merge(config.tags)

  hcloud_labels = tags.transform_keys { |k| k.to_s.downcase.gsub(/[^a-z0-9_]/, '_') }

  # Create HAProxy VMs
  result[:haproxy_servers] = create_haproxy_fleet(name, config, hcloud_labels)

  # Create Hetzner Cloud LB in front of HAProxy fleet (managed mode)
  unless config.bare_metal?
    result[:cloud_lb] = create_hetzner_cloud_lb(name, config, result[:haproxy_servers], hcloud_labels)
  end

  result
end