×

本节概述了 OpenShift Serverless Logic 必要的支持服务。它特别关注使用 OpenShift Serverless Logic 运算符配置和部署数据索引服务和作业服务支持服务。

在典型的 OpenShift Serverless Logic 安装中,必须部署这两个服务才能确保工作流成功执行。数据索引服务允许高效的数据管理,而作业服务确保可靠的作业处理。

支持服务和工作流集成

在给定命名空间中部署支持服务时,可以选择启用或禁用部署。启用部署会指示 OpenShift Serverless Logic 运算符自动拦截使用命名空间内的previewgitops配置文件的工作流部署,并将其配置为连接到该服务。

例如,当启用数据索引服务时,工作流会自动配置为向其发送状态更改事件。同样,启用作业服务可确保每当工作流需要超时时都会创建一个作业。OpenShift Serverless Logic 运算符还会将作业服务配置为向数据索引服务发送事件,从而促进服务之间的无缝集成。

OpenShift Serverless Logic 运算符不仅部署支持服务,还管理其他必要的配置以确保工作流成功执行。所有这些配置都是自动处理的。您只需要在SonataFlowPlatform CR 中提供支持服务的配置。

仅部署其中一项支持服务或使用禁用的部署属于高级用例。在标准安装中,必须启用这两个服务才能确保工作流顺利执行。

使用 SonataFlowPlatform CR 部署支持服务

要部署支持服务,请在SonataFlowPlatform自定义资源 (CR) 的spec.services部分中配置dataIndexjobService子字段。此配置指示 OpenShift Serverless Logic 运算符在应用SonataFlowPlatform CR 时部署每个服务。

每个服务的配置都是独立处理的,允许您在SonataFlowPlatform CR 中与其他配置一起自定义这些设置。

请参阅以下部署支持服务的脚手架示例配置

apiVersion: sonataflow.org/v1alpha08
kind: SonataFlowPlatform
metadata:
  name: sonataflow-platform-example
  namespace: example-namespace
spec:
  services:
    dataIndex: (1)
      enabled: true (2)
      # Specific configurations for the Data Index Service
      # might be included here
    jobService: (3)
      enabled: true (4)
      # Specific configurations for the Job Service
      # might be included here
1 数据索引服务配置字段。
2 设置enabled: true将部署数据索引服务。如果设置为false或省略,则部署将被禁用。默认值为false
3 作业服务配置字段。
4 设置enabled: true将部署作业服务。如果设置为false或省略,则部署将被禁用。默认值为false

支持服务的范围

SonataFlowPlatform自定义资源 (CR) 允许在特定命名空间内部署支持服务。这意味着所有自动配置的支持服务和工作流通信都限制在部署平台的命名空间中。

此功能在需要为不同的工作流集提供单独的支持服务实例时特别有用。例如,您可以隔离地部署应用程序及其工作流和支持服务,确保它们与其他部署保持独立。

支持服务的持久化配置

OpenShift Serverless Logic 中支持服务的持久化配置可以是临时配置或 PostgreSQL 配置,具体取决于环境的需求。临时持久化非常适合开发和测试,而 PostgreSQL 持久化则推荐用于生产环境。

临时持久化配置

短暂持久化使用嵌入式PostgreSQL数据库,每个服务专用一个。OpenShift Serverless Logic Operator会在每次服务重启时重新创建此数据库,因此仅适用于开发和测试目的。除了以下SonataFlowPlatform CR之外,您无需任何其他配置。

apiVersion: sonataflow.org/v1alpha08
kind: SonataFlowPlatform
metadata:
  name: sonataflow-platform-example
  namespace: example-namespace
spec:
  services:
    dataIndex:
      enabled: true
      # Specific configurations for the Data Index Service
      # might be included here
    jobService:
      enabled: true
      # Specific configurations for the Job Service
      # might be included here

PostgreSQL持久化配置

对于PostgreSQL持久化,您必须在集群上设置一个PostgreSQL服务器实例。此实例的管理独立于OpenShift Serverless Logic Operator的控制。要将支持服务与PostgreSQL服务器连接,您必须配置相应的数据库连接参数。

您可以使用以下示例在SonataFlowPlatform CR中配置PostgreSQL持久化

PostgreSQL持久化配置示例
apiVersion: sonataflow.org/v1alpha08
kind: SonataFlowPlatform
metadata:
  name: sonataflow-platform-example
  namespace: example-namespace
