How to write a custom ingressgateway in istio?

6/21/2019

I'm new to istio, I have a simple test yaml file which is a little long. What I want to do is to write a custom ingressgateway service for my gateway. And after testing, the incorrect part is the definition of ingressgateway which is at the top. The entire yaml is below:

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

I want to access my app from browser with the address like: http://my_host_ip:31389/article. The problem now is the ingressgateway doesn't route traffic to my gateway. Is there any one can help me? Thanks.

-- leo
istio
kubernetes
kubernetes-ingress

1 Answer

6/29/2019

Documentation on istio gateway routing is here https://istio.io/docs/tasks/traffic-management/ingress/ingress-control/.

If you look at gateway spec they have

selector: istio: ingressgateway # use Istio default gateway implementation

While you have

selector: app: batman-ingressgateway #istio: ingressgateway

For VirtualService definition you can look here https://istio.io/docs/reference/config/networking/v1alpha3/virtual-service/ You can try with routing requests to /article to your service

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>

-- milosevic81
Source: StackOverflow