入口控制器可以使用基于选择器的规则吗? [英] Can Ingress Controllers use Selector based rules?

查看:64
本文介绍了入口控制器可以使用基于选择器的规则吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在AKS中部署了一个有状态集-我的目标是为我的有状态集负载均衡流量.

根据我的理解,我可以定义一个LoadBalancer服务,该服务可以基于选择器来路由流量,诸如此类.

  apiVersion:v1种类:服务元数据:名称:nginx标签:应用程式:nginx规格:类型:LoadBalancer端口:港口:80名称:网络选择器:应用程式:nginx 

但是我不想沿着LoadBalance路线走,我更希望Ingress为我完成这项工作,我的问题是,任何Ingress控制器都可以支持路由规则吗,该规则可以基于选择器对端点进行基于路径的路由?而不是路由到其他服务.

更新要详细说明该场景-我的statefulset中的每个pod是一个无状态节点,负责HTTP提要的数据处理.我希望我的Ingress服务能够在这些有状态集Pod(尊重保持活动状态)之间负载均衡流量,但是考虑到k8中有状态集的性质,它们目前是通过无头服务公开的.我不确定无头服务是否可以负载均衡状态集的流量?

更新2 快速搜索显示无头服务没有 没有 负载均衡

有时您不需要负载平衡和单个服务IP.在这种情况下,您可以创建所谓的无头"广告素材.通过显式地指定无"服务,可以将服务指定为无".群集IP(.spec.clusterIP).

解决方案

我不确定无头服务是否可以平衡状态集的流量?

第一个答案是否".为什么?

k8s服务由kube-proxy实现.Kube-proxy本身可以在两种模式下工作:

  1. iptables(也称为netfilter)
  2. ipvs(也称为LVS/Linux虚拟服务器)

在iptables模式下进行负载平衡是NAT iptables规则:从ClusterIP地址到端点列表

在ipvs模式下的负载均衡是将端点作为上游的VIP(LVS虚拟IP)

因此,当您在将clusterIP设置为None的情况下创建k8s服务时,您的意思就是:

我需要此服务没有负载平衡"

将clusterIP设置为None会导致kube-proxy 不创建 iptables模式下的NAT规则,VIP处于ipvs模式下.在此特定服务选择器选择的Pod上,流量负载平衡将一无所有

第二个答案是可能是".为什么?

您可以使用所需的广告连播选择器自由创建无头服务.对该服务的DNS查询将返回所选Pod的DNS A记录的列表.然后,您可以使用此数据以您的方式

实施负载均衡

I have deployed a statefulset in AKS - My goal is to load balance traffic to my statefulset.

From my understanding I can define a LoadBalancer Service that can route traffic based on Selectors, something like this.

apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  type: LoadBalancer
  ports:
  - port: 80
    name: web
  selector:
    app: nginx

However I don't want to necessarily go down the LoadBalance route and I would prefer Ingress doing this work for me, My question is can any of the ingress controller support routing rules which can do Path based routing to endpoints based on selectors? Instead of routing to another service.

Update To elaborate more on the scenario - Each pod in my statefulset is a stateless node doing data processing of a HTTP feed. I want my ingress service to be able to load balance traffic across these statefulset pods ( honoring keep-alives etc), however given the nature of statefulsets in k8s they are currently exposed through a headless service. I am not sure if a headless service can load balance traffic to my statefulsets?

Update 2 Quick search reveals headless service does not loadbalance

Sometimes you don't need load-balancing and a single Service IP. In this case, you can create what are termed "headless" Services, by explicitly specifying "None" for the cluster IP (.spec.clusterIP).

解决方案

I am not sure if a headless service can load balance traffic to my statefulsets?

The first answer is "no". Why?

k8s Service is implemented by the kube-proxy. Kube-proxy itself can work in two modes:

  1. iptables (also known as netfilter)
  2. ipvs (also known as LVS/Linux Virtual Server)

load balancing in case of iptables mode is a NAT iptables rule: from ClusterIP address to the list of Endpoints

load balancing in case of ipvs mode is a VIP (LVS Virtual IP) with the Endpoints as upstreams

So, when you create k8s Service with clusterIP set to None you are exactly saying:

"I need this service WITHOUT load balancing"

Setting up the clusterIP to None causes kube-proxy NOT TO CREATE NAT rule in iptables mode, VIP in ipvs mode. There will be nothing for traffic load balancing across the pods selected by this particular Service selector

The second answer is "it could be". Why?

You are free to create headless Service with desired pods selector. DNS query to this Service will return the list of DNS A records for selected pods. Then you can use this data to implement load balancing YOUR way

这篇关于入口控制器可以使用基于选择器的规则吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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