You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
6.2 KiB

  1. # MetalLB
  2. MetalLB hooks into your Kubernetes cluster, and provides a network load-balancer implementation.
  3. It allows you to create Kubernetes services of type "LoadBalancer" in clusters that don't run on a cloud provider, and thus cannot simply hook into 3rd party products to provide load-balancers.
  4. The default operating mode of MetalLB is in ["Layer2"](https://metallb.universe.tf/concepts/layer2/) but it can also operate in ["BGP"](https://metallb.universe.tf/concepts/bgp/) mode.
  5. ## Prerequisites
  6. You have to configure arp_ignore and arp_announce to avoid answering ARP queries from kube-ipvs0 interface for MetalLB to work.
  7. ```yaml
  8. kube_proxy_strict_arp: true
  9. ```
  10. ## Install
  11. You have to explicitly enable the MetalLB extension.
  12. ```yaml
  13. metallb_enabled: true
  14. metallb_speaker_enabled: true
  15. ```
  16. By default only the MetalLB BGP speaker is allowed to run on control plane nodes. If you have a single node cluster or a cluster where control plane are also worker nodes you may need to enable tolerations for the MetalLB controller:
  17. ```yaml
  18. metallb_config:
  19. controller:
  20. nodeselector:
  21. kubernetes.io/os: linux
  22. tolerations:
  23. - key: "node-role.kubernetes.io/control-plane"
  24. operator: "Equal"
  25. value: ""
  26. effect: "NoSchedule"
  27. ```
  28. If you'd like to set additional nodeSelector and tolerations values, you can do so in the following fasion:
  29. ```yaml
  30. metallb_config:
  31. controller:
  32. nodeselector:
  33. kubernetes.io/os: linux
  34. tolerations:
  35. - key: "node-role.kubernetes.io/control-plane"
  36. operator: "Equal"
  37. value: ""
  38. effect: "NoSchedule"
  39. speaker:
  40. nodeselector:
  41. kubernetes.io/os: linux
  42. tolerations:
  43. - key: "node-role.kubernetes.io/control-plane"
  44. operator: "Equal"
  45. value: ""
  46. effect: "NoSchedule"
  47. ```
  48. ## Pools
  49. First you need to specify all of the pools you are going to use:
  50. ```yaml
  51. metallb_config:
  52. address_pools:
  53. primary:
  54. ip_range:
  55. - 192.0.1.0-192.0.1.254
  56. pool1:
  57. ip_range:
  58. - 192.0.2.1-192.0.2.1
  59. auto_assign: false # When set to false, you need to explicitly set the loadBalancerIP in the service!
  60. pool2:
  61. ip_range:
  62. - 192.0.3.0/24
  63. avoid_buggy_ips: true # When set to true, .0 and .255 addresses will be avoided.
  64. ```
  65. ## Layer2 Mode
  66. Pools that need to be configured in layer2 mode, need to be specified in a list:
  67. ```yaml
  68. metallb_config:
  69. layer2:
  70. - primary
  71. ```
  72. ## BGP Mode
  73. When operating in BGP Mode MetalLB needs to have defined upstream peers and link the pool(s) specified above to the correct peer:
  74. ```yaml
  75. metallb_config:
  76. layer3:
  77. defaults:
  78. peer_port: 179 # The TCP port to talk to. Defaults to 179, you shouldn't need to set this in production.
  79. hold_time: 120s # Requested BGP hold time, per RFC4271.
  80. communities:
  81. vpn-only: "1234:1"
  82. NO_ADVERTISE: "65535:65282"
  83. metallb_peers:
  84. peer1:
  85. peer_address: 192.0.2.1
  86. peer_asn: 64512
  87. my_asn: 4200000000
  88. communities:
  89. - vpn-only
  90. address_pool:
  91. - pool1
  92. # (optional) The source IP address to use when establishing the BGP session. In most cases the source-address field should only be used with per-node peers, i.e. peers with node selectors which select only one node. CURRENTLY NOT SUPPORTED
  93. source_address: 192.0.2.2
  94. # (optional) The router ID to use when connecting to this peer. Defaults to the node IP address.
  95. # Generally only useful when you need to peer with another BGP router running on the same machine as MetalLB.
  96. router_id: 1.2.3.4
  97. # (optional) Password for TCPMD5 authenticated BGP sessions offered by some peers.
  98. password: "changeme"
  99. peer2:
  100. peer_address: 192.0.2.2
  101. peer_asn: 64513
  102. my_asn: 4200000000
  103. communities:
  104. - NO_ADVERTISE
  105. address_pool:
  106. - pool2
  107. # (optional) The source IP address to use when establishing the BGP session. In most cases the source-address field should only be used with per-node peers, i.e. peers with node selectors which select only one node. CURRENTLY NOT SUPPORTED
  108. source_address: 192.0.2.1
  109. # (optional) The router ID to use when connecting to this peer. Defaults to the node IP address.
  110. # Generally only useful when you need to peer with another BGP router running on the same machine as MetalLB.
  111. router_id: 1.2.3.5
  112. # (optional) Password for TCPMD5 authenticated BGP sessions offered by some peers.
  113. password: "changeme"
  114. ```
  115. When using calico >= 3.18 you can replace MetalLB speaker by calico Service LoadBalancer IP advertisement.
  116. See [calico service IPs advertisement documentation](https://docs.projectcalico.org/archive/v3.18/networking/advertise-service-ips#advertise-service-load-balancer-ip-addresses).
  117. In this scenario you should disable the MetalLB speaker and configure the `calico_advertise_service_loadbalancer_ips` to match your `ip_range`
  118. ```yaml
  119. metallb_speaker_enabled: false
  120. metallb_config:
  121. address_pools:
  122. primary:
  123. ip_range:
  124. - 10.5.0.0/16
  125. auto_assign: true
  126. layer2:
  127. - primary
  128. calico_advertise_service_loadbalancer_ips: "{{ metallb_config.address_pools.primary.ip_range }}"
  129. ```
  130. If you have additional loadbalancer IP pool in `metallb_config.address_pools` , ensure to add them to the list.
  131. ```yaml
  132. metallb_speaker_enabled: false
  133. metallb_config:
  134. address_pools:
  135. primary:
  136. ip_range:
  137. - 10.5.0.0/16
  138. auto_assign: true
  139. pool1:
  140. ip_range:
  141. - 10.6.0.0/16
  142. auto_assign: true
  143. pool2:
  144. ip_range:
  145. - 10.10.0.0/16
  146. auto_assign: true
  147. layer2:
  148. - primary
  149. layer3:
  150. defaults:
  151. peer_port: 179
  152. hold_time: 120s
  153. communities:
  154. vpn-only: "1234:1"
  155. NO_ADVERTISE: "65535:65282"
  156. metallb_peers:
  157. peer1:
  158. peer_address: 10.6.0.1
  159. peer_asn: 64512
  160. my_asn: 4200000000
  161. communities:
  162. - vpn-only
  163. address_pool:
  164. - pool1
  165. peer2:
  166. peer_address: 10.10.0.1
  167. peer_asn: 64513
  168. my_asn: 4200000000
  169. communities:
  170. - NO_ADVERTISE
  171. address_pool:
  172. - pool2
  173. calico_advertise_service_loadbalancer_ips:
  174. - 10.5.0.0/16
  175. - 10.6.0.0/16
  176. - 10.10.0.0/16
  177. ```