Deployment modes

APISIX has three different deployment modes for different production use cases. The table below summarises the deployment modes:

Deployment modeRolesDescription
traditionaltraditionalData plane and control plane are deployed together. enable_admin attribute should be disabled manually.
decoupleddata_plane / control_planeData plane and control plane are deployed independently.
standalonedata_planeOnly data_plane is deployed and the configurations are loaded from a local YAML file.

Each of these deployment modes are explained in detail below.

Traditional

In the traditional deployment mode, one instance of APISIX will be both the data_plane and the control_plane.

An example configuration of the traditional deployment mode is shown below:

conf/config.yaml

  1. apisix:
  2. node_listen:
  3. - port: 9080
  4. deployment:
  5. role: traditional
  6. role_traditional:
  7. config_provider: etcd
  8. admin:
  9. admin_listen:
  10. port: 9180
  11. etcd:
  12. host:
  13. - http://${etcd_IP}:${etcd_Port}
  14. prefix: /apisix
  15. timeout: 30
  16. #END

The instance of APISIX deployed as the traditional role will:

  1. Listen on port 9080 to handle user requests, controlled by node_listen.
  2. Listen on port 9180 to handle Admin API requests, controlled by admin_listen.

Decoupled

In the decoupled deployment mode the data_plane and control_plane instances of APISIX are deployed separately, i.e., one instance of APISIX is configured to be a data plane and the other to be a control plane.

The instance of APISIX deployed as the data plane will:

Once the service is started, it will handle the user requests.

The example below shows the configuration of an APISIX instance as data plane in the decoupled mode:

conf/config.yaml

  1. deployment:
  2. role: data_plane
  3. role_data_plane:
  4. config_provider: etcd
  5. #END

The instance of APISIX deployed as the control plane will:

  1. Listen on port 9180 and handle Admin API requests.

The example below shows the configuration of an APISIX instance as control plane in the decoupled mode:

conf/config.yaml

  1. deployment:
  2. role: control_plane
  3. role_control_plane:
  4. config_provider: etcd
  5. etcd:
  6. host:
  7. - https://${etcd_IP}:${etcd_Port}
  8. prefix: /apisix
  9. timeout: 30
  10. #END

Standalone

Turning on the APISIX node in Standalone mode will no longer use the default etcd as the configuration center.

This method is more suitable for two types of users:

  1. Kubernetes(k8s):Declarative API that dynamically updates the routing rules with a full yaml configuration.
  2. Different configuration centers: There are many implementations of the configuration center, such as Consul, etc., using the full yaml file for intermediate conversion.

The routing rules in the conf/apisix.yaml file are loaded into memory immediately after the APISIX node service starts. And every time interval (default 1 second), will try to detect whether the file content is updated, if there is an update, reload the rule.

Note: Reloading and updating routing rules are all hot memory updates. There is no replacement of working processes, since it’s a hot update.

Since the current Admin API is based on the etcd configuration center solution, enable Admin API is not allowed when the Standalone mode is enabled.

Standalone mode can only be enabled when we set the role of APISIX as data plane. We set deployment.role to data_plane and deployment.role_data_plane.config_provider to yaml.

Refer to the example below:

  1. deployment:
  2. role: data_plane
  3. role_data_plane:
  4. config_provider: yaml
  5. #END

How to configure rules

All of the rules are stored in one file which named conf/apisix.yaml, APISIX checks if this file has any change every second. If the file is changed & it ends with #END, APISIX loads the rules from this file and updates its memory.

Here is a mini example:

  1. routes:
  2. -
  3. uri: /hello
  4. upstream:
  5. nodes:
  6. "127.0.0.1:1980": 1
  7. type: roundrobin
  8. #END

WARNING: APISIX will not load the rules into memory from file conf/apisix.yaml if there is no #END at the end.

Environment variables can also be used like so:

  1. routes:
  2. -
  3. uri: /hello
  4. upstream:
  5. nodes:
  6. "${{UPSTREAM_ADDR}}": 1
  7. type: roundrobin
  8. #END

WARNING: When using docker to deploy APISIX in standalone mode. New environment variables added to apisix.yaml while APISIX has been initialized will only take effect after a reload.

More information about using environment variables can be found here.

How to configure Route

Single Route:

  1. routes:
  2. -
  3. uri: /hello
  4. upstream:
  5. nodes:
  6. "127.0.0.1:1980": 1
  7. type: roundrobin
  8. #END

