第 6 章 功能:通过操作器提供 3scale 服务和配置
本文档包含有关功能 3scale 操作器的信息,其中包括通过 OpenShift Container Platform(OCP)用户界面通过 3scale 操作器置备 3scale 服务和配置。
3scale 的功能操作器只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围。
先决条件
- 具有 3scale 2.8 On-Premises 实例管理员特权的用户帐户
- 已安装 3scale Operator。
OpenShift Container Platform 4,具有在 OpenShift 集群中具有管理员特权的用户帐户。
- 备注:OCP 4 支持仅使用操作器部署 3scale。
- 有关支持配置的更多信息,请参阅 Red Hat 3scale API 管理支持的配置 页面。
当使用 3scale 操作器在 3scale 中更新 API 配置时,自定义资源定义(CRD)是事实的来源。如果在 Admin 用户界面中进行更改,它们不会持久存在,最终会被 CRD 中的定义覆盖。
以下小节解释了如何部署与功能相关的自定义资源、部署可选租户自定义资源以及如何删除自定义资源:
6.1. 部署与功能相关的自定义资源 复制链接链接已复制到粘贴板!
在新创建的租户中使用 Openshift Container Platform,您将配置 API、指标和 映射规则。
6.1.1. 创建 API 复制链接链接已复制到粘贴板!
以下流程创建带有标签 api: api01
的 API。
步骤
点 Catalog > Installed Operators。
- 从 Installed Operators 列表中,点 3scale Operator。
- 单击 API 选项卡。
- 点击 Create API。
清除示例内容,并将以下 YAML 定义添加到编辑器中,然后单击 Create。
apiVersion: capabilities.3scale.net/v1alpha1 kind: API metadata: creationTimestamp: 2019-01-25T13:28:41Z generation: 1 labels: environment: testing name: api01 spec: planSelector: matchLabels: api: api01 description: api01 integrationMethod: apicastHosted: apiTestGetRequest: / authenticationSettings: credentials: apiKey: authParameterName: user-key credentialsLocation: headers errors: authenticationFailed: contentType: text/plain; charset=us-ascii responseBody: Authentication failed responseCode: 403 authenticationMissing: contentType: text/plain; charset=us-ascii responseBody: Authentication Missing responseCode: 403 hostHeader: "" secretToken: Shared_secret_sent_from_proxy_to_API_backend_9603f637ca51ccfe mappingRulesSelector: matchLabels: api: api01 privateBaseURL: https://echo-api.3scale.net:443 metricSelector: matchLabels: api: api01
apiVersion: capabilities.3scale.net/v1alpha1 kind: API metadata: creationTimestamp: 2019-01-25T13:28:41Z generation: 1 labels: environment: testing name: api01 spec: planSelector: matchLabels: api: api01 description: api01 integrationMethod: apicastHosted: apiTestGetRequest: / authenticationSettings: credentials: apiKey: authParameterName: user-key credentialsLocation: headers errors: authenticationFailed: contentType: text/plain; charset=us-ascii responseBody: Authentication failed responseCode: 403 authenticationMissing: contentType: text/plain; charset=us-ascii responseBody: Authentication Missing responseCode: 403 hostHeader: "" secretToken: Shared_secret_sent_from_proxy_to_API_backend_9603f637ca51ccfe mappingRulesSelector: matchLabels: api: api01 privateBaseURL: https://echo-api.3scale.net:443 metricSelector: matchLabels: api: api01
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意所有选择器(指标、计划、映射规则)都使用特定标签
api: api01
。您可以通过添加更多标签和配置选择器来改变这种情况,以解决复杂的场景。
6.1.2. 添加计划 复制链接链接已复制到粘贴板!
以下流程添加带有标签 api: api01
的计划。
步骤
点 Catalog > Installed Operators。
- 从 Installed Operators 列表中,点 3scale Operator。
- 点 Plan 选项卡。
- 点击 Create Plan。
清除示例内容,并将以下 YAML 定义添加到编辑器中,然后单击 Create。
apiVersion: capabilities.3scale.net/v1alpha1 kind: Plan metadata: labels: api: api01 name: plan01 spec: approvalRequired: false default: true costs: costMonth: 0 setupFee: 0 limitSelector: matchLabels: api: api01 trialPeriod: 0
apiVersion: capabilities.3scale.net/v1alpha1 kind: Plan metadata: labels: api: api01 name: plan01 spec: approvalRequired: false default: true costs: costMonth: 0 setupFee: 0 limitSelector: matchLabels: api: api01 trialPeriod: 0
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
6.1.3. 添加指标 复制链接链接已复制到粘贴板!
以下流程添加名为 metric01 的指标
。
步骤
点 Catalog > Installed Operators。
- 从 Installed Operators 列表中,点 3scale Operator。
- 单击 Metric 选项卡。
- 单击 Create Metric。
清除示例内容,并将以下 YAML 定义添加到编辑器中,然后单击 Create。
apiVersion: capabilities.3scale.net/v1alpha1 kind: Metric metadata: labels: api: api01 name: metric01 spec: description: metric01 unit: hit incrementHits: false
apiVersion: capabilities.3scale.net/v1alpha1 kind: Metric metadata: labels: api: api01 name: metric01 spec: description: metric01 unit: hit incrementHits: false
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
6.1.4. 设置限制 复制链接链接已复制到粘贴板!
以下流程设置指标的点击次数限制为每天 10 个。
步骤
点 Catalog > Installed Operators。
- 从 Installed Operators 列表中,点 3scale Operator。
- 单击 限制 选项卡。
- 单击 Create Limit。
清除示例内容,并将以下 YAML 定义添加到编辑器中,然后单击 Create。
apiVersion: capabilities.3scale.net/v1alpha1 kind: Limit metadata: labels: api: api01 name: plan01-metric01-day-10 spec: description: Limit for metric01 in plan01 maxValue: 10 metricRef: name: metric01 period: day
apiVersion: capabilities.3scale.net/v1alpha1 kind: Limit metadata: labels: api: api01 name: plan01-metric01-day-10 spec: description: Limit for metric01 in plan01 maxValue: 10 metricRef: name: metric01 period: day
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
6.1.5. 添加映射规则 复制链接链接已复制到粘贴板!
以下流程添加一个 MappingRule 来 递增 metric01
。
步骤
点 Catalog > Installed Operators。
- 从 Installed Operators 列表中,点 3scale Operator。
- 点 MappingRule 选项卡。
- 点 Create Mapping Rule。
清除示例内容,并将以下 YAML 定义添加到编辑器中,然后单击 Create。
apiVersion: capabilities.3scale.net/v1alpha1 kind: MappingRule metadata: labels: api: api01 name: metric01-get-path01 spec: increment: 1 method: GET metricRef: name: metric01 path: /path01
apiVersion: capabilities.3scale.net/v1alpha1 kind: MappingRule metadata: labels: api: api01 name: metric01-get-path01 spec: increment: 1 method: GET metricRef: name: metric01 path: /path01
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
6.1.6. 创建绑定 复制链接链接已复制到粘贴板!
以下流程与绑定对象、API、计划、指标、设置限制和您之前创建的映射规则结合在一起。使用由 Tenant Controller 创建的凭证:
步骤
点 Catalog > Installed Operators。
- 从 Installed Operators 列表中,点 3scale Operator。
- 单击 绑定 选项卡。
- 单击 Create Binding。
清除示例内容,并将以下 YAML 定义添加到编辑器中,然后单击 Create。
apiVersion: capabilities.3scale.net/v1alpha1 kind: Binding metadata: name: mytestingbinding spec: credentialsRef: name: ecorp-tenant-secret APISelector: matchLabels: environment: testing
apiVersion: capabilities.3scale.net/v1alpha1 kind: Binding metadata: name: mytestingbinding spec: credentialsRef: name: ecorp-tenant-secret APISelector: matchLabels: environment: testing
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 绑定对象引用
ecorp-tenant-secret
,并创建标记为environment: stage
的 API 对象。- 导航到新的 3scale 租户,检查前面步骤中执行的所有操作都已创建好。