Calico在我的k8s上运行良好,但无法在该节点上Ping clusterip

问题描述

我已根据official website上的步骤安装了calico,它可以正常运行,并且日志中未报告任何错误。但是,当我对clusterip进行Ping操作时,Ping操作失败,并且Pod日志中没有错误,因此无法找到问题所在。 有

root@qhwk-k8s-master-0:/work/k8s/calico-v3.16.3# kcp -n calico-system
NAME                                       READY   STATUS    RESTARTS   AGE   IP               NODE                NOMINATED NODE   READInesS GATES
calico-kube-controllers-6bbcdcb447-kcb4k   1/1     Running   7          23m   192.168.74.193   qhwk-k8s-node-2     <none>           <none>
calico-node-5spbv                          1/1     Running   0          23m   10.58.221.192    qhwk-k8s-master-0   <none>           <none>
calico-node-f5xfn                          1/1     Running   0          23m   10.58.221.47     qhwk-k8s-master-1   <none>           <none>
calico-node-fgbsc                          1/1     Running   0          23m   10.58.221.50     qhwk-k8s-node-0     <none>           <none>
calico-node-mfxpv                          1/1     Running   0          23m   10.58.221.153    qhwk-k8s-master-2   <none>           <none>
calico-node-pnksj                          1/1     Running   0          23m   10.58.221.52     qhwk-k8s-node-2     <none>           <none>
calico-node-rhbjt                          1/1     Running   0          23m   10.58.221.132    qhwk-k8s-node-1     <none>           <none>
calico-typha-66865d84cf-629ws              1/1     Running   0          21m   10.58.221.153    qhwk-k8s-master-2   <none>           <none>
calico-typha-66865d84cf-77z2q              1/1     Running   0          23m   10.58.221.132    qhwk-k8s-node-1     <none>           <none>
calico-typha-66865d84cf-f49kw              1/1     Running   0          21m   10.58.221.52     qhwk-k8s-node-2     <none>           <none>
calico-typha-66865d84cf-jwhq5              1/1     Running   0          21m   10.58.221.50     qhwk-k8s-node-0     <none>           <none>
root@qhwk-k8s-master-0:/work/k8s/calico-v3.16.3# kc get svc
NAME                    TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                                      AGE
centos-service          ClusterIP   172.18.173.199   <none>        80/TCP                                       120m
default-http-backend    ClusterIP   172.18.28.240    <none>        80/TCP                                       4h42m
gateway-Nginx-service   ClusterIP   172.18.190.4     <none>        80/TCP                                       5h18m
nacos-service           ClusterIP   172.18.160.214   <none>        80/TCP                                       5h42m
nginx-ingress-service   NodePort    172.18.236.7     <none>        80:30080/TCP,443:30081/TCP,18080:31648/TCP   4h42m
Nginx-service           ClusterIP   172.18.89.51     <none>        80/TCP                                       135m
root@qhwk-k8s-master-0:/work/k8s/calico-v3.16.3# ping 172.18.190.4
PING 172.18.190.4 (172.18.190.4) 56(84) bytes of data.
^C
--- 172.18.190.4 ping statistics ---
2 packets transmitted,0 received,100% packet loss,time 1007ms

root@qhwk-k8s-master-0:/work/k8s/calico-v3.16.3# ping 172.18.173.199
PING 172.18.173.199 (172.18.173.199) 56(84) bytes of data.
^C
--- 172.18.173.199 ping statistics ---
4 packets transmitted,time 3023ms

root@qhwk-k8s-master-0:/work/k8s/calico-v3.16.3#

从下面的操作记录中可以看出,curl serviceip和curl podip都不在节点上工作。但是,如果您输入Pod,serviceip和podip都可以通过curl连接起来

