首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Istio流量拆分未正确使用权重

Istio流量拆分未正确使用权重
EN

Stack Overflow用户
提问于 2020-05-13 05:47:36
回答 1查看 300关注 0票数 2

我正在使用默认的bookinfo应用程序https://istio.io/docs/examples/bookinfo/,并尝试使用评论服务测试拆分流量。Kiali显示了拆分,一切似乎都配置正确,但它仍在进行循环调度。如果我删除所有虚拟服务和目的地规则,应用程序会正常工作。

代码语言:javascript
复制
# Source: bookinfo/templates/destination-rule-all.yaml
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: productpage
spec:
  host: productpage
  subsets:
  - name: v1
    labels:
      version: v1
---
# Source: bookinfo/templates/destination-rule-all.yaml
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: ratings
spec:
  host: ratings
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2
  - name: v2-mysql
    labels:
      version: v2-mysql
  - name: v2-mysql-vm
    labels:
      version: v2-mysql-vm
---
# Source: bookinfo/templates/destination-rule-all.yaml
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: details
spec:
  host: details
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2
---
# Source: bookinfo/templates/destination-rule-all.yaml
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: reviews
spec:
  host: reviews
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2
  - name: v3
    labels:
      version: v3
---
# Source: bookinfo/templates/bookinfo-gateway.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: bookinfo-gateway
  chart: bookinfo-0.1.2
  release: bookinfo
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---
# Source: bookinfo/templates/bookinfo-gateway.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: bookinfo
  chart: bookinfo-0.1.2
  release: bookinfo
spec:
  hosts:
  - "*"
  gateways:
  - bookinfo-gateway
  http:
  - match:
    - uri:
        exact: /productpage
    - uri:
        prefix: /static
    - uri:
        exact: /login
    - uri:
        exact: /logout
    - uri:
        prefix: /api/v1/products
    route:
    - destination:
        host: productpage
        port:
          number: 9080
---
# Source: bookinfo/templates/virtual-service-all-v1.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: productpage
spec:
  hosts:
  - productpage
  gateways:
  - bookinfo-gateway
  http:
  - route:
    - destination:
        host: productpage
        subset: v1
---
# Source: bookinfo/templates/virtual-service-all-v1.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
  - reviews
  gateways:
  - bookinfo-gateway
  http:
  - route:
    - destination:
        host: reviews
        subset: v1
      weight: 100
    - destination:
        host: reviews
        subset: v2
      weight: 0
    - destination:
        host: reviews
        subset: v3
      weight: 0
---
# Source: bookinfo/templates/virtual-service-all-v1.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: ratings
spec:
  hosts:
  - ratings
  gateways:
  - bookinfo-gateway
  http:
  - route:
    - destination:
        host: ratings
        subset: v1
---
# Source: bookinfo/templates/virtual-service-all-v1.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: details
spec:
  hosts:
  - details
  gateways:
  - bookinfo-gateway
  http:
  - route:
    - destination:
        host: details
        subset: v1

# Source: bookinfo/templates/reviews-v1-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: reviews-v1
  labels:
    chart: bookinfo-0.1.2
    release: bookinfo
    app: reviews
    version: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: reviews
      release: bookinfo
      version: v1
  template:
    metadata:
      labels:
        app: reviews
        release: bookinfo
        version: v1
    spec:
      serviceAccountName: bookinfo-reviews
      containers:
      - name: reviews
        image: myhub/istio/examples-bookinfo-reviews-v1:1.15.0
        imagePullPolicy: IfNotPresent
        env:
        - name: LOG_DIR
          value: "/tmp/logs"
        ports:
        - containerPort: 9080
        volumeMounts:
        - name: tmp
          mountPath: /tmp
        - name: wlp-output
          mountPath: /opt/ibm/wlp/output
      volumes:
      - name: wlp-output
        emptyDir: {}
      - name: tmp
        emptyDir: {}
