跳到主要内容
版本:3.8.x

命令参考

API Declarative CLI(ADC)是一个命令行工具,用于声明式地管理 APISIX 和 API7 企业版。开发人员和管理员可以直接定义网关的期望状态,专注于配置结果。

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

ADC 具有以下通用语法:

adc [command] [options]

以及全局选项:

  • -V, --version 查看版本
  • -h, --help 显示命令的帮助菜单

配置 ADC​

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

使用环境变量​

ADC 将所有配置选项暴露为环境变量。例如,你可以分别使用 ADC_BACKEND 和 ADC_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
检查与指定后端的连通性​
adc ping --backend api7ee --server https://localhost:7443

adc lint​

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

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

使用示例​

检查指定的配置文件​
adc lint -f adc.yaml
检查多个配置文件​
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 adc.yaml
从多个文件同步配置​
adc sync -f service-a.yaml -f service-b.yaml
将配置同步到指定网关组​
adc sync -f adc.yaml --gateway-group production
跳过检查并同步配置​
adc sync -f adc.yaml --no-lint
同步配置并输出调试日志​
adc sync -f adc.yaml --verbose 2
将配置同步到指定后端​
adc sync -f service-a.yaml -f service-b.yaml --backend api7ee --server https://localhost:7443
仅同步配置文件中的指定资源类型​
adc sync -f adc.yaml --include-resource-type global_rule --include-resource-type plugin_metadata
仅同步带指定标签的资源​
adc sync -f adc.yaml --label-selector app=catalog

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.yaml​
adc dump
将后端配置保存到指定文件​
adc dump -o service-configuration.yaml
仅保存后端中的指定资源类型​
adc dump --include-resource-type global_rule --include-resource-type plugin_metadata
仅保存带指定标签的资源​
adc dump --label-selector app=catalog
保存指定后端的配置​
adc dump -o api7ee-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 adc.yaml
将多个文件中的配置与后端配置比较​
adc diff -f service-a.yaml -f service-b.yaml
将指定文件中的配置与指定后端比较​
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.

使用示例​

将 YAML 格式的 OpenAPI 规范转换为 ADC 配置并保存到默认文件 adc.yaml​
adc convert openapi -f openapi.yaml
将 JSON 格式的 OpenAPI 规范转换为 ADC 配置并保存到指定文件​
adc convert openapi -f openapi.json -o converted-adc.yaml

更多说明请参阅 OpenAPI 转换器参考。

adc help​

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

使用示例​

adc help [command]