Istio Basic路由规则无法使其正常工作

时间:2018-10-02 13:10:18

标签: istio

我正在尝试设置路由规则,但无法正常工作。

istioctl版本:1.0.2 kubectl版本:客户端1.10.3 /服务器1.9.6

我有以下部署(下面的配置文件): 1.两个简单的烧瓶荚 2.一个NodePort服务 3.一个DestinationRule 4.一个VirtualService

部署完所有上述内容后,我仍然会从两个Pod中得到答复,而不仅仅是在VirtualService中定义的V1。 我想念什么吗?

吊舱1:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: flask-v1
spec:
  selector:
    matchLabels:
      app: flask
  replicas: 1
  template:
    metadata:
      labels:
        app: flask
        version: v1
    spec:
      containers:
      - name: flask
        image: simple-flask-example:1.0.0
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 5000

吊舱2:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: flask-v2
spec:
  selector:
    matchLabels:
      app: flask
  replicas: 1
  template:
    metadata:
      labels:
        app: flask
        version: v2
    spec:
      containers:
      - name: flask
        image: simple-flask-example:2.0.0
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 5000

服务节点端口:

apiVersion: v1
kind: Service
metadata:
  name: flask
  labels:
    app: flask
spec:
  type: NodePort
  ports:
  - port: 80
    name: http
    targetPort: 5000
  selector:
    app: flask

目的地规则:

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: flask
spec:
  host: flask
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2

VirtualService:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: flask
spec:
  hosts:
  - flask
  http:
  - route:
    - destination:
        host: flask
        subset: v1

请求测试:

>>> for x in range(10) : requests.request('GET','http://10.200.167.223').text
...
'{\n    "hello": "world v2"\n}\n'
'{\n    "hello": "world v2"\n}\n'
'{\n    "hello": "world v2"\n}\n'
'{\n    "hello": "world v1"\n}\n'
'{\n    "hello": "world v1"\n}\n'
'{\n    "hello": "world v2"\n}\n'
'{\n    "hello": "world v2"\n}\n'
'{\n    "hello": "world v1"\n}\n'
'{\n    "hello": "world v2"\n}\n'
'{\n    "hello": "world v1"\n}\n'

1 个答案:

答案 0 :(得分:2)

Istio路由规则(VirtualService规则)在客户端代理中执行,而不在目标服务中执行,因此,如果直接通过NodePort调用该服务,则不会执行任何Istio路由。您需要从另一个Istio服务或通过Istio网关调用它。

一种简单的测试服务路由的方法是使用 sleep sample作为客户。

或者,您可以为服务设置入口网关,例如here中描述的示例。