zookeeper

    The process is as follows:

    1. APISIX registers an upstream and specifies the service discovery type as zookeeper to etcd.
    2. apisix-seed watches the resource changes of APISIX in etcd and filters the discovery type and obtains the service name.
    3. apisix-seed binds the service to the etcd resource and starts watching the service in zookeeper.
    4. The client registers the service with zookeeper.
    5. apisix-seed gets the service changes in zookeeper.
    6. apisix-seed queries the bound etcd resource information through the service name, and writes the updated service node to etcd.
    7. The APISIX worker watches etcd changes and refreshes the service node information to the memory.
    1. Start the Zookeeper service
    1. Download and compile the apisix-seed project.
    1. git clone https://github.com/api7/apisix-seed.git
    2. cd apisix-seed
    3. go build
    1. Modify the apisix-seed configuration file, config path conf/conf.yaml.
    1. etcd: # APISIX ETCD Configure
    2. host:
    3. prefix: /apisix
    4. timeout: 30
    5. discovery:
    6. zookeeper: # Zookeeper Service Discovery
    7. hosts:
    8. - "127.0.0.1:2181" # Zookeeper service address
    9. prefix: /zookeeper
    10. weight: 100 # default weight for node
    11. timeout: 10 # default 10s
    1. Start apisix-seed to monitor service changes

    Set a route, the request path is /zk/*, the upstream uses zookeeper as service discovery, and the service name is APISIX-ZK.

    1. -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
    2. {
    3. "uri": "/zk/*",
    4. "upstream": {
    5. "service_name": "APISIX-ZK",
    6. "type": "roundrobin",
    7. "discovery_type": "zookeeper"
    8. }
    1. Service registration using Zookeeper CLI
    • Register Service
    1. # Login Container
    2. docker exec -it ${CONTAINERID} /bin/bash
    3. # Login Zookeeper Client
    4. oot@ae2f093337c1:/apache-zookeeper-3.7.0-bin# ./bin/zkCli.sh
    5. # Register Service
    6. [zk: localhost:2181(CONNECTED) 0] create /zookeeper/APISIX-ZK '{"host":"127.0.0.1:1980","weight":100}'
    • Successful Response
    1. Verify Request
    • Request
    1. curl -i http://127.0.0.1:9080/zk/hello
    • Response
    1. HTTP/1.1 200 OK
    2. Connection: keep-alive
    3. Content-Type: text/html; charset=utf-8
    4. Date: Tue, 29 Mar 2022 08:51:28 GMT
    5. Server: APISIX/2.12.0
    6. Transfer-Encoding: chunked