流量管理 FAQ

如何查看当前配置在 Istio 中的路由规则?

可以使用命令 kubectl get virtualservice -o yaml 查看规则。

可以使用标准的 ingress 规范而不使用任何路由规则吗?

简单的 ingress 规范,包括主机,TLS 和基于路径的精确匹配,无需路由规则即可正常工作。但需要注意,ingress 资源中使用的路径不能包含任何 “.” 字符。

例如,以下 ingress 资源匹配 example.com 主机的请求,其中 /helloworld 为 URL。

$ kubectl create -f - <<EOF
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: simple-ingress
annotations:
  kubernetes.io/ingress.class: istio
spec:
rules:
- host: example.com
  http:
    paths:
    - path: /helloworld
      backend:
        serviceName: myservice
        servicePort: grpc
EOF

但是,以下的规则不能正常工作,因为在路径和 ingress.kubernetes.io 注释中使用了正则表达式:

$ kubectl create -f - <<EOF
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: this-will-not-work
annotations:
  kubernetes.io/ingress.class: istio
  # Ingress annotations other than ingress class will not be honored
  ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: example.com
  http:
    paths:
    - path: /hello(.*?)world/
      backend:
        serviceName: myservice
        servicePort: grpc
EOF
程序部署文件中的端口命名约定是怎么样的?

命名端口:服务端口必须进行命名。

为利用 Istio 的路由功能,端口名称必须是 protocol-suffix 形式,其中 protocol 可为 grpchttphttp2httpsmongoredistcptlsudp

例如,name: http2-fooname: http 是有效的端口名称,但 name:http2foo 则不是。如果端口名称以不识别的前缀开头,或者端口未命名,则端口上的流量将被视为普通 TCP 流量(除非端口明确指定了使用协议:UDP 表示 UDP 端口)。