Kubernetes中的默认负载平衡 [英] Default Load Balancing in Kubernetes

查看:83
本文介绍了Kubernetes中的默认负载平衡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用Kubernetes集群.我们集群中给定Kubernetes服务的网络呼叫流程如下所示:

I've recently started working with Kubernetes clusters. The flow of network calls for a given Kubernetes service in our cluster is something like the following:

外部非K8S负载均衡器->入口控制器->入口资源->服务->吊舱

External Non-K8S Load Balancer -> Ingress Controller -> Ingress Resource -> Service -> Pod

对于给定的服务,有两个副本.通过查看副本中容器的日志,我可以看到调用被路由到不同的Pod.据我所知,我们还没有在Kubernetes中为我们的服务在任何地方显式设置任何负载平衡策略.

For a given service, there are two replicas. By looking at the logs of the containers in the replicas, I can see that calls are being routed to different pods. As far as I can see, we haven't explicitly set up any load-balancing policies anywhere for our services in Kubernetes.

我有几个问题:

1)K8S是否有默认的负载平衡策略?我已经阅读了有关kube-proxy和随机路由的信息.绝对不是循环式的. 2)是否有一种明显的方法可以在Ingress资源本身中指定负载平衡规则?在每个服务的基础上?

1) Is there a default load-balancing policy for K8S? I've read about kube-proxy and random routing. It definitely doesn't appear to be round-robin. 2) Is there an obvious way to specify load balancing rules in the Ingress resources themselves? On a per-service basis?

查看我们的Ingress资源之一,我可以看到'loadBalancer'属性为空:

Looking at one of our Ingress resources, I can see that the 'loadBalancer' property is empty:

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
ingress.kubernetes.io/rewrite-target: /
kubectl.kubernetes.io/last-applied-configuration: |
  {"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"annotations":{"ingress.kubernetes.io/rewrite-target":"/","nginx.ingress.kubernetes.io/rewrite-target":"/"},"name":"example-service-ingress","namespace":"member"},"spec":{"rules":[{"host":"example-service.x.x.x.example.com","http":{"paths":[{"backend":{"serviceName":"example-service-service","servicePort":8080},"path":""}]}}]}}
nginx.ingress.kubernetes.io/rewrite-target: /
  creationTimestamp: "2019-02-13T17:49:29Z"
  generation: 1
  name: example-service-ingress
  namespace: x
  resourceVersion: "59178"
  selfLink: /apis/extensions/v1beta1/namespaces/x/ingresses/example-service-ingress
  uid: b61decda-2fb7-11e9-935b-02e6ca1a54ae
spec:
  rules:
  - host: example-service.x.x.x.example.com
    http:
      paths:
      - backend:
          serviceName: example-service-service
          servicePort: 8080
status:
  loadBalancer:
    ingress:
    - {}

我应该指定-我们正在使用本地Kubernetes集群,而不是在云上.

I should specify - we're using an on-prem Kubernetes cluster, rather than on the cloud.

干杯!

推荐答案

The "internal load balancing" between Pods of a Service has already been covered in this question from a few days ago.

Ingress实际上并没有做任何特别的事情(除非您一直在使用它使用的NGINX配置进行黑客攻击)-它将使用与链接的问题相同的服务规则.

Ingress isn't really doing anything special (unless you've been hacking in the NGINX config it uses) - it will use the same Service rules as in the linked question.

如果您想要或需要对Pod如何在服务内路由的方式进行细粒度控制,则可以扩展Kubernetes的功能-我建议您研究

If you want or need fine-grained control of how pods are routed to within a service, it is possible to extend Kubernetes' features - I recommend you look into the traffic management features of Istio, as one of its features is to be able to dynamically control how much traffic different pods in a service receive.

这篇关于Kubernetes中的默认负载平衡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