Skip to content

Latest commit

 

History

History
110 lines (94 loc) · 3.04 KB

nacos.md

File metadata and controls

110 lines (94 loc) · 3.04 KB
title keywords description
nacos
APISIX
Nacos
apisix-seed
This document contains information about how to use Nacos as service registry in Apache APISIX via apisix-seed.

Deploy Nacos

Quickly deploy Nacos using the Nacos Docker image:

docker run --name nacos-quick -e MODE=standalone -p 8848:8848 -d nacos/nacos-server:2.0.2

Install APISIX-Seed

Download and build APISIX-Seed:

git clone https://github.com/api7/apisix-seed.git
cd apisix-seed
make build && make install

The default configuration file is in /usr/local/apisix-seed/conf/conf.yaml with the following contents:

etcd:                            # APISIX etcd Configure
  host:
    - "http://127.0.0.1:2379"
  prefix: /apisix
  timeout: 30

discovery:                       # service discovery center
  nacos:
    host:                        # it's possible to define multiple nacos hosts addresses of the same nacos cluster.
      - "http://127.0.0.1:8848"
    prefix: /nacos
    weight: 100                  # default weight for node
    timeout:
      connect: 2000              # default 2000ms
      send: 2000                 # default 2000ms
      read: 5000                 # default 5000ms

You can easily understand each configuration item, we will not explain it additionally.

Start APISIX-Seed:

APISIX_SEED_WORKDIR=/usr/local/apisix-seed /usr/local/apisix-seed/apisix-seed

Register the upstream service

Start the httpbin service via Docker:

docker run -d -p 8080:80 --rm kennethreitz/httpbin

Register the service to Nacos:

curl -X POST 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=httpbin&ip=127.0.0.1&port=8080'

Verify in Apache APISIX

Start Apache APISIX with default configuration:

apisix start

Create a Route through the Admin API interface of Apache APISIX:

curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
    "uris": "/*",
    "hosts": [
        "httpbin"
    ],
    "upstream": {
        "discovery_type": "nacos",
        "service_name": "httpbin",
        "type": "roundrobin"
    }
}'

Send a request to confirm whether service discovery is in effect:

curl http://127.0.0.1:9080/get -H 'Host: httpbin'