Ensure Upstream High Availability
When API7 Gateway sends the API requests to the upstreams, there can be availability and reliability concerns if those upstream systems fail. This guide covers strategies for the high availability of your upstream dependencies.
Prerequisite(s)
Add Multiple Upstream Nodes
Using multiple upstream nodes protects against single-node failure. Modifications made to upstream nodes in a gateway group will not affect the same service version published to other gateway groups.
- Dashboard
- Ingress Controller
- Select Published Services of your gateway group from the side navigation bar, then click the service you want to modify, for example,
httpbin
with version1.0.0
. - Under the published service, select Upstreams from the side navigation bar.
- Click Nodes > Add Node.
- From the dialog box, do the following:
- In the Host and Port fields, enter another API Endpoint.
- In the Weight field, enter
100
, the same as the first node. - Click Add.
Create a Kubernetes manifest file to configure a route pointing to multiple upstream services using the ApisixRoute custom resource:
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
name: multiple-upstream-nodes
# namespace: api7 # replace with your namespace
spec:
http:
- name: multiple-upstream-nodes
match:
paths:
- /*
backends:
- serviceName: upstream1
servicePort: 80
- serviceName: upstream2
servicePort: 80
Apply the configuration to your cluster:
kubectl apply -f multiple-upstream-nodes.yaml
Modify Load Balancing Type
Load balancing distributes network requests across multiple nodes. It is crucial for systems handling high traffic volumes, improving performance, scalability, and reliability.
API7 Gateway supports a variety of load-balancing algorithms:
- Weighted Round Robin (WRR)
- Consistent Hash
- Exponentially Weighted Moving Average (EWMA)
- Least connection
By default, API7 Gateway supports the WRR algorithm. This algorithm distributes incoming requests over a set of nodes based on their weight in a cyclical pattern.
- Dashboard
- Ingress Controller
- Select Published Services of your gateway group from the side navigation bar, then click the service you want to modify, for example,
httpbin
with version1.0.0
. - Under the published service, select Upstreams from the side navigation bar.
- In the Upstream Configuration field, click Edit.
- From the dialog box, edit Load Balancing Type to
Least Connection
. - Click Save.
apiVersion: apisix.apache.org/v2
kind: ApisixUpstream
metadata:
name: httpbin # correspond to service name
# namespace: api7 # replace with your namespace
spec:
loadbalancer:
type: least_conn
Apply the configuration to your cluster:
kubectl apply -f loadbalancer.yaml
Enable Health Checks
Health checking is a mechanism that determines whether upstream nodes are healthy or unhealthy based on their responsiveness. With health checks configured, API7 Enterprise will only forward requests to upstream nodes that are considered healthy, and not forward requests to the nodes that are considered unhealthy.
There are two general approaches to health checks:
- Active health checks: determines the health of an upstream node by actively probing the node.
- Passive health checks: determines the health of an upstream node based on how the node responds to user requests without initiating additional probes. Passive checks must be used with active checks. They cannot be used alone.
API7 Enterprise supports both L7 (HTTPS and HTTP) and L4 (TCP) health checks.
By default, upstream health checks are globally enabled:
apisix:
disable_upstream_healthcheck: false
Follow the following steps to configure the details of health checks.
Before proceeding, make sure your API backend has implemented the endpoints for health checks.
- Dashboard
- Ingress Controller
- Select Published Services of your gateway group from the side navigation bar, then click the service you want to modify, for example,
httpbin
with version1.0.0
. - Under the published service, select Upstreams from the side navigation bar.
- In the Health Check field, click Enable.
- Configure Active Health Check and optionally the Passive Health Check.
API7 Enterprise requires the configuration of active health check when using passive health check. When an upstream service becomes unhealthy, the active health check is in place to periodically check if the upstream service has recovered.
See Configure Upstream Health Checks to learn more about configurations and behaviours.
Create a Kubernetes manifest file for an upstream, where health check is enabled:
apiVersion: apisix.apache.org/v2
kind: ApisixUpstream
metadata:
name: httpbin # correspond to service name
# namespace: api7 # replace with your namespace
spec:
healthCheck:
passive:
unhealthy:
httpCodes:
- 429
- 404
- 500
- 501
- 502
- 503
- 504
- 505
httpFailures: 5
active:
type: http
httpPath: /health
timeout: 3
healthy:
successes: 2
interval: 1s
httpCodes:
- 200
- 302
Apply the configuration to your cluster:
kubectl apply -f upstream-healthcheck.yaml