跳到主要内容
版本:3.2.15.2

APISIX Declarative CLI (ADC)

APISIX Declarative CLI (ADC) 是一个命令行工具,用于声明式地管理 APISIX 和 API7 企业版。它提供了简单明了的方式来定义网关的期望状态,让开发人员和管理员专注于结果而非步骤。

声明式配置作为单一事实来源,开发人员可以通过他们现有的版本控制系统进行管理。

ADC 具有以下通用语法:

adc [command] [options]

以及全局选项:

  • -V, --version to check the version
  • -h, --help to print the help menu of the command

配置 ADC

在使用 ADC 管理网关之前,需要先进行配置。你可以使用环境变量或命令行参数来配置 ADC。

使用环境变量

ADC 将所有配置选项暴露为环境变量。例如,你可以分别使用 ADC_BACKENDADC_SERVER 环境变量来配置后端类型和地址。

export ADC_BACKEND=api7ee
export ADC_SERVER=https://localhost:7443

更好的方式是在 .env 文件中配置这些选项:

.env
ADC_BACKEND=api7ee
ADC_SERVER=https://localhost:7443

使用命令行参数

你也可以使用命令行参数来配置 ADC 或覆盖环境变量中的配置。例如,为 ping 命令配置/覆盖后端类型和地址:

adc ping --backend api7ee --server "https://localhost:7443"

运行 adc help [command] 以查看命令的可用配置选项。

命令

adc ping

Ping 已配置的后端以验证连接性。

OptionDefault ValueDescriptionValid ValuesEnv Variable
--verbose <integer>1Overrides verbose logging levels.0 represents no log, 1 represents basic logs, and 2 represents debug logs.0, 1 or 2
--backend <backend>apisixBackend type to connect.apisix or api7eeADC_BACKEND
--server <string>http://localhost:9180Backend server address.ADC_SERVER
--token <string>API token to access the backend.ADC_TOKEN
--gateway-group <string>defaultGateway group to operate on.ADC_GATEWAY_GROUP
--label-selector <selectors>Resource labels to filter for.
--include-resource-type <string>Filter for resource types, such that the resource search results should only contain the specified type.
--exclude-resource-type <string>Filter for resource types, such that the resource search results should exclude the specified type.
--timeout <duration>10sRequest timeout for the client to connect with the backend Admin API in duration, such as 30s, 10m, and 1h10m.
--ca-cert-file <string>Path to CA certificate for verifying the backend Admin API.ADC_CA_CERT_FILE
--tls-client-cert-file <string>Path to mutual TLS client certificate for verifying the backend Admin API.ADC_TLS_CLIENT_CERT_FILE
--tls-client-key-file <string>Path to mutual TLS client key for verifying the backend Admin API.ADC_TLS_CLIENT_KEY_FILE
--tls-skip-verifyfalseWhether to verify the TLS certificate when connecting to the backend Admin API.ADC_TLS_SKIP_VERIFY

使用示例

adc ping --backend api7ee --server https://localhost:7443

adc lint

在本地验证提供的配置文件。

OptionDefault ValueDescriptionValid ValuesEnv Variable
-f, --file <file-path>Files to lint.

使用示例

adc lint -f service-a.yaml -f service-b.yaml

adc sync

将本地配置同步到连接的后端。

OptionDefault ValueDescriptionValid ValuesEnv Variable
--verbose <integer>1Overrides verbose logging levels.0 represents no log, 1 represents basic logs, and 2 represents debug logs.0, 1 or 2
--backend <backend>apisixBackend type to connect.apisix or api7eeADC_BACKEND
--server <string>http://localhost:9180Backend server address.ADC_SERVER
--token <string>API token to access the backend.ADC_TOKEN
--gateway-group <string>defaultGateway group to operate on.ADC_GATEWAY_GROUP
--label-selector <selectors>Resource labels to filter for.
-f, --file <file-path>Configuration files to synchronize.
--include-resource-type <string>Filter for resource types, such that the resource search results should only contain the specified type.
--exclude-resource-type <string>Filter for resource types, such that the resource search results should exclude the specified type.
--timeout <duration>10sRequest timeout for the client to connect with the backend Admin API in duration, such as 30s, 10m, and 1h10m.
--ca-cert-file <string>Path to CA certificate for verifying the backend Admin API.ADC_CA_CERT_FILE
--tls-client-cert-file <string>Path to mutual TLS client certificate for verifying the backend Admin API.ADC_TLS_CLIENT_CERT_FILE
--tls-client-key-file <string>Path to mutual TLS client key for verifying the backend Admin API.ADC_TLS_CLIENT_KEY_FILE
--tls-skip-verifyfalseWhether to verify the TLS certificate when connecting to the backend Admin API.ADC_TLS_SKIP_VERIFY

