kubernetesgoogle-kubernetes-enginegatewaybucket

Load balance between GCP bucket and GKE


I have an GKE cluster with "Gateway" and "Httproute" resources like this.

kind: Gateway
apiVersion: gateway.networking.k8s.io/v1beta1
metadata:
  namespace: development
  name: dev-example-gateway
spec:
  gatewayClassName: gke-l7-global-external-managed
  listeners:
  - name: http
    protocol: HTTP
    port: 80

kind: HTTPRoute
apiVersion: gateway.networking.k8s.io/v1beta1
metadata:
  name: store
  namespace: development
spec:
  parentRefs:
  - kind: Gateway
    name: dev-example-gateway
  hostnames:
  - "gateway.example.com"
  rules:
  - backendRefs:
    - name: example-frontend-svc
      port: 3000
  - matches:
      - path:
          type: PathPrefix
          value: /api
    filters:
      - type: URLRewrite
        urlRewrite:
          hostname: gateway.example.com
          path:
            type: ReplacePrefixMatch
            replacePrefixMatch: /
    backendRefs:
      - name: example-backend-svc
        port: 2828

Also I have a GCP bucket that I want to pass traffic to. I have created backend bucket for that called "example-bucket". Added this code below to httproute resource`

  - matches:
      - path:
          type: PathPrefix
          value: /_next/static/
    filters:
      - type: URLRewrite
        urlRewrite:
          hostname: gateway.example.com
          path:
            type: ReplacePrefixMatch
            replacePrefixMatch: /static/
    backendRefs:
      - name: projects/example/global/backendBuckets/example-bucket
        port: 80

But it adds another backend for that, not the bucket, some autogenerated one called "gkegw1-bxdu-development-gw-serve404-80-s8c5ntyjhig9". The LB type I use supports backend buckets.

Tried this httproute configuration.

kind: HTTPRoute
apiVersion: gateway.networking.k8s.io/v1beta1
metadata:
  name: store
  namespace: development
spec:
  parentRefs:
  - kind: Gateway
    name: dev-example-gateway
  hostnames:
  - "gateway.example.com"
  rules:
  - backendRefs:
    - name: example-frontend-svc
      port: 3000
  - matches:
      - path:
          type: PathPrefix
          value: /api
    filters:
      - type: URLRewrite
        urlRewrite:
          hostname: gateway.example.com
          path:
            type: ReplacePrefixMatch
            replacePrefixMatch: /
    backendRefs:
      - name: example-backend-svc
        port: 2828
  - matches:
      - path:
          type: PathPrefix
          value: /_next/static/
    filters:
      - type: URLRewrite
        urlRewrite:
          hostname: gateway.example.com
          path:
            type: ReplacePrefixMatch
            replacePrefixMatch: /static/
    backendRefs:
      - name: projects/example/global/backendBuckets/example-bucket
        port: 80

Other backends are working as expected.


Solution

  • Unfortunately, neither GKE Ingress or Gateway support using GCS as a backend. You'd have to configure the load balancer manually and then use add GKE standalone NEGs as backends as well as the GCS backend.