Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
223 views
in Technique[技术] by (71.8m points)

linux - MetalLB works only in master Node, cant reach ip assigned from workers

I've sucessfully installed MetalLB on my Bare Metal Kubernetes cluster, but only pods assigned to the master Node seems to work.

MLB is configured on layer2, in the range of 192.168.0.100-192.168.0.200, and pods do get an IP when assigned to worker nodes, but those ips do not respond to any request.

If the assigned ip is curled inside the node, it works, yet if its curled from another node or machine, it doesnt respond.

Example:

# kubectl get pods -o wide
NAME                       READY   STATUS    RESTARTS   AGE     IP            NODE                  NOMINATED NODE   READINESS GATES
nginx2-658ffbbcb6-w5w28    1/1     Running   0          4m51s   10.244.1.2    worker2.homelab.com   <none>           <none>
nginx21-65b87bcbcb-fv856   1/1     Running   0          4h32m   10.244.0.10   master1.homelab.com   <none>           <none>

# kubectl get svc
NAME         TYPE           CLUSTER-IP       EXTERNAL-IP     PORT(S)        AGE
kubernetes   ClusterIP      10.96.0.1        <none>          443/TCP        5h49m
nginx2       LoadBalancer   10.111.192.206   192.168.0.111   80:32404/TCP   5h21m
nginx21      LoadBalancer   10.108.222.125   192.168.0.113   80:31387/TCP   4h43m

# kubectl get nodes -o wide
NAME                  STATUS   ROLES                  AGE     VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION                CONTAINER-RUNTIME
master1.homelab.com   Ready    control-plane,master   5h50m   v1.20.2   192.168.0.20   <none>        CentOS Linux 7 (Core)   3.10.0-1160.15.2.el7.x86_64   docker://20.10.3
worker2.homelab.com   Ready    <none>                 10m     v1.20.2   192.168.0.22   <none>        CentOS Linux 7 (Core)   3.10.0-1160.15.2.el7.x86_64   docker://20.10.3

Deployment nginx2 (Worker2, the one that doest work)

 kubectl describe svc nginx2
Name:                     nginx2
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=nginx2
Type:                     LoadBalancer
IP:                       10.111.192.206
LoadBalancer Ingress:     192.168.0.111
Port:                     http  80/TCP
TargetPort:               80/TCP
NodePort:                 http  32404/TCP
Endpoints:                10.244.1.2:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason        Age                  From             Message
  ----    ------        ----                 ----             -------
  Normal  nodeAssigned  10m (x6 over 5h23m)  metallb-speaker  announcing from node "master1.homelab.com"
  Normal  nodeAssigned  5m18s                metallb-speaker  announcing from node "worker2.homelab.com"


[root@worker2 ~]# curl 192.168.0.111
<!DOCTYPE html> ..... (Works)


[root@master1 ~]# curl 192.168.0.111
curl: (7) Failed connect to 192.168.0.111:80; No route to host
                       

Deployment nginx21 (Master1, the one that works)

 kubectl describe svc nginx21
Name:                     nginx21
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=nginx21
Type:                     LoadBalancer
IP:                       10.108.222.125
LoadBalancer Ingress:     192.168.0.113
Port:                     http  80/TCP
TargetPort:               80/TCP
NodePort:                 http  31387/TCP
Endpoints:                10.244.0.10:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason        Age                  From             Message
  ----    ------        ----                 ----             -------
  Normal  nodeAssigned  12m (x3 over 4h35m)  metallb-speaker  announcing from node "master1.homelab.com"



[root@worker2 ~]# curl 192.168.0.113
<!DOCTYPE html> ..... (Works)

[root@master1 ~]# curl 192.168.0.113
<!DOCTYPE html> ..... (Works)

--------- PING WORKS FROM OTHER MACHINES ----------

I've just found out this, so it might be a problem with iptables? i dont really know how it works on MetalLB, i can ping the ip (192.168.0.111) from other machines and it responds

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

i figured out, after Matt response, it was the firewall that was blocking the access, so i just simply added the whole network to the port 80 and it worked.

[root@worker2 ~]# firewall-cmd --new-zone=kubernetes --permanent
success
[root@worker2 ~]# firewall-cmd --zone=kubernetes --add-source=192.168.0.1/16 --permanent
success
[root@worker2 ~]# firewall-cmd --zone=kubernetes --add-port=80/tcp --permanent
success
[root@worker2 ~]# firewall-cmd --reload

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...