官方github: https://github.com/google/metallb
官方文档:https://metallb.universe.tf


1. 安装之前

如果你在IPVS模式下使用kube-proxy,Kubernetes v1.14.2必须启用严格的ARP模式。注意,如果你使用kube-router作为service-proxy,你不需要这个,因为它默认启用了严格的ARP。

你可以通过编辑当前集群中的kube-proxy配置来实现:

$ kubectl edit configmap -n kube-system kube-proxy
...
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: "ipvs"
ipvs:
  strictARP: true
...

或者可以通过修改 configmap 来实现:

$ kubectl get configmap kube-proxy -n kube-system -o yaml | \
sed -e "s/strictARP: false/strictARP: true/" | \
kubectl diff -f - -n kube-system

$ kubectl get configmap kube-proxy -n kube-system -o yaml | \
sed -e "s/strictARP: false/strictARP: true/" | \
kubectl apply -f - -n kube-system

2. metallb安装

//安装 metallb

$ kubectl apply -f https://gitee.com/jack_zang/kubernetes/raw/master/lb/install-v0.13.7/metallb-native-v0.13.7.yaml

//配置 ip 地址池

$ cat lb/install-v0.13.7/metallb-l2-ippool.yaml
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  name: internal-ip
  namespace: metallb-system
spec:
  addresses:
  - 192.168.10.203-192.168.10.204

$ kubectl apply -f https://gitee.com/jack_zang/kubernetes/raw/master/lb/install-v0.13.7/metallb-l2-ippool.yaml

// 声明 地址池

$ cat lb/install-v0.13.7/metallb-l2advertisement.yaml
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
  name: l2
  namespace: metallb-system
spec:
  ipAddressPools:
    - internal-ip

$ kubectl apply https://gitee.com/jack_zang/kubernetes/raw/master/lb/install-v0.13.7/metallb-l2advertisement.yaml

3. 验证

$ kubectl get pods -n metallb-system
NAME                          READY   STATUS    RESTARTS   AGE
controller-6c58495cbb-h589v   1/1     Running   0          101s
speaker-dt42c                 1/1     Running   0          101s
speaker-n7k6x                 1/1     Running   0          101s
speaker-rfgnx                 1/1     Running   0          101s
作者:jackzang  创建时间:2022-10-20 18:01
最后编辑:jackzang  更新时间:2024-08-01 15:36