带有多个版本的单个服务的istio负载平衡

时间:2018-07-25 09:17:50

标签: kubernetes istio

我能够通过istio示例应用程序实现负载平衡

  1. https://github.com/piomin/sample-istio-services
  2. https://istio.io/docs/guides/bookinfo/

但是无法使用具有2个版本的单个私有服务来实现istio负载平衡。示例:2个具有不同版本的领事服务器。

服务和广告连播定义:

apiVersion: v1
kind: Service
metadata:
  name: consul-test
  labels:
    app: test
spec:
  ports:
  - port: 8500
    name: http
  selector:
    app: test
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: consul-test-v1
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: test
        version: v1
    spec:
      containers:
      - name: consul-test-v1
        image: consul:latest
        ports:
        - containerPort: 8500
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: consul-test-v2
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: test
        version: v2
    spec:
      containers:
      - name: consul-test-v2
        image: consul:1.1.0
        ports:
        - containerPort: 8500

网关定义:

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: http-gateway
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: con-gateway
spec:
  hosts:
  - "*"
  gateways:
  - http-gateway
  http:
  - match:
    - uri:
        exact: /catalog
    route:
    - destination:
        host: consul-test
        port:
          number: 8500

虚拟服务中的路由规则:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: consul-test
spec:
  hosts:
  - consul-test
  gateways:
  - con-gateway
  - mesh
  http:
  - route:
    - destination:
        host: consul-test
        subset: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: consul-test
spec:
  host: consul-test
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2

尽管我将所有流量(http请求)路由到consul服务器版本v1,但我在consul-service上的http请求却交替出现在v1和v2上,即遵循循环规则。

$ kubectl get svc
NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
consul-test      ClusterIP   10.97.200.140    <none>        8500/TCP         9m

$ curl -L http://10.97.200.140:8500/v1/catalog/nodes
[
    {
        "ID": "ebfa341b-4557-a392-9f8a-8ee307113faa",
        "Node": "consul-test-v1-765dd566dd-6cmj9",
        "Address": "127.0.0.1",
        "Datacenter": "dc1",
        "TaggedAddresses": {
            "lan": "127.0.0.1",
            "wan": "127.0.0.1"
        },
        "Meta": {
            "consul-network-segment": ""
        },
        "CreateIndex": 9,
        "ModifyIndex": 10
    }
]
$ curl -L http://10.97.200.140:8500/v1/catalog/nodes
[
    {
        "ID": "1b60a5bd-9a17-ff18-3a65-0ff95b3a836a",
        "Node": "consul-test-v2-fffd475bc-st4mv",
        "Address": "127.0.0.1",
        "Datacenter": "dc1",
        "TaggedAddresses": {
            "lan": "127.0.0.1",
            "wan": "127.0.0.1"
        },
        "Meta": {
            "consul-network-segment": ""
        },
        "CreateIndex": 5,
        "ModifyIndex": 6
    }
]

1 个答案:

答案 0 :(得分:0)

在服务ClusterIP:ClusterPort上完成卷曲时,我遇到了上述问题

$ kubectl get svc
NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
consul-test      ClusterIP   10.97.200.140    <none>        8500/TCP         9m

$ curl -L http://10.97.200.140:8500/v1/catalog/nodes

但是在INGRESS_HOST和INGRESS_PORT上进行卷发(确定INGRESS_HOST和INGRESS_PORT存在here)时,LoadBalancing可以按预期工作

$ curl -L http:// $ INGRESS_HOST:$ INGRESS_PORT / v1 / catalog / nodes ---工作