Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gateway API: HttpRoute with weight and namespace doesn't work well. #3860

Closed
1 task done
parkjeongryul opened this issue Apr 6, 2023 · 4 comments · Fixed by #4375
Closed
1 task done

Gateway API: HttpRoute with weight and namespace doesn't work well. #3860

parkjeongryul opened this issue Apr 6, 2023 · 4 comments · Fixed by #4375
Assignees
Labels
bug Something isn't working
Milestone

Comments

@parkjeongryul
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

We have each backend service separated by a namespace, and we want to distribute the traffic by weighting it as follows, but it doesn’t seem to be working, any idea why?

apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
metadata:
  name: kong
  annotations:
    konghq.com/gatewayclass-unmanaged: 'true'
spec:
  controllerName: konghq.com/kic-gateway-controller

---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
  name: kong
  namespace: kong
spec:
  gatewayClassName: kong
  listeners:
    - name: proxy
      hostname: "my host name"
      port: 80
      protocol: HTTP
      allowedRoutes:
        namespaces:
          from: All

---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: ReferenceGrant
metadata:
  name: clous-jrpark-blue-2304032002
  namespace: clous-jrpark-blue-2304032002
spec:
  from:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute
      namespace: clous-jrpark
  to:
    - group: ""
      kind: Service

---

apiVersion: gateway.networking.k8s.io/v1beta1
kind: ReferenceGrant
metadata:
  name: clous-jrpark-green-2304061502
  namespace: clous-jrpark-green-2304061502
spec:
  from:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute
      namespace: clous-jrpark
  to:
    - group: ""
      kind: Service

---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: clous-jrpark
  namespace: clous-jrpark
  annotations:
    konghq.com/strip-path: 'true'
spec:
  parentRefs:
    - name: kong
      namespace: kong
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /clous-jrpark/common-sas
      backendRefs:
        - name: s-common-sas
          namespace: clous-jrpark-blue-2304032002
          port: 80
          weight: 90
        - name: s-common-sas
          namespace: clous-jrpark-green-2304061502
          port: 80
          weight: 10

But traffic flows to only one backend.

image

Expected Behavior

traffic should flow to both backend with the weight.

Steps To Reproduce

There are yaml files that i applied.

Kong Ingress Controller version

kong-ingress-controller:v2.9.2
kong:3.2.2

Kubernetes version

v1.23.15

Anything else?

No response

@parkjeongryul parkjeongryul added the bug Something isn't working label Apr 6, 2023
@parkjeongryul
Copy link
Contributor Author

I did some testing and found some things that didn’t work as expected.

  1. Services with the same name seem to conflict (even if in different namespaces).
    • I created a service with a different name and found that the traffic was delivered.
      backendRefs:
        - namespace: clous-jrpark-blue-2304032002
          name: s-common-sas
          port: 80
          weight: 30
        - namespace: clous-jrpark-green-2304061502
          name: s-common-sas-2
          port: 80
          weight: 5
  1. Weights between different namespaces don’t seem to be calculated
    • Regardless of weight, traffic flows to all backend service evenly.
      backendRefs:
        - namespace: clous-jrpark-blue-2304032002
          name: s-common-sas
          port: 80
          weight: 30
        - namespace: clous-jrpark-green-2304061502
          name: s-common-sas-2
          port: 80
          weight: 5

image

@mlavacca
Copy link
Member

mlavacca commented Apr 7, 2023

Thanks for reporting this, @parkjeongryul. I'll test your configuration and get back to you soon.

@mlavacca
Copy link
Member

mlavacca commented Apr 7, 2023

After an initial investigation, it looks like we actually have a cross-namespace problem. With this configuration, only the newest backend is pushed to the dataplane (for this reason, the LB isn't performed), while if we move everything into the same namespace, the routing works as expected as both the backends are pushed to the dataplane. It requires further investigation. I'll keep you posted @parkjeongryul.

@mlavacca mlavacca self-assigned this Apr 7, 2023
@parkjeongryul
Copy link
Contributor Author

Thanks for investigation.

  1. How long will it take for the feature to be fixed as expected? (Is this a simple change?)
  2. I've found that using a service of type ExternalName allows us to achieve the behavior we want. Is there a problem with using it this way?
apiVersion: v1
kind: Service
metadata:
  name: clous-jrpark-green-2304061502
  namespace: clous-jrpark
spec:
  type: ExternalName
  externalName: s-common-sas.clous-jrpark-green-2304061502.svc.cluster.local
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: http
---
apiVersion: v1
kind: Service
metadata:
  name: clous-jrpark-blue-2304032002
  namespace: clous-jrpark
spec:
  type: ExternalName
  externalName: s-common-sas.clous-jrpark-blue-2304032002.svc.cluster.local
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: http
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: clous-jrpark
  namespace: clous-jrpark
  annotations:
    konghq.com/strip-path: 'true'
spec:
  parentRefs:
    - name: kong
      namespace: kong
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /clous-jrpark/common-sas
      backendRefs:
        - name: clous-jrpark-green-2304061502
          port: 80
          weight: 30
        - name: clous-jrpark-blue-2304032002
          port: 80
          weight: 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants