7.3.3. 插件服务代理
如果您需要从插件向集群服务发出 HTTP 请求,您可以使用 spec.proxy 数组字段在 ConsolePlugin 资源中声明服务代理。控制台后端公开 /api/proxy/plugin/<plugin-name>/<proxy-alias>/<request-path>?<optional-query-parameters> 端点来代理插件和服务之间的通信。代理请求默认使用 服务 CA 捆绑包。服务必须使用 HTTPS。
注意
该插件必须使用 consolefetch API 从 JavaScript 代码发出请求,或者一些请求可能会失败。如需更多信息,请参阅 "Dynamic plugin API"。
对于每个条目,您必须分别在 endpoint 和 alias 字段中指定代理的端点和别名。对于 Service 代理类型,您必须将端点 type 字段设置为 Service,service 必须包含 name, namespace, 和 port 字段的值。例如,/api/proxy/plugin/helm/helm-charts/releases?limit=10 是代理请求路径,它来自带有一个 helm-charts 服务的 helm 插件,列出 10 个 helm release。
服务代理示例
apiVersion: console.openshift.io/v1
kind: ConsolePlugin
metadata:
name:<plugin-name>
spec:
proxy:
- alias: helm-charts
authorization: UserToken
caCertificate: '-----BEGIN CERTIFICATE-----\nMIID....'en
endpoint:
service:
name: <service-name>
namespace: <service-namespace>
port: <service-port>
type: Service