使用示例

adc sync -f service-a.yaml -f service-b.yaml --backend api7ee --server https://localhost:7443

adc dump

将后端配置保存到本地文件。

OptionDefault ValueDescriptionValid ValuesEnv Variable
--verbose <integer>1Overrides verbose logging levels.0 represents no log, 1 represents basic logs, and 2 represents debug logs.0, 1 or 2
--backend <backend>apisixBackend type to connect.apisix or api7eeADC_BACKEND
--server <string>http://localhost:9180Backend server address.ADC_SERVER
--token <string>API token to access the backend.ADC_TOKEN
--gateway-group <string>defaultGateway group to operate on.ADC_GATEWAY_GROUP
--label-selector <selectors>Resource labels to filter for.
-o, --output <file-path>Specify the file path where the backend data should be dumped.
--include-resource-type <string>Filter for resource types, such that the resource search results should only contain the specified type.
--exclude-resource-type <string>Filter for resource types, such that the resource search results should exclude the specified type.
--timeout <duration>10sRequest timeout for the client to connect with the backend Admin API in duration, such as 30s, 10m, and 1h10m.
--ca-cert-file <string>Path to CA certificate for verifying the backend Admin API.ADC_CA_CERT_FILE
--tls-client-cert-file <string>Path to mutual TLS client certificate for verifying the backend Admin API.ADC_TLS_CLIENT_CERT_FILE
--tls-client-key-file <string>Path to mutual TLS client key for verifying the backend Admin API.ADC_TLS_CLIENT_KEY_FILE
--tls-skip-verifyfalseWhether to verify the TLS certificate when connecting to the backend Admin API.ADC_TLS_SKIP_VERIFY

使用示例

adc dump -o apisix-dump.yaml --backend api7ee --server https://localhost:7443

adc diff

显示本地文件和后端配置之间的差异。

OptionDefault ValueDescriptionValid ValuesEnv Variable
--verbose <integer>1Overrides verbose logging levels.0 represents no log, 1 represents basic logs, and 2 represents debug logs.0, 1 or 2
--backend <backend>apisixBackend type to connect.apisix or api7eeADC_BACKEND
--server <string>http://localhost:9180Backend server address.ADC_SERVER
--token <string>API token to access the backend.ADC_TOKEN
--gateway-group <string>defaultGateway group to operate on.ADC_GATEWAY_GROUP
--label-selector <selectors>Resource labels to filter for.
-f, --file <file-path>Configuration files to compare.
--include-resource-type <string>Filter for resource types, such that the resource search results should only contain the specified type.
--exclude-resource-type <string>Filter for resource types, such that the resource search results should exclude the specified type.
--timeout <duration>10sRequest timeout for the client to connect with the backend Admin API in duration, such as 30s, 10m, and 1h10m.
--ca-cert-file <string>Path to CA certificate for verifying the backend Admin API.ADC_CA_CERT_FILE
--tls-client-cert-file <string>Path to mutual TLS client certificate for verifying the backend Admin API.ADC_TLS_CLIENT_CERT_FILE
--tls-client-key-file <string>Path to mutual TLS client key for verifying the backend Admin API.ADC_TLS_CLIENT_KEY_FILE
--tls-skip-verifyfalseWhether to verify the TLS certificate when connecting to the backend Admin API.ADC_TLS_SKIP_VERIFY

使用示例

adc diff -f service-a.yaml -f service-b.yaml --backend api7ee --server https://localhost:7443

adc convert

将 API 规范转换为 ADC 配置。

OptionDefault ValueDescriptionValid ValuesEnv Variable
openapiConvert an OpenAPI specification to ADC configuration.

使用示例

adc convert openapi -f open-api-spec.yaml -o adc.yaml

adc help

打印通用帮助菜单或指定命令的帮助菜单。

使用示例

adc help [command]