无法在裸机kubernetes群集上获取外部IP

时间:2019-07-12 01:40:07

标签: docker kubernetes load-balancing bare-metal-server metallb

我正在尝试建立一个裸机Kubernetes集群。我已经设置了基本群集,没问题,但是我似乎无法让MetalLB正常工作以向服务公开外部IP。

我的最终目标是能够部署具有2个以上副本的应用程序,并具有一个IP /端口供我参考,以便访问任何正在运行的实例。

到目前为止,我所做的(为了对此进行测试)是:

kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.7.3/manifests/metallb.yaml
kubectl apply -f metallb-layer-2.yml
kubectl run nginx --image=nginx --port=80
kubectl expose deployment nginx --type=LoadBalancer --name=nginx-service

metallb-layer-2.yml:

apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    address-pools:
    - name: k8s-master-ip-space
      protocol: layer2
      addresses:
      - 192.168.0.240-192.168.0.250

然后运行kubectl get svc时,我得到:

NAME            TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
nginx-service   LoadBalancer   10.101.122.140   <pending>     80:30930/TCP     9m29s

无论我做什么,都无法获得具有外部IP的服务。有人有主意吗?

编辑:找到了有关使用NodePort的另一篇文章之后,我做了以下事情:

iptables -A FORWARD -j ACCEPT

找到了here

现在,不幸的是,当我尝试卷曲nginx端点时,我得到了:

> kubectl get svc
NAME            TYPE           CLUSTER-IP       EXTERNAL-IP       PORT(S)          AGE
nginx-service   LoadBalancer   10.101.122.140   192.168.0.240     80:30930/TCP     13h
> curl 192.168.0.240:30930
curl: (7) Failed to connect to 192.168.0.240 port 30930: No route to host
> curl 192.168.0.240:80
curl: (7) Failed to connect to 192.168.0.240 port 80: No route to host

我不确定这到底意味着什么。

编辑2: 当我在运行Pod的工作程序上执行TCP Dump时,我得到:

15:51:44.705699 IP 192.168.0.223.54602 > 192.168.0.240.http: Flags [S], seq 1839813500, win 29200, options [mss 1460,sackOK,TS val 375711117 ecr 0,nop,wscale 7], length 0
15:51:44.709940 ARP, Request who-has 192.168.0.240 tell 192.168.0.169, length 28
15:51:45.760613 ARP, Request who-has 192.168.0.240 tell 192.168.0.169, length 28
15:51:45.775511 IP 192.168.0.223.54602 > 192.168.0.240.http: Flags [S], seq 1839813500, win 29200, options [mss 1460,sackOK,TS val 375712189 ecr 0,nop,wscale 7], length 0
15:51:46.800622 ARP, Request who-has 192.168.0.240 tell 192.168.0.169, length 28
15:51:47.843262 IP 192.168.0.223.54602 > 192.168.0.240.http: Flags [S], seq 1839813500, win 29200, options [mss 1460,sackOK,TS val 375714257 ecr 0,nop,wscale 7], length 0
15:51:47.843482 ARP, Request who-has 192.168.0.240 tell 192.168.0.169, length 28
15:51:48.880572 ARP, Request who-has 192.168.0.240 tell 192.168.0.169, length 28
15:51:49.774953 ARP, Request who-has 192.168.0.240 tell 192.168.0.223, length 46
15:51:49.920602 ARP, Request who-has 192.168.0.240 tell 192.168.0.169, length 28

1 个答案:

答案 0 :(得分:1)

在与MetalLB维护人员联系后,他能够找出问题是Debian Buster的新nftables防火墙。要禁用,

# update-alternatives --set iptables /usr/sbin/iptables-legacy
# update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
# update-alternatives --set arptables /usr/sbin/arptables-legacy
# update-alternatives --set ebtables /usr/sbin/ebtables-legacy

然后重新启动集群中的节点!