istio路由规则错误:" json:无法将字符串解组为Go值"

时间:2018-03-06 08:18:35

标签: istio

我是Istio的新手,我通过简单的应用程序查看了一些用例。

我在使用VirtualBox 5.2.6在Windows 10 Pro上运行的 minikube上部署了2个简单服务,其中istio为0.6.0

service1 的版本v1和v1& v2 of service2 。 service1响应/ hello,service2响应/ world。到目前为止一切正常,两项服务都是响应的,并且在服务2时,循环法正在运行。

现在我想应用2个路由规则,一个用于根据标头路由到service2的v2,其余用于service2的v1,但是当我尝试这样做时,我收到一个错误:

Error: cannot parse proto message: YAML decoding error: destination:
  name: service2
match:
  request:
    headers:
      Foo: bar
precedence: 2
route:
- labels:
    version: v2
 json: cannot unmarshal string into Go value of type map[string]json.RawMessage

请在下面找到我的应用和路由规则配置。

此配置有什么问题?

请注意,当我省略"匹配"它没关系,但当然这不是我想要的。

apiVersion: config.istio.io/v1alpha2
kind: RouteRule
metadata:
  name: service2-route
spec:
  destination:
    name: service2
  precedence: 2
  match:
    request:
      headers:
        Foo: bar
  route:
  - labels:
      version: v2
---
apiVersion: config.istio.io/v1alpha2
kind: RouteRule
metadata:
  name: service2-default
spec:
  destination:
    name: service2
  precedence: 1
  route:
  - labels:
      version: v1
    weight: 100

和我的服务部署yaml:

###########################################################################
# Service 1
##########################################################################
apiVersion: v1
kind: Service
metadata:
  name: service1
  labels:
    app: service1
spec:
  ports:
  - port: 8080
    name: http
  selector:
    app: service1
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: service1-v1
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: service1
        version: v1
    spec:
      containers:
      - name: service1
        image: myrepo/sampleapp-service1:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080
---
###########################################################################
# Service 2
##########################################################################
apiVersion: v1
kind: Service
metadata:
  name: service2
  labels:
    app: service2
spec:
  ports:
  - port: 8081
    name: http
  selector:
    app: service2
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: service2-v1
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: service2
        version: v1
    spec:
      containers:
      - name: service2
        image: myrepo/sampleapp-service2:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8081
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: service2-v2
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: service2
        version: v2
    spec:
      containers:
      - name: service2
        image: myrepo/sampleapp-service2:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8081
---
###########################################################################
# Ingress resource (gateway)
##########################################################################
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: gateway
  annotations:
    kubernetes.io/ingress.class: "istio"
spec:
  rules:
  - http:
      paths:
      - path: /hello
        backend:
          serviceName: service1
          servicePort: 8080
      - path: /world
        backend:
          serviceName: service2
          servicePort: 8081
---

1 个答案:

答案 0 :(得分:1)

这里的问题很简单,你必须说你想如何匹配你的标题。在您的示例中,我可以假设您想要完全匹配,因此使用以下语法:

  match:
    request:
      headers:
        Foo: 
          exact: bar

Here您可以找到更多可用选项。 如果你的标题值包含任何特殊字符,我还建议使用引号。