如何在istio中编写自定义入口网关?

时间:2019-06-21 09:34:35

标签: kubernetes kubernetes-ingress istio

我是istio的新手,我有一个简单的测试yaml文件,该文件有点长。我要做的是为我的网关编写一个自定义的ingressgateway服务。经过测试,不正确的部分是位于顶部的入口网关的定义。整个Yaml如下:

apiVersion: v1
kind: Service
metadata:
  name: batman-ingressgateway
  labels:
    app: batman-ingressgateway
spec:
  type: LoadBalancer
  selector:
    app: batman-ingressgateway
  ports:
  - port: 80
    targetPort: 80
    nodePort: 31389
    name: http
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: batman-gateway
spec:
  selector:
    app: batman-ingressgateway
      #istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: batman
spec:
  hosts:
  - "*"
  gateways:
  - batman-gateway
  http:
    - match:
      route:
      - destination:
          host: batman
          port:
            number: 8000
          subset: v1
        weight: 80
      - destination:
          host: batman
          port:
            number: 8000
          subset: v2
        weight: 20
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: batman-destination
spec:
  host: batman
  subsets:
  - name: v1
    labels:
      version: v1
      run: batman
  - name: v2
    labels:
      version: v2
      run: batman

我想从浏览器中访问地址为http://my_host_ip:31389/article的应用程序。现在的问题是Ingressgateway无法将流量路由到我的网关。有没有人可以帮助我? 谢谢。

1 个答案:

答案 0 :(得分:1)

有关istio网关路由的文档在https://istio.io/docs/tasks/traffic-management/ingress/ingress-control/

如果您查看网关规格的话,

selector: istio: ingressgateway # use Istio default gateway implementation

有空

selector: app: batman-ingressgateway #istio: ingressgateway

对于VirtualService定义,您可以在这里https://istio.io/docs/reference/config/networking/v1alpha3/virtual-service/中查看 您可以尝试将/ article的请求路由到您的服务

apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: article-route spec: hosts: - * http: - match: - uri: prefix: "/article" route: - destination: host: <name of your service>