apache / apisix-ingress-controller

APISIX Ingress Controller for Kubernetes
https://apisix.apache.org/
Apache License 2.0
1.02k stars 343 forks source link

Autogenerated upstream from (service) backend does not match name from CRD: upstream doesn't exist #2267

Open martin-schulze-e2m opened 3 months ago

martin-schulze-e2m commented 3 months ago

Current State

I could find no documentation about how to do this. My understanding was, that the upstream should be named the same as the referenced service and be in the same namespace but I still get:

ApisixIngress synced failed, with error: upstream doesn't exist. It will be created after ApisixRoute is created referencing it.

For a concrete example:

apiVersion: apisix.apache.org/v2
kind: ApisixUpstream
metadata:
  name: bitter
spec:
  timeout:
    read: 180s
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
  name: bitter
spec:
  http:
    - backends:
        - serviceName: bitter
          servicePort: 80
      match:
        hosts:
          - bitter.test
        paths:
          - /*
      name: route-open

I can see that this backend creates an upstream called default_bitter_80 but the upstream config is not applied (as told by the error message). Similarly, I can't name the Upstream default_bitter_80 because K8s forbids _, so how am I supposed to get this to match?

Update When I tried to use another name I get the error message ApisixIngress synced failed, with error: service "bitter--80" not found, so it seems the name was right but the upstream was still not matched

APISIX Version: 3.9.1

Desired State

Describe how one can configure the autogenerated upstream from a backend route.

kayx23 commented 3 months ago

I have run into upstream doesn't exist. It will be created after ApisixRoute is created referencing it. when kubectl apply an upstream manifest. But once I created the service with route in it pointing to the upstream, I can apply the ApisixUpstream manifest without issue.

All I did was I made sure these correspond:

image

and that you create the ApisixRoute first and ApisixUpstream second.

martin-schulze-e2m commented 3 months ago

I deleted the upstream and upgraded the helm chart that creates both route and upstream. Still the same error despite the route existing before the upstream.

I am also wondering how the matching should work, considering that the full upstream name contains the port number but the upstream CRD does not.

martin-schulze-e2m commented 3 months ago

I reproduced this on a local test cluster with log_level: debug in the ingress controller and got this additional message:

debug   apisix/upstream.go:43   try to look up upstream {"name": "default_bitter_80_service"

However, as I said, the actual upstream name is default_bitter_80, so no wonder there is no match.

Please note that I am relying on the bitnami chart version 3.3.9.

With this I also think that this is not a docs issue (though the docs around this could be improved) but an actual bug.

This used to work with APISIX 3.5.0 (from bitnami chart version 2.1.1)