minikube metallb 外部 ip 与 minikube ip

minikube metallb external-ip vs minikube ip

apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
  labels:
    app: metallb

data:
  config: |
    address-pools:
    - name: default
      protocol: layer2
      addresses:
      - 192.168.99.100-192.168.99.250

你好,我在 minikube (virtualbox) 中使用 metallb。配置metallb的external-ip时,必须根据minikube的ip范围来设置。但为什么即使超出范围它也能正常工作?

由于您的 Layer 2 configuration of your MetalLB:

,此行为按预期工作

Layer 2 mode is the simplest to configure: in many cases, you don’t need any protocol-specific configuration, only IP addresses.

Layer 2 mode does not require the IPs to be bound to the network interfaces of your worker nodes. It works by responding to ARP requests on your local network directly, to give the machine’s MAC address to clients.

在您的 ConfigMap 中我们看到:

data:
  config: |
    address-pools:
    - name: default
      protocol: layer2
      addresses:
      - 192.168.99.100-192.168.99.250

它让 MetalLB 控制从 192.168.99.100192.168.99.250 的 IP 并配置第 2 层模式。请注意,您的 minikube IP 192.168.99.102 在上面定义的范围内,因此您可以通过浏览器访问它。

这个机制在 this guideMetalLB Layer 2 Configuration 部分有很好的解释:

MetalLB contains two pieces of information, a protocol and range of IP addresses. In this configuration MetalLB is instructed to handout addresses from the 192.168.99.95/105, its our predefined range with respect to node IP. In our case to get IP of our minikube we use minikube ip command and set range accordingly in config file.

我建议通读整个指南,以更好地理解整个 minikube + MetalLB 概念。