In this tutorial, we will introduce how to configure external services discovery in the ApisixUpstream resources.
APISIX already supports various service discovery components, such as DNS, consul, nacos, etc. Please see Integration service discovery registry for details.
- An available Kubernetes cluster
- An available APISIX and APISIX Ingress Controller installation
We assume that your APISIX is installed in the
Integration of APISIX Ingress with service discovery components is configured through the ApisixUpstream resource.
In this case, we don't configure the
backends field in the ApisixRoute resource.
Instead, we will use the
upstreams field to refer to an ApisixUpstream resources with the
discovery field configured.
- name: rule1
# backends: # We won't use the `backends` field
# - serviceName: httpbin
# servicePort: 80
- name: httpbin-upstream
This configuration tells the ingress controller not to resolve upstream hosts through the K8s services, but to use the configuration defined in the referenced ApisixUpstream.
The referenced ApisixUpstream MUST have
discovery field configured. For example:
In this yaml example, we configured
httpbin.default.svc.cluster.local as the backend.
The type of service discovery needs to be pre-configured in APISIX. For example:
- "10.96.0.10:53" # default kube-dns cluster IP.
After applying the above configuration, we can try to access
httpbin.default.svc.cluster.local directly through APISIX.