spec:
  services:
    dataIndex:
      enabled: true
      persistence:
        postgresql:
          serviceRef:
            name: postgres-example (1)
            namespace: postgres-example-namespace (2)
            databaseName: example-database (3)
            databaseSchema: data-index-schema (4)
            port: 1234 (5)
          secretRef:
            name: postgres-secrets-example (6)
            userKey: POSTGRESQL_USER (7)
            passwordKey: POSTGRESQL_PASSWORD (8)
    jobService:
      enabled: true
      persistence:
        postgresql:
        # Specific database configuration for the Job Service
        # might be included here.
1 要连接PostgreSQL数据库服务器的服务名称。
2 可选:定义PostgreSQL服务的命名空间。默认为SonataFlowPlatform命名空间。
3 定义用于存储支持服务数据的PostgreSQL数据库名称。
4 可选:指定用于存储支持服务数据的模式。默认值为SonataFlowPlatform名称,后缀为-data-index-service-jobs-service。例如,sonataflow-platform-example-data-index-service
5 可选:连接PostgreSQL服务的端口号。默认值为5432
6 定义包含数据库访问用户名和密码的密钥名称。
7 定义密钥中包含用于连接数据库的用户名。
8 定义密钥中包含用于连接数据库的密码。

您可以使用相应的持久化字段独立配置每个服务的持久化。

运行以下命令创建访问PostgreSQL的密钥

$ oc create secret generic <postgresql_secret_name> \
  --from-literal=POSTGRESQL_USER=<user> \
  --from-literal=POSTGRESQL_PASSWORD=<password> \
  -n <namespace>

公共PostgreSQL持久化配置

OpenShift Serverless Logic Operator会自动将支持服务连接到在spec.persistence字段中配置的公共PostgreSQL服务器。

对于规则,适用以下优先级:

  • 如果为支持服务配置了特定的持久化,例如services.dataIndex.persistence,则使用该配置。

  • 如果未为服务配置持久化,则系统使用当前平台的公共持久化配置。

使用公共PostgreSQL配置时,每个服务的模式会自动设置为SonataFlowPlatform名称,后缀为-data-index-service-jobs-service,例如sonataflow-platform-example-data-index-service

高级支持服务配置

在必须为支持服务应用高级配置的场景中,请使用SonataFlowPlatform自定义资源 (CR) 中的podTemplate字段。此字段允许您通过指定配置(例如副本数、环境变量、容器映像和初始化选项)来自定义服务 Pod 部署。

您可以使用以下示例配置服务的高级设置

数据索引服务的高级配置示例
apiVersion: sonataflow.org/v1alpha08
kind: SonataFlowPlatform
metadata:
  name: sonataflow-platform-example
  namespace: example-namespace
spec:
  services:
    # This can be either 'dataIndex' or 'jobService'
    dataIndex:
      enabled: true
      podTemplate:
        replicas: 2 (1)
        container: (2)
          env: (3)
            - name: <any_advanced_config_property>
              value: <any_value>
          image: (4)
        initContainers: (5)

您可以根据需求将“services”字段设置为“dataIndex”或“jobService”。其余配置保持不变。

1 定义副本数。默认值为1。对于jobService,此值始终被覆盖为1,因为它作为单例服务运行。
2 包含运行服务的容器的特定配置。
3 允许您通过指定环境变量来微调服务属性。
4 配置服务的容器镜像,如果您需要更新或自定义镜像,这将非常有用。
5 为Pod配置初始化容器,这对于在主容器启动之前设置先决条件非常有用。

podTemplate字段为定制每个支持服务的部署提供了灵活性。它遵循标准PodSpec API,这意味着相同的 API 验证规则也适用于这些字段。

集群范围的支持服务

您可以使用SonataFlowClusterPlatform自定义资源 (CR) 定义可在不同命名空间的流程中使用的集群范围的支持服务集。通过引用现有的命名空间特定SonataFlowPlatform CR,您可以扩展这些服务的集群范围使用。

您可以使用以下基本配置示例,使部署在任何命名空间中的工作流都能利用部署在特定命名空间(例如example-namespace)中的支持服务。

SonataFlowClusterPlatform CR 示例
apiVersion: sonataflow.org/v1alpha08
kind: SonataFlowClusterPlatform
metadata:
  name: cluster-platform
spec:
  platformRef:
    name: sonataflow-platform-example (1)
    namespace: example-namespace (2)
1 指定已安装的管理支持服务的SonataFlowPlatform CR 的名称。
2 指定管理支持服务的SonataFlowPlatform CR 的命名空间。

您可以通过在SonataFlowPlatform.spec.services中配置该命名空间来覆盖任何命名空间中的这些集群范围的服务。