下午好,我遇到了无法将 MetalLB 连接到 K3S 的问题。我有一个包含 3 个主服务器和 3 个工作服务器的集群
NAME STATUS ROLES AGE VERSION
master-node-1 Ready control-plane,etcd,master 4d2h v1.30.5+k3s1
master-node-2 Ready control-plane,etcd,master 4d1h v1.31.1+k3s1
master-node-3 Ready control-plane,etcd,master 4d1h v1.31.1+k3s1
worker-node-1 Ready <none> 4d1h v1.31.1+k3s1
worker-node-2 Ready <none> 4d v1.31.1+k3s1
worker-node-3 Ready <none> 4d v1.31.1+k3s1
最初,我尝试以这种方式安装 MetalLB
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/namespace.yaml
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/metallb.yaml
配置
# config.yml
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 192.168.0.170-192.168.0.180
这种方法虽然有效,但负载均衡器在水龙头上不稳定,有 50% 的概率无法进入网站。后来我发现这是一种过时的方法。我尝试了一种新方法
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.14.5/config/manifests/metallb-native.yaml
配置
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: k3s-lb-pool
namespace: metallb
spec:
addresses:
- 192.168.0.170-192.168.0.180
autoAssign: true
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: k3s-lb-pool
namespace: metallb
但我收到错误
Error from server (InternalError): error when creating "metalLB-config.yaml": Internal error occurred: failed calling webhook "ipaddresspoolvalidationwebhook.metallb.io": failed to call webhook: Post "https://metallb-webhook-service.metallb.svc:443/validate-metallb-io-v1beta1-ipaddresspool?timeout=10s": no endpoints available for service "metallb-webhook-service"
Error from server (InternalError): error when creating "metalLB-config.yaml": Internal error occurred: failed calling webhook "l2advertisementvalidationwebhook.metallb.io": failed to call webhook: Post "https://metallb-webhook-service.metallb.svc:443/validate-metallb-io-v1beta1-l2advertisement?timeout=10s": no endpoints available for service "metallb-webhook-service"
但命名空间仍然正常工作
root@master-node-1:~# kubectl get pod -n=metallb-system
NAME READY STATUS RESTARTS AGE
controller-86f5578878-9ddsr 1/1 Running 2 (3m31s ago) 4m57s
speaker-5j47x 1/1 Running 0 4m56s
speaker-6drpd 1/1 Running 0 4m56s
speaker-ccpmq 1/1 Running 0 4m56s
speaker-jfpch 1/1 Running 1 (3m12s ago) 4m56s
speaker-mps8b 1/1 Running 0 4m57s
speaker-t9lx2 1/1 Running 0 4m56s
(我提前道歉,英语不是我的母语)