Use Service Discovery for Upstream
Instead of configuring the upstream directly, service discovery mechanisms like Consul, Eureka, Nacos, or Kubernetes Service Discovery can be used to dynamically detect upstream nodes.
Once published, a service cannot directly switch between configured upstream nodes and service discovery. Instead, you have to configure this through a canary deployment.
Prerequisites
- Install API7 Enterprise.
- Have at least one gateway instance in your gateway group.
Kubernetes
Add Service Registry Connection
- Select Service Registries of your gateway group from the side navigation bar, then click Add Service Registry Connection.
- From the dialog box, do the following:
- In the Name field, enter
Registry for Test
. - In the Discovery Type field, choose
Kubernetes
. - Fill in the API Server Address and Token Value field.
- Click Add.
- Wait to make sure the status of the service registry is
Healthy
.
Configure Upstream
Select Published Services under your gateway group from the side navigation bar and then click Add Service.
Select Add Manually.
From the Add Service dialog box, do the following:
- In the Name field, enter
httpbin
. - In the Service Type field, choose
HTTP (Layer 7 Proxy)
. - In the Upstream Scheme field, choose
HTTP
. - In the How to find the upstream field, choose
Use Service Discovery
. - In the Service Registry field, choose
Registry for Test
, then choose the Namespace and Service Name.
- In the Name field, enter
Click Add. This will create a new service in the 'No Version' state.
Below is an interactive demo that provides a hands-on introduction to connecting Kubernetes service discovery. You will gain a better understanding of how to use it in API7 Gateway by clicking and following the steps.
Nacos
Add Service Registry Connection
- Select Service Registries of your gateway group from the side navigation bar, then click Add Service Registry Connection.
- From the dialog box, do the following:
- In the Name field, enter
Registry for Test
. - In the Discovery Type field, choose
Nacos
. - In the Hosts field, fill in the host address and port.
- In the How to Get Token field, choose a way to get the token and configure related parameters.
- Click Add.
- Wait to make sure the status of the service registry is
Healthy
.
Configure Upstream
Select Published Services under your gateway group from the side navigation bar and then click Add Service.
Select Add Manually.
From the Add Service dialog box, do the following:
- In the Name field, enter
httpbin
. - In the Service Type field, choose
HTTP (Layer 7 Proxy)
. - In the Upstream Scheme field, choose
HTTP
. - In the How to find the upstream field, choose
Use Service Discovery
. - In the Service Registry field, choose
Registry for Test
, then choose the Namespace, Group, and Service Name.
- In the Name field, enter
Click Add. This will create a new service in the 'No Version' state.
Below is an interactive demo that provides a hands-on introduction to connecting Nacos service discovery. You will gain a better understanding of how to use it in API7 Gateway by clicking and following the steps.