【问题标题】:Load balancing is not working properly负载平衡无法正常工作
【发布时间】:2015-09-26 05:02:55
【问题描述】:

我们想测试 Kubernetes 负载平衡。因此,我们创建了一个运行 6 个容器副本的 2 节点集群。容器已经运行 apache2 服务器和 php,如果我们浏览 hostname.php,它将打印 pod 名称

集群详情: 172.16.2.92 -- 主人和仆从 172.16.2.91 -- 奴才

RC 和服务详情:

前端控制器.json:

{
   "kind":"ReplicationController",
   "apiVersion":"v1beta3",
   "metadata":{
      "name":"frontend",
      "labels":{
         "name":"frontend"
      }
   },
   "spec":{
      "replicas":6,
      "selector":{
         "name":"frontend"
      },
      "template":{
         "metadata":{
            "labels":{
               "name":"frontend"
            }
         },
         "spec":{
            "containers":[
               {
                  "name":"php-hostname",
                  "image":"naresht/hostname",
                  "ports":[
                     {
                        "containerPort":80,
                        "protocol":"TCP"
                     }
                  ]

               }
            ]
         }
      }
   }
}

前端服务.json:

{
   "kind":"Service",
   "apiVersion":"v1beta3",
   "metadata":{
      "name":"frontend",
      "labels":{
         "name":"frontend"
      }
   },

   "spec":{
      "createExternalLoadBalancer": true,
      "ports": [
        {
          "port":3000,
          "targetPort":80,
          "protocol":"TCP"
        }
      ],
      "publicIPs": [ "172.16.2.92"],
      "selector":{
         "name":"frontend"
      }
   }
}

Pod 详细信息: frontend-01bb8、frontend-svxfl 和 frontend-yki5s 在节点 172.16.2.91 上运行 frontend-65ykz 、 frontend-c1x0d 和 frontend-y925t 在节点 172.16.2.92 上运行

如果我们浏览 172.16.2.92:3000/hostname.php,它会打印 POD 名称。

问题:

在节点 172.16.2.92 上运行 watch -n1 curl 172.16.2.92:3000/hostname.php 只会给出 pod(frontend-65ykz 、 frontend-c1x0d 和 frontend-y925t )。他们没有显示其他节点 172.16.2.91 pod。 在节点 172.16.2.91 上运行相同的命令只会提供该 pod。他们没有显示其他节点 172.16.2.92 pod。 在集群外运行相同的命令仅显示 172.16.2.92 个 pod。 但是,如果我们在任何地方运行,我们希望查看所有 pod,而不是特定节点 pod。

查看以下详细信息以获取更多信息,如果有任何问题,请为您提供帮助

# kubectl 获取节点

NAME          LABELS                                           STATUS
172.16.2.91   kubernetes.io/hostname=172.16.2.91   Ready
172.16.2.92   kubernetes.io/hostname=172.16.2.92   Ready

# kubectl 获取 pod

POD              IP            CONTAINER(S)   IMAGE(S)                                         HOST                      LABELS                                                              STATUS    CREATED          MESSAGE
frontend-01bb8   172.17.0.84                                                                   172.16.2.91/172.16.2.91   name=frontend                                                       Running   About a minute
                               php-hostname   naresht/hostname                                                                                                                               Running   About a minute
frontend-65ykz   10.1.64.79                                                                    172.16.2.92/172.16.2.92   name=frontend                                                       Running   About a minute
                               php-hostname   naresht/hostname                                                                                                                               Running   About a minute
frontend-c1x0d   10.1.64.77                                                                    172.16.2.92/172.16.2.92   name=frontend                                                       Running   About a minute
                               php-hostname   naresht/hostname                                                                                                                               Running   About a minute
frontend-svxfl   172.17.0.82                                                                   172.16.2.91/172.16.2.91   name=frontend                                                       Running   About a minute
                               php-hostname   naresht/hostname                                                                                                                               Running   About a minute
frontend-y925t   10.1.64.78                                                                    172.16.2.92/172.16.2.92   name=frontend                                                       Running   About a minute
                               php-hostname   naresht/hostname                                                                                                                               Running   About a minute
