5.18. 导出产品
您可以使用 .yaml
格式导出 3scale 产品定义,以便您可以将该产品导入到与源 3scale 实例没有连接的 3scale 实例中。您必须先设置 3scale 产品,然后才能导出该产品。请参阅 创建新产品来测试 API 调用。
当两个 3scale 实例具有网络连接时,当您想要在 3scale 实例中使用相同的 3scale 产品时,请使用 toolbox 3scale copy
命令。
描述
当您导出 3scale 产品时,toolbox 以 .yaml
格式序列化产品定义,该定义遵循 Product 和 Backend 自定义资源定义(CRD)。如需更多信息,请参阅使用 3scale 操作器配置和置备 3scale。除了产品的基本信息外,输出 .yaml
还包括:
- 链接到产品的后端。
- 链接后端的指标、方法和映射规则.
- 应用计划中定义的限值和定价规则.
- 限值和定价规则引用的指标和方法。
导出产品是一种只读操作。换句话说,重复导出产品是安全的。toolbox 不会更改要导出的产品。如果需要,您可以在将 .yaml
输出导入到另一个 3scale 实例前修改它。
导出 3scale 产品适用于以下情况:
-
源和目标 3scale 实例之间没有连接。例如,当您想要在多个 3scale 实例中使用同一产品时,可能会存在严重网络限制阻止运行 toolbox
3scale copy
命令。 -
您需要使用 Git 或其它源控制系统来维护 3scale 产品定义(采用
.yaml
格式)。
3scale toolbox export
和 import
命令也可能有助于备份和恢复产品定义。
格式
使用此格式运行 export
命令:
$ 3scale product export [-f output-file] <remote> <product>
export
命令可以将输出发送到 stdout
或文件。默认值为 stdout
。要将输出发送到一个文件,请使用 -f
或 --file
选项指定带有 .yaml
的文件名称。
将 <remote>
替换为与您要从中导出产品的 3scale 实例关联的 3scale 供应商帐户别名或 URL。有关指定此功能的更多信息,请参阅管理远程访问凭证。
将 <product>
替换为您要导出的产品的系统名称或 3scale ID。此产品必须与您指定的 3scale 供应商帐户关联。您可以在产品 概述 页面的 3scale GUI 中找到产品的系统名称。要获得产品的 3scale ID,请运行 toolbox 3scale services show
命令。
示例
以下命令从与 my-3scale-1
供应商帐户关联的 3scale 实例导出 petstore
产品,并将其输出到 petstore-product.yaml
文件:
$ 3scale product export -f petstore-product.yaml my-3scale-1 petstore
以下是 Default API
产品的序列化示例:
apiVersion: v1 kind: List items: - apiVersion: capabilities.3scale.net/v1beta1 kind: Product metadata: annotations: 3scale_toolbox_created_at: '2021-02-17T10:59:23Z' 3scale_toolbox_version: 0.17.1 name: api.xysnalcj spec: name: Default API systemName: api description: '' mappingRules: - httpMethod: GET pattern: "/v2" metricMethodRef: hits increment: 1 last: false metrics: hits: friendlyName: Hits unit: hit description: Number of API hits methods: servicemethod01: friendlyName: servicemethod01 description: '' policies: - name: apicast version: builtin configuration: {} enabled: true applicationPlans: basic: name: Basic appsRequireApproval: false trialPeriod: 0 setupFee: 0.0 custom: false state: published costMonth: 0.0 pricingRules: - from: 1 to: 1000 pricePerUnit: 1.0 metricMethodRef: systemName: hits limits: - period: hour value: 1222222 metricMethodRef: systemName: hits backend: backend_01 backendUsages: backend_01: path: "/v1/pets" backend_02: path: "/v1/cats" deployment: apicastSelfManaged: authentication: oidc: issuerType: rest issuerEndpoint: https://hello:test@example.com/auth/realms/3scale-api-consumers jwtClaimWithClientID: azp jwtClaimWithClientIDType: plain authenticationFlow: standardFlowEnabled: false implicitFlowEnabled: true serviceAccountsEnabled: false directAccessGrantsEnabled: true credentials: query security: hostHeader: '' secretToken: some_secret gatewayResponse: errorStatusAuthFailed: 403 errorHeadersAuthFailed: text/plain; charset=us-ascii errorAuthFailed: Authentication failed errorStatusAuthMissing: 403 errorHeadersAuthMissing: text/plain; charset=us-ascii errorAuthMissing: Authentication parameters missing errorStatusNoMatch: 404 errorHeadersNoMatch: text/plain; charset=us-ascii errorNoMatch: No Mapping Rule matched errorStatusLimitsExceeded: 429 errorHeadersLimitsExceeded: text/plain; charset=us-ascii errorLimitsExceeded: Usage limit exceeded stagingPublicBaseURL: http://staging.example.com:80 productionPublicBaseURL: http://example.com:80 - apiVersion: capabilities.3scale.net/v1beta1 kind: Backend metadata: annotations: 3scale_toolbox_created_at: '2021-02-17T10:59:34Z' 3scale_toolbox_version: 0.17.1 name: backend.01.pcjwxbdu spec: name: Backend 01 systemName: backend_01 privateBaseURL: https://b1.example.com:443 description: new desc mappingRules: - httpMethod: GET pattern: "/v1/pets" metricMethodRef: hits increment: 1 last: false metrics: hits: friendlyName: Hits unit: hit description: Number of API hits methods: mybackendmethod01: friendlyName: mybackendmethod01 description: '' - apiVersion: capabilities.3scale.net/v1beta1 kind: Backend metadata: annotations: 3scale_toolbox_created_at: '2021-02-17T10:59:34Z' 3scale_toolbox_version: 0.17.1 name: backend.02.tiedgjsk spec: name: Backend 02 systemName: backend_02 privateBaseURL: https://b2.example.com:443 description: '' mappingRules: - httpMethod: GET pattern: "/v1/cats" metricMethodRef: hits increment: 1 last: false metrics: hits: friendlyName: Hits unit: hit description: Number of API hits methods: backend02_method01: friendlyName: backend02_method01 description: ''
导出和传送到 Product
CR
运行 export
命令时,您可以管道输出来创建 产品自定义资源(CR)。哪个 3scale 实例包含这个 CR 取决于以下条件:
-
如果定义了
threescale-provider-account
secret,3scale operator 会在由该 secret 标识的 3scale 实例中创建 product CR。 -
如果没有定义
threescale-provider-account
secret,那么如果命名空间中安装了 3scale 实例,则新产品 CR 将位于该命名空间中,3scale 操作器会在该命名空间中创建产品 CR。 -
如果没有定义
threescale-provider-account
secret,如果新产品 CR 所在的命名空间不包含 3scale 实例,则 3scale 操作器会将产品 CR 标记为失败状态。
假设您在包含 3scale-provider-account
机密的命名空间中运行以下命令:toolbox 将 petstore
CR 传送到 3scale 实例,该实例在 3scale-provider-account
secret 中标识:
$ 3scale product export my-3scale-1 petstore | oc apply -f -