Multiple Routes:

  1. routes:
  2. -
  3. uri: /hello
  4. upstream:
  5. nodes:
  6. "127.0.0.1:1980": 1
  7. type: roundrobin
  8. -
  9. uri: /hello2
  10. upstream:
  11. nodes:
  12. "127.0.0.1:1981": 1
  13. type: roundrobin
  14. #END

How to configure Route + Service

  1. routes:
  2. -
  3. uri: /hello
  4. service_id: 1
  5. services:
  6. -
  7. id: 1
  8. upstream:
  9. nodes:
  10. "127.0.0.1:1980": 1
  11. type: roundrobin
  12. #END

How to configure Route + Upstream

  1. routes:
  2. -
  3. uri: /hello
  4. upstream_id: 1
  5. upstreams:
  6. -
  7. id: 1
  8. nodes:
  9. "127.0.0.1:1980": 1
  10. type: roundrobin
  11. #END

How to configure Route + Service + Upstream

  1. routes:
  2. -
  3. uri: /hello
  4. service_id: 1
  5. services:
  6. -
  7. id: 1
  8. upstream_id: 2
  9. upstreams:
  10. -
  11. id: 2
  12. nodes:
  13. "127.0.0.1:1980": 1
  14. type: roundrobin
  15. #END

How to configure Plugins

  1. # plugins listed here will be hot reloaded and override the boot configuration
  2. plugins:
  3. - name: ip-restriction
  4. - name: jwt-auth
  5. - name: mqtt-proxy
  6. stream: true # set 'stream' to true for stream plugins
  7. #END

How to configure Plugin Configs

  1. plugin_configs:
  2. -
  3. id: 1
  4. plugins:
  5. response-rewrite:
  6. body: "hello\n"
  7. routes:
  8. - id: 1
  9. uri: /hello
  10. plugin_config_id: 1
  11. upstream:
  12. nodes:
  13. "127.0.0.1:1980": 1
  14. type: roundrobin
  15. #END

