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.

223 lines
6.3 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/master"
  24. operator: "Equal"
  25. value: ""
  26. effect: "NoSchedule"
  27. - key: "node-role.kubernetes.io/control-plane"
  28. operator: "Equal"
  29. value: ""
  30. effect: "NoSchedule"
  31. ```
  32. If you'd like to set additional nodeSelector and tolerations values, you can do so in the following fasion:
  33. ```yaml
  34. metallb_config:
  35. controller:
  36. nodeselector:
  37. kubernetes.io/os: linux
  38. tolerations:
  39. - key: "node-role.kubernetes.io/control-plane"
  40. operator: "Equal"
  41. value: ""
  42. effect: "NoSchedule"
  43. speaker:
  44. nodeselector:
  45. kubernetes.io/os: linux
  46. tolerations:
  47. - key: "node-role.kubernetes.io/control-plane"
  48. operator: "Equal"
  49. value: ""
  50. effect: "NoSchedule"
  51. ```
  52. ## Pools
  53. First you need to specify all of the pools you are going to use:
  54. ```yaml
  55. metallb_config:
  56. address_pools:
  57. primary:
  58. ip_range:
  59. - 192.0.1.0-192.0.1.254
  60. auto_assign: true
  61. pool1:
  62. ip_range:
  63. - 192.0.2.1-192.0.2.1
  64. auto_assign: false # When set to false, you need to explicitly set the loadBalancerIP in the service!
  65. pool2:
  66. ip_range:
  67. - 192.0.2.2-192.0.2.2
  68. auto_assign: false
  69. ```
  70. ## Layer2 Mode
  71. Pools that need to be configured in layer2 mode, need to be specified in a list:
  72. ```yaml
  73. metallb_config:
  74. layer2:
  75. - primary
  76. ```
  77. ## BGP Mode
  78. When operating in BGP Mode MetalLB needs to have defined upstream peers and link the pool(s) specified above to the correct peer:
  79. ```yaml
  80. metallb_config:
  81. layer3:
  82. defaults:
  83. peer_port: 179 # The TCP port to talk to. Defaults to 179, you shouldn't need to set this in production.
  84. hold_time: 120s # Requested BGP hold time, per RFC4271.
  85. communities:
  86. vpn-only: "1234:1"
  87. NO_ADVERTISE: "65535:65282"
  88. metallb_peers:
  89. peer1:
  90. peer_address: 192.0.2.1
  91. peer_asn: 64512
  92. my_asn: 4200000000
  93. communities:
  94. - vpn-only
  95. address_pool:
  96. - pool1
  97. # (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
  98. source_address: 192.0.2.2
  99. # (optional) The router ID to use when connecting to this peer. Defaults to the node IP address.
  100. # Generally only useful when you need to peer with another BGP router running on the same machine as MetalLB.
  101. router_id: 1.2.3.4
  102. # (optional) Password for TCPMD5 authenticated BGP sessions offered by some peers.
  103. password: "changeme"
  104. peer2:
  105. peer_address: 192.0.2.2
  106. peer_asn: 64513
  107. my_asn: 4200000000
  108. communities:
  109. - NO_ADVERTISE
  110. address_pool:
  111. - pool2
  112. # (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
  113. source_address: 192.0.2.1
  114. # (optional) The router ID to use when connecting to this peer. Defaults to the node IP address.
  115. # Generally only useful when you need to peer with another BGP router running on the same machine as MetalLB.
  116. router_id: 1.2.3.5
  117. # (optional) Password for TCPMD5 authenticated BGP sessions offered by some peers.
  118. password: "changeme"
  119. ```
  120. When using calico >= 3.18 you can replace MetalLB speaker by calico Service LoadBalancer IP advertisement.
  121. See [calico service IPs advertisement documentation](https://docs.projectcalico.org/archive/v3.18/networking/advertise-service-ips#advertise-service-load-balancer-ip-addresses).
  122. In this scenario you should disable the MetalLB speaker and configure the `calico_advertise_service_loadbalancer_ips` to match your `ip_range`
  123. ```yaml
  124. metallb_speaker_enabled: false
  125. metallb_config:
  126. address_pools:
  127. primary:
  128. ip_range:
  129. - 10.5.0.0/16
  130. auto_assign: true
  131. layer2:
  132. - primary
  133. calico_advertise_service_loadbalancer_ips: "{{ metallb_config.address_pools.primary.ip_range }}"
  134. ```
  135. If you have additional loadbalancer IP pool in `metallb_config.address_pools` , ensure to add them to the list.
  136. ```yaml
  137. metallb_speaker_enabled: false
  138. metallb_config:
  139. address_pools:
  140. primary:
  141. ip_range:
  142. - 10.5.0.0/16
  143. auto_assign: true
  144. pool1:
  145. ip_range:
  146. - 10.6.0.0/16
  147. auto_assign: true
  148. pool2:
  149. ip_range:
  150. - 10.10.0.0/16
  151. auto_assign: true
  152. layer2:
  153. - primary
  154. layer3:
  155. defaults:
  156. peer_port: 179
  157. hold_time: 120s
  158. communities:
  159. vpn-only: "1234:1"
  160. NO_ADVERTISE: "65535:65282"
  161. metallb_peers:
  162. peer1:
  163. peer_address: 10.6.0.1
  164. peer_asn: 64512
  165. my_asn: 4200000000
  166. communities:
  167. - vpn-only
  168. address_pool:
  169. - pool1
  170. peer2:
  171. peer_address: 10.10.0.1
  172. peer_asn: 64513
  173. my_asn: 4200000000
  174. communities:
  175. - NO_ADVERTISE
  176. address_pool:
  177. - pool2
  178. calico_advertise_service_loadbalancer_ips:
  179. - 10.5.0.0/16
  180. - 10.6.0.0/16
  181. - 10.10.0.0/16
  182. ```