frontend-yki5s   172.17.0.83                                                                   172.16.2.91/172.16.2.91   name=frontend                                                       Running   About a minute
                               php-hostname   naresht/hostname                                                                                                                               Running   About a minute
kube-dns-sbgma   10.1.64.11                                                                    172.16.2.92/172.16.2.92   k8s-app=kube-dns,kubernetes.io/cluster-service=true,name=kube-dns   Running   45 hours
                               kube2sky       gcr.io/google_containers/kube2sky:1.1                                                                                                          Running   45 hours
                               etcd           quay.io/coreos/etcd:v2.0.3                                                                                                                     Running   45 hours
                               skydns         gcr.io/google_containers/skydns:2015-03-11-001                                                                                                 Running   45 hours

# kubectl 获取服务

NAME            LABELS                                                              SELECTOR           IP(S)           PORT(S)
frontend        name=frontend                                                       name=frontend      192.168.3.184   3000/TCP
kube-dns        k8s-app=kube-dns,kubernetes.io/cluster-service=true,name=kube-dns   k8s-app=kube-dns   192.168.3.10    53/UDP
kubernetes      component=apiserver,provider=kubernetes                             <none>             192.168.3.2     443/TCP
kubernetes-ro   component=apiserver,provider=kubernetes                            <none>             192.168.3.1     80/TCP

# iptables -t nat -L

Chain KUBE-PORTALS-CONTAINER (1 references)
target     prot opt source               destination
REDIRECT   tcp  --  anywhere             192.168.3.184        /* default/frontend: */ tcp dpt:3000 redir ports 50734
REDIRECT   tcp  --  anywhere             kube02               /* default/frontend: */ tcp dpt:3000 redir ports 50734
REDIRECT   udp  --  anywhere             192.168.3.10         /* default/kube-dns: */ udp dpt:domain redir ports 52415
REDIRECT   tcp  --  anywhere             192.168.3.2          /* default/kubernetes: */ tcp dpt:https redir ports 33373
REDIRECT   tcp  --  anywhere             192.168.3.1          /* default/kubernetes-ro: */ tcp dpt:http redir ports 60311

Chain KUBE-PORTALS-HOST (1 references)
target     prot opt source               destination
DNAT       tcp  --  anywhere             192.168.3.184        /* default/frontend: */ tcp dpt:3000 to:172.16.2.92:50734
DNAT       tcp  --  anywhere             kube02               /* default/frontend: */ tcp dpt:3000 to:172.16.2.92:50734
DNAT       udp  --  anywhere             192.168.3.10         /* default/kube-dns: */ udp dpt:domain to:172.16.2.92:52415
DNAT       tcp  --  anywhere             192.168.3.2          /* default/kubernetes: */ tcp dpt:https to:172.16.2.92:33373
DNAT       tcp  --  anywhere             192.168.3.1          /* default/kubernetes-ro: */ tcp dpt:http to:172.16.2.92:60311

谢谢

【问题讨论】:

    标签: docker load-balancing kubernetes internal-load-balancer


    【解决方案1】:

    在我看来,问题在于网络配置。 主机 172.16.2.91 中的 Pod 的 IP 地址为 172.17.0.xx,可以从其他主机访问,即 172.16.2.92

    如果 ping 失败,请根据 kubernetes 要求检查您的网络: https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/networking.md Kubernetes 对任何网络实现都提出了以下基本要求(除非任何有意的网络分段策略): •所有容器都可以在没有NAT的情况下与所有其他容器通信 •所有节点都可以在没有NAT的情况下与所有容器通信(反之亦然) • 容器认为自己的 IP 与其他人认为的 IP 相同

    【讨论】:

      【解决方案2】:

      因为法兰绒不能正常工作,所以这样做

      每个节点上的/root/kube/reconfDocker.sh

      它将重新启动 docker 和 flannel,然后检查 ifconfig docker0 和 flannel0 网桥 IP 是否应该在同一个网络中。然后负载平衡将起作用。它对我有用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-30
        • 2017-04-02
        • 1970-01-01
        • 2020-11-28
        • 2010-11-04
        • 1970-01-01
        相关资源
        最近更新 更多