root@qhwk-k8s-master-0:~# kc get svc -n bn-public
NAME                    TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                                      AGE
centos-service          ClusterIP   172.18.173.199   <none>        80/TCP                                       6h12m
default-http-backend    ClusterIP   172.18.28.240    <none>        80/TCP                                       8h
gateway-Nginx-service   ClusterIP   172.18.190.4     <none>        80/TCP                                       9h
nacos-service           ClusterIP   172.18.160.214   <none>        80/TCP                                       9h
nginx-ingress-service   NodePort    172.18.236.7     <none>        80:30080/TCP,18080:31648/TCP   8h
Nginx-service           ClusterIP   172.18.89.51     <none>        80/TCP                                       6h27m
root@qhwk-k8s-master-0:~# kc get pods -o wide -n bn-public 
NAME                                        READY   STATUS             RESTARTS   AGE     IP               NODE              NOMINATED NODE   READInesS GATES
default-http-backend-84489c7cf-7cdgl        1/1     Running            0          8h      192.168.74.213   qhwk-k8s-node-2   <none>           <none>
default-http-backend-84489c7cf-8kdg6        1/1     Running            0          8h      192.168.21.206   qhwk-k8s-node-1   <none>           <none>
default-http-backend-84489c7cf-94hrk        1/1     Running            0          8h      192.168.21.207   qhwk-k8s-node-1   <none>           <none>
default-http-backend-84489c7cf-cqmv4        1/1     Running            0          8h      192.168.35.212   qhwk-k8s-node-0   <none>           <none>
gateway-Nginx-deploy-7f67dc9c75-f5x56       1/2     CrashLoopBackOff   103        9h      192.168.35.210   qhwk-k8s-node-0   <none>           <none>
nacos-deploy-795df8675b-v4998               1/1     Running            0          9h      192.168.74.210   qhwk-k8s-node-2   <none>           <none>
networktool-nftnw                           1/1     Running            0          177m    192.168.21.193   qhwk-k8s-node-1   <none>           <none>
nginx-ingress-controller-77d68ddfc5-5qx5h   1/1     Running            0          8h      192.168.21.205   qhwk-k8s-node-1   <none>           <none>
nginx-ingress-controller-77d68ddfc5-dflvk   1/1     Running            0          8h      192.168.35.211   qhwk-k8s-node-0   <none>           <none>
nginx-ingress-controller-77d68ddfc5-njhmh   1/1     Running            0          8h      192.168.74.211   qhwk-k8s-node-2   <none>           <none>
nginx-ingress-controller-77d68ddfc5-pnlq9   1/1     Running            0          8h      192.168.74.212   qhwk-k8s-node-2   <none>           <none>
test-centos-864b48b597-nnnh4                1/1     Running            6          6h2m    192.168.74.214   qhwk-k8s-node-2   <none>           <none>
test-Nginx-6568c89cf-4tpq6                  1/1     Running            0          6h28m   192.168.21.208   qhwk-k8s-node-1   <none>           <none>
root@qhwk-k8s-master-0:~# ping  192.168.21.208
PING 192.168.21.208 (192.168.21.208) 56(84) bytes of data.
^C
--- 192.168.21.208 ping statistics ---
3 packets transmitted,time 2014ms

root@qhwk-k8s-master-0:~# curl   192.168.21.208
^C
root@qhwk-k8s-master-0:~# curl  172.18.89.51
^C
root@qhwk-k8s-master-0:~# kc get ep -n bn-public |grep Nginx
gateway-Nginx-service   <none>                                                                    9h
nginx-ingress-service   192.168.21.205:443,192.168.35.211:443,192.168.74.211:443 + 9 more...      8h
Nginx-service           192.168.21.208:80                                                         6h30m
root@qhwk-k8s-master-0:~# kc exec -it test-Nginx-6568c89cf-4tpq6 sh -n bn-public
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
# curl localhost             
<!DOCTYPE html>
<html>
<head>
<title>Welcome to Nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma,Verdana,Arial,sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to Nginx!</h1>
<p>If you see this page,the Nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://Nginx.org/">Nginx.org</a>.<br/>
Commercial support is available at
<a href="http://Nginx.com/">Nginx.com</a>.</p>

<p><em>Thank you for using Nginx.</em></p>
</body>
</html>
# curl Nginx-service
<!DOCTYPE html>
<html>
<head>
<title>Welcome to Nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma,the Nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://Nginx.org/">Nginx.org</a>.<br/>
Commercial support is available at
<a href="http://Nginx.com/">Nginx.com</a>.</p>

<p><em>Thank you for using Nginx.</em></p>
</body>
</html>
#

解决方法

它正在按设计方式工作-您无法ping服务的IP,因为它是virtual IP-它没有连接到任何网络接口,但是您可以卷曲它。只是一堆iptable规则,可以帮助在Pod之间转发流量。

但是您可以ping pod的IP。