---
# Source: bookinfo/templates/reviews-v2-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: reviews-v2
  labels:
    chart: bookinfo-0.1.2
    release: bookinfo
    app: reviews
    version: v2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: reviews
      release: bookinfo
      version: v2
  template:
    metadata:
      labels:
        app: reviews
        release: bookinfo
        version: v2
    spec:
      serviceAccountName: bookinfo-reviews
      containers:
      - name: reviews
        image: myhub/istio/examples-bookinfo-reviews-v2:1.15.0
        imagePullPolicy: IfNotPresent
        env:
        - name: LOG_DIR
          value: "/tmp/logs"
        ports:
        - containerPort: 9080
        volumeMounts:
        - name: tmp
          mountPath: /tmp
        - name: wlp-output
          mountPath: /opt/ibm/wlp/output
      volumes:
      - name: wlp-output
        emptyDir: {}
      - name: tmp
        emptyDir: {}
---
# Source: bookinfo/templates/reviews-v3-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  metadata:
  name: reviews-v3
  labels:
    chart: bookinfo-0.1.2
    release: bookinfo
    app: reviews
    version: v3
spec:
  replicas: 1
  selector:
    matchLabels:
      app: reviews
      release: bookinfo
      version: v3
  template:
    metadata:
      labels:
        app: reviews
        release: bookinfo
        version: v3
    spec:
      serviceAccountName: bookinfo-reviews
      containers:
      - name: ratings
        image: myhub/istio/examples-bookinfo-reviews-v3:1.15.0
        imagePullPolicy: IfNotPresent
        env:
        - name: LOG_DIR
          value: "/tmp/logs"
        ports:
        - containerPort: 9080
        volumeMounts:
        - name: tmp
          mountPath: /tmp
        - name: wlp-output
          mountPath: /opt/ibm/wlp/output
      volumes:
      - name: wlp-output
        emptyDir: {}
      - name: tmp
        emptyDir: {}
---

环境

kind v0.7.0 go1.13.6 linux/amd64

K8s v1.18.1 v1.17.0

EN

回答 1

Stack Overflow用户

发布于 2020-05-13 16:11:46

我试着用istio 1.5.2在gke上重现你的问题,一切正常。

我跟踪了istio bookinfo documentation

代码语言:javascript
复制
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml

如前所述,here

应用默认目标规则

在使用Istio控制Bookinfo版本路由之前,您需要在目标规则中定义可用版本,称为子集。

运行以下命令为Bookinfo服务创建默认目标规则:

如果您没有启用mutual TLS,请执行以下命令:

如果您不熟悉Istio并且正在使用演示配置文件,请选择此选项。

代码语言:javascript
复制
$ kubectl apply -f samples/bookinfo/networking/destination-rule-all.yaml

如果您启用了mutual TLS,请执行以下命令:

代码语言:javascript
复制
$ kubectl apply -f samples/bookinfo/networking/destination-rule-all-mtls.yaml

等待几秒钟以传播目标规则。

您可以使用以下命令显示目标规则:

代码语言:javascript
复制
$ kubectl get destinationrules -o yaml

应用您的虚拟服务进行评论

示例

仅用于子集v1的流量。

代码语言:javascript
复制
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
  - reviews
  http:
  - route:
    - destination:
        host: reviews
        subset: v1

仅用于子集v2的流量。

代码语言:javascript
复制
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
  - reviews
  http:
  - route:
    - destination:
        host: reviews
        subset: v2

子集v2和v3的流量权重为50/50。

代码语言:javascript
复制
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
  - reviews
  http:
  - route:
    - destination:
        host: reviews
        subset: v2
      weight: 50
    - destination:
        host: reviews
        subset: v3
      weight: 50

子集v1、v2和v3的100/0/0权重流量。

代码语言:javascript
复制
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
  - reviews
  http:
  - route:
    - destination:
        host: reviews
        subset: v2
      weight: 100
    - destination:
        host: reviews
        subset: v3
      weight: 0
    - destination:
        host: reviews
        subset: v1
      weight: 0

对于仅针对子集的虚拟服务,v1 Kiali显示流量仅流向v1

Istio productpage没有显示明星,所以它是review v1。

这里有一些关于weight-based routing的文档可供查阅。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61762589

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档