How to enable SSL

  1. ssls:
  2. -
  3. cert: |
  4. -----BEGIN CERTIFICATE-----
  5. MIIDrzCCApegAwIBAgIJAI3Meu/gJVTLMA0GCSqGSIb3DQEBCwUAMG4xCzAJBgNV
  6. BAYTAkNOMREwDwYDVQQIDAhaaGVqaWFuZzERMA8GA1UEBwwISGFuZ3pob3UxDTAL
  7. BgNVBAoMBHRlc3QxDTALBgNVBAsMBHRlc3QxGzAZBgNVBAMMEmV0Y2QuY2x1c3Rl
  8. ci5sb2NhbDAeFw0yMDEwMjgwMzMzMDJaFw0yMTEwMjgwMzMzMDJaMG4xCzAJBgNV
  9. BAYTAkNOMREwDwYDVQQIDAhaaGVqaWFuZzERMA8GA1UEBwwISGFuZ3pob3UxDTAL
  10. BgNVBAoMBHRlc3QxDTALBgNVBAsMBHRlc3QxGzAZBgNVBAMMEmV0Y2QuY2x1c3Rl
  11. ci5sb2NhbDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJ/qwxCR7g5S
  12. s9+VleopkLi5pAszEkHYOBpwF/hDeRdxU0I0e1zZTdTlwwPy2vf8m3kwoq6fmNCt
  13. tdUUXh5Wvgi/2OA8HBBzaQFQL1Av9qWwyES5cx6p0ZBwIrcXQIsl1XfNSUpQNTSS
  14. D44TGduXUIdeshukPvMvLWLezynf2/WlgVh/haWtDG99r/Gj3uBdjl0m/xGvKvIv
  15. NFy6EdgG9fkwcIalutjrUnGl9moGjwKYu4eXW2Zt5el0d1AHXUsqK4voe0p+U2Nz
  16. quDmvxteXWdlsz8o5kQT6a4DUtWhpPIfNj9oZfPRs3LhBFQ74N70kVxMOCdec1lU
  17. bnFzLIMGlz0CAwEAAaNQME4wHQYDVR0OBBYEFFHeljijrr+SPxlH5fjHRPcC7bv2
  18. MB8GA1UdIwQYMBaAFFHeljijrr+SPxlH5fjHRPcC7bv2MAwGA1UdEwQFMAMBAf8w
  19. DQYJKoZIhvcNAQELBQADggEBAG6NNTK7sl9nJxeewVuogCdMtkcdnx9onGtCOeiQ
  20. qvh5Xwn9akZtoLMVEdceU0ihO4wILlcom3OqHs9WOd6VbgW5a19Thh2toxKidHz5
  21. rAaBMyZsQbFb6+vFshZwoCtOLZI/eIZfUUMFqMXlEPrKru1nSddNdai2+zi5rEnM
  22. HCot43+3XYuqkvWlOjoi9cP+C4epFYrxpykVbcrtbd7TK+wZNiK3xtDPnVzjdNWL
  23. geAEl9xrrk0ss4nO/EreTQgS46gVU+tLC+b23m2dU7dcKZ7RDoiA9bdVc4a2IsaS
  24. 2MvLL4NZ2nUh8hAEHiLtGMAV3C6xNbEyM07hEpDW6vk6tqk=
  25. -----END CERTIFICATE-----
  26. key: |
  27. -----BEGIN PRIVATE KEY-----
  28. MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCf6sMQke4OUrPf
  29. lZXqKZC4uaQLMxJB2DgacBf4Q3kXcVNCNHtc2U3U5cMD8tr3/Jt5MKKun5jQrbXV
  30. FF4eVr4Iv9jgPBwQc2kBUC9QL/alsMhEuXMe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/TmWnsH1hGIGDRtJLCiZeHL70u32kzCMkI1jOhFAWqoutMa
  47. 7obDkmwraONIVW/kFp6bWtSJhhTQTD4adI9cPCKWDXdcCHSWj0Xk+U8HgQKBgBng
  48. t1HYhaLzIZlP/U/nh3XtJyTrX7bnuCZ5FhKJNWrYjxAfgY+NXHRYCKg5x2F5j70V
  49. be7pLhxmCnrPTMKZhik56AaTBOxVVBaYWoewhUjV4GRAaK5Wc8d9jB+3RizPFwVk
  50. V3OU2DJ1SNZ+W2HBOsKrEfwFF/dgby6i2w6MuAP1AoGBAIxvxUygeT/6P0fHN22P
  51. zAHFI4v2925wYdb7H//D8DIADyBwv18N6YH8uH7L+USZN7e4p2k8MGGyvTXeC6aX
  52. IeVtU6fH57Ddn59VPbF20m8RCSkmBvSdcbyBmqlZSBE+fKwCliKl6u/GH0BNAWKz
  53. r8yiEiskqRmy7P7MY9hDmEbG
  54. -----END PRIVATE KEY-----
  55. snis:
  56. - "yourdomain.com"
  57. #END

How to configure global rule

  1. global_rules:
  2. -
  3. id: 1
  4. plugins:
  5. response-rewrite:
  6. body: "hello\n"
  7. #END

How to configure consumer

  1. consumers:
  2. - username: jwt
  3. plugins:
  4. jwt-auth:
  5. key: user-key
  6. secret: my-secret-key
  7. #END

How to configure plugin metadata

  1. upstreams:
  2. - id: 1
  3. nodes:
  4. "127.0.0.1:1980": 1
  5. type: roundrobin
  6. routes:
  7. -
  8. uri: /hello
  9. upstream_id: 1
  10. plugins:
  11. http-logger:
  12. batch_max_size: 1
  13. uri: http://127.0.0.1:1980/log
  14. plugin_metadata:
  15. - id: http-logger # note the id is the plugin name
  16. log_format:
  17. host: "$host",
  18. remote_addr: "$remote_addr"
  19. #END

How to configure stream route

  1. stream_routes:
  2. - server_addr: 127.0.0.1
  3. server_port: 1985
  4. id: 1
  5. upstream_id: 1
  6. plugins:
  7. mqtt-proxy:
  8. protocol_name: "MQTT"
  9. protocol_level: 4
  10. upstreams:
  11. - nodes:
  12. "127.0.0.1:1995": 1
  13. type: roundrobin
  14. id: 1
  15. #END

How to configure protos

  1. protos:
  2. - id: helloworld
  3. desc: hello world
  4. content: >
  5. syntax = "proto3";
  6. package helloworld;
  7. service Greeter {
  8. rpc SayHello (HelloRequest) returns (HelloReply) {}
  9. }
  10. message HelloRequest {
  11. string name = 1;
  12. }
  13. message HelloReply {
  14. string message = 1;
  15. }
  16. #END