【问题标题】:istio load balancing of a single service with multiple versions具有多个版本的单个服务的 istio 负载均衡
【发布时间】:2019-01-02 01:22:42
【问题描述】:

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

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

但无法让 istio 负载平衡与具有 2 个版本的单个私有服务一起工作。示例:2 个不同版本的领事服务器。

服务和 pod 定义:

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
    }
]

【问题讨论】:

  • 你能提供来自 pod 的日志吗?
  • 请在此处找到 pod 日志。 link

标签: kubernetes istio


【解决方案1】:

在服务 ClusterIP:ClusterPort 上完成 curl 后,我遇到了上述问题

$ 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 上完成 curl 时,LoadBalancing 会按预期工作(确定 INGRESS_HOST 和 INGRESS_PORT 存在 here

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

【讨论】:

  • 您将 INGRESS_HOST 指向什么?你能显示kubectl get po的输出吗?
  • $kubectl get po 显示了两个 pod,consul-test-v1-765dd566dd-6cmj9, consul-test-v2-fffd475bc-st4mv。 INGRESS_HOST 由“kubectl get po -l istio=ingressgateway -n istio-system -o 'jsonpath={.items[0].status.hostIP}' ”定义,指向主机外部IP。
  • 据我所知,一切正常。 ClusterIP 不是 Ingress_Host,Ingress 负责平衡请求和版本而不是集群。
猜你喜欢
  • 2021-01-27
  • 2021-03-17
  • 2019-05-25
  • 2021-07-21
  • 1970-01-01
  • 1970-01-01
  • 2021-09-30
  • 2014-06-08
  • 2021-01-10
相关资源
最近更新 更多