apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
metadata:
  name: istio
spec:
  controllerName: istio.io/gateway-controller
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
  name: gateway
  namespace: istio-system
spec:
  addresses:
  - value: istio-ingressgateway
    type: Hostname
  gatewayClassName: istio
  listeners:
  - name: default
    hostname: "*.domain.example"
    port: 80
    protocol: HTTP
    allowedRoutes:
      namespaces:
        from: All
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: http
  namespace: default
spec:
  parentRefs:
  - name: gateway
    namespace: istio-system
  hostnames: ["first.domain.example", "another.domain.example"]
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /get
      headers:
      - name: my-header
        value: some-value
        type: Exact
    filters:
    - type: RequestHeaderModifier
      requestHeaderModifier:
        add:
        - name: my-added-header
          value: added-value
        remove: [my-removed-header]
    - type: ResponseHeaderModifier
      responseHeaderModifier:
        add:
        - name: my-added-resp-header
          value: added-resp-value
        remove: [my-removed-header]
    backendRefs:
    - name: httpbin
      port: 80
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: http2
  namespace: default
spec:
  parentRefs:
  - name: gateway
    namespace: istio-system
  hostnames: ["second.domain.example"]
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /second
    backendRefs:
    - name: httpbin-second
      port: 80
  - matches:
    - path:
        type: PathPrefix
        value: /
    backendRefs:
    - name: httpbin-wildcard
      port: 80
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: redirect
  namespace: default
spec:
  parentRefs:
  - name: gateway
    namespace: istio-system
  rules:
  - filters:
    - type: RequestRedirect
      requestRedirect:
        port: 8080
        statusCode: 302
        scheme: https
        path:
          type: ReplaceFullPath
          replaceFullPath: /replace-full
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: redirect-prefix-replace
  namespace: default
spec:
  parentRefs:
  - name: gateway
    namespace: istio-system
  hostnames: ["redirect.domain.example"]
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /original
    filters:
    - type: RequestRedirect
      requestRedirect:
        port: 8080
        statusCode: 302
        scheme: https
        path:
          type: ReplacePrefixMatch
          replacePrefixMatch: /replacement
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: rewrite
  namespace: default
spec:
  parentRefs:
  - name: gateway
    namespace: istio-system
  rules:
  - name: route1
    matches:
    - path:
        type: PathPrefix
        value: /prefix-original
    filters:
    - type: URLRewrite
      urlRewrite:
        hostname: "new.example.com"
        path:
          type: ReplacePrefixMatch
          replacePrefixMatch: "/replacement"
    backendRefs:
    - name: httpbin
      port: 80
  - matches:
    - path:
        type: PathPrefix
        value: /prefix-to-be-removed
    filters:
    - type: URLRewrite
      urlRewrite:
        path:
          type: ReplacePrefixMatch
          replacePrefixMatch: ""
    backendRefs:
    - name: httpbin
      port: 80
  - matches:
    - path:
        type: PathPrefix
        value: /full-original
    filters:
    - type: URLRewrite
      urlRewrite:
        hostname: "new.example.com"
        path:
          type: ReplaceFullPath
          replaceFullPath: "/replacement"
    backendRefs:
    - name: httpbin
      port: 80
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: mirror
  namespace: default
spec:
  parentRefs:
  - name: gateway
    namespace: istio-system
  rules:
  - filters:
    - type: RequestMirror
      requestMirror:
        fraction:
          numerator: 4
          denominator: 8
        backendRef:
          name: httpbin-mirror
          port: 80
    - type: RequestMirror
      requestMirror:
        percent: 80
        backendRef:
          name: httpbin-second
          port: 80
    backendRefs:
    - name: httpbin
      port: 80
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: http-not-selected
  namespace: default
spec:
  parentRefs:
  - name: gateway
    namespace: istio-system
  hostnames: ["should.not.select"]
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /get
    backendRefs:
    - name: httpbin-bad
      port: 80
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: http-timeout-request
  namespace: default
spec:
  parentRefs:
  - name: gateway
    namespace: istio-system
  hostnames: ["timeout.domain.example"]
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /get
    backendRefs:
    - name: httpbin
      port: 80
    timeouts:
      request: 1ms
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: http-timeout-backend-request
  namespace: default
spec:
  parentRefs:
  - name: gateway
    namespace: istio-system
  hostnames: ["timeout-backend.domain.example"]
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /get
    backendRefs:
    - name: httpbin
      port: 80
    timeouts:
      request: 2ms
      backendRequest: 1ms
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: http-retry-request
  namespace: default
spec:
  parentRefs:
    - name: gateway
      namespace: istio-system
  hostnames: ["retry.domain.example"]
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /explicit
      backendRefs:
        - name: httpbin
          port: 80
      retry:
        attempts: 3
        backoff: 3ms
        codes:
        - 503
        - 429
    - matches:
        - path:
            type: PathPrefix
            value: /empty
      backendRefs:
        - name: httpbin
          port: 80
      retry: {}
    - matches:
        - path:
            type: PathPrefix
            value: /disable
      backendRefs:
        - name: httpbin
          port: 80
      retry:
        attempts: 0
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: http-route-cors
  namespace: default
spec:
  hostnames:
  - "cors.domain.example"
  parentRefs:
    - name: gateway
      namespace: istio-system
  rules:
    - backendRefs:
        - kind: Service
          name: httpbin
          port: 80
      filters:
        - cors:
            allowCredentials: true
            allowOrigins:
            # - '*' # This will be allowed in the future, probably https://github.com/kubernetes-sigs/gateway-api/issues/3648#issuecomment-2735208553
            # - '*.com'
              - "https://example.com"
            allowMethods:
              - GET
              - HEAD
              - POST
            allowHeaders:
              - Accept
              - Accept-Language
              - Content-Language
              - Content-Type
              - Range
          type: CORS
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: multiple-inferencepool-backend-refs
  namespace: default
spec:
  parentRefs:
    - name: gateway
      namespace: istio-system
  hostnames: ["infpool-multi.domain.example"]
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /infpool
          headers:
          - name: my-header
            value: some-value
            type: Exact
      backendRefs:
        - name: infpool-gen
          group: inference.networking.k8s.io
          kind: InferencePool
          port: 80
    - matches:
        - path:
            type: PathPrefix
            value: /infpool
          headers:
          - name: my-header
            value: some-value-2
            type: Exact
      backendRefs:
        - name: infpool-gen2
          group: inference.networking.k8s.io
          kind: InferencePool
          port: 80
---
apiVersion: inference.networking.k8s.io/v1
kind: InferencePool
metadata:
  name: infpool-gen
  namespace: default
spec:
  targetPorts:
  - number: 8000
  selector:
    matchLabels:
      app: vllm-llama3-8b-instruct
  endpointPickerRef:
    name: vllm-llama3-8b-instruct-epp
    port:
      number: 9002
---
apiVersion: inference.networking.k8s.io/v1
kind: InferencePool
metadata:
  name: infpool-gen2
  namespace: default
spec:
  targetPorts:
  - number: 8000
  selector:
    matchLabels:
      app: vllm-llama3-8b-instruct
  endpointPickerRef:
    name: vllm-llama3-8b-instruct-epp
    port:
      number: 9002
