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 enabled, API7 Enterprise Edition 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.
Make sure your API backend has already implemented the endpoints for health checks before enabling it.
- 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.
- From the dialog box, do the following:
- In the Probe Scheme field, choose
HTTP
. - In the HTTP Probe Path field, enter
/health
. - Use the default value for the rest of the fields.
- Click Enable.
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