What is Apache APISIX API Gateway
Apache APISIX is a dynamic, real-time, high-performance API Gateway.
APISIX API Gateway provides rich traffic management features such as load balancing, dynamic upstream, canary release, circuit breaking, authentication, observability, and more.
You can use APISIX API Gateway to handle traditional north-south traffic, as well as east-west traffic between services. At present, APISIX has been used in various industries, including NASA, Tencent Cloud, EU Digital Factory, Airbus, Airwallex, iQIYI, etc.
How to run Apache APISIX
Apache APISIX supports stand-alone mode and also supports the use of etcd database as the configuration center.
How to run APISIX in stand-alone mode
In stand-alone mode, APISIX uses apisix.yaml as the configuration center to store routing, upstream, consumer and other information. After APISIX is started, it will load the apisix.yaml file regularly to update the corresponding configuration information.
You can start an APISIX container with stand-alone mode by the following command:
-p 9080:9080 \
-e APISIX_STAND_ALONE=true \
apache/apisix
Add Route and Plugin configuration to the running APISIX container:
routes:
-
id: httpbin
uri: /*
upstream:
nodes:
"httpbin.org": 1
type: roundrobin
plugin_config_id: 1
plugin_configs:
-
id: 1
plugins:
response-rewrite:
body: "Hello APISIX\n"
desc: "response-rewrite"
#END
_EOC_'
Test example:
If you want to know more configuration examples, you can refer to stand-alone.
How to run APISIX using etcd as configuration center
Solution 1
The operation of APISIX also supports the use of etcd as the configuration center. Before starting the APISIX container, we need to start the etcd container with the following command, and specify the network used by the container as the host network. Make sure that all the required ports (default: 9080, 9443 and 2379) are available and not used by other system processes.
- Start etcd.
--name etcd \
--net host \
-e ALLOW_NONE_AUTHENTICATION=yes \
-e ETCD_ADVERTISE_CLIENT_URLS=http://127.0.0.1:2379 \
bitnami/etcd:latest
- Start APISIX.
--name apache-apisix \
--net host \
apache/apisix
Solution 2
Before starting the APISIX container, we need to create a Docker virtual network and start the etcd container.
- Create a network and view the subnet address, then start etcd
docker network inspect -v apisix-network && \
docker run -d --name etcd \
--network apisix-network \
-p 2379:2379 \
-p 2380:2380 \
-e ALLOW_NONE_AUTHENTICATION=yes \
-e ETCD_ADVERTISE_CLIENT_URLS=http://127.0.0.1:2379 \
bitnami/etcd:latest
- View the return result of the previous step, we can see the
subnetaddress. Create a APISIX configuration file in the current directory. You need to setallow_adminto thesubnetaddress obtained in step1.
deployment:
role: traditional
role_traditional:
config_provider: etcd
admin:
allow_admin:
- 0.0.0.0/0 # Please set it to the subnet address you obtained.
# If not set, by default all IP access is allowed.
etcd:
host:
- "http://etcd:2379"
prefix: "/apisix"
timeout: 30
EOF
- Start APISIX and reference the file created in the previous step.
--network apisix-network \
-p 9080:9080 \
-p 9180:9180 \
-v $(pwd)/config.yaml:/usr/local/apisix/conf/config.yaml \
apache/apisix
Test example
Check that APISIX is running properly by running the following command on the host.
curl "http://127.0.0.1:9180/apisix/admin/services/" \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1'