第 2 章 安装 API 控制器
要安装 API 控制器,请使用 community Operator。
先决条件
-
对 OpenShift 集群的
cluster-admin访问权限。
流程
-
在 OpenShift Container Platform web 控制台中,使用
cluster-admin权限登录。 - 在左侧导航菜单中,点 Operators > OperatorHub。
-
在 Filter by keyword 文本框中,输入
Apicurio来查找 Apicurio API Controller。 - 阅读 Operator 信息,然后点 Install 显示 Operator 订阅页面。
接受以下通知的默认订阅设置:
- 安装模式 :集群中的所有命名空间(默认)
- 安装的命名空间 :选择要安装 Operator 的命名空间,如 api-controller。如果命名空间尚不存在,点此字段并选择 Create Project 来创建命名空间。
- 批准策略 :选择 Automatic 或 Manual。
- 点 Install,然后等待片刻,直到 Operator 安装并可供使用。
-
验证是否安装了 Operator。安装 Operator 后,点 Operators > Installed Operators 来验证 Apicurio API Controller 是否已安装到所选命名空间中,如
api-controller。 - 进入 OpenShift Container Platform Web 控制台中的 Developer 视图,以应用安装所需的 YAML。
使用
api-controller命名空间中的以下 YAML 创建 PostgreSQL 数据库:apiVersion: v1 kind: PersistentVolumeClaim metadata: name: registry-pvc namespace: api-controller spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi # Adjust the storage size as needed --- apiVersion: apps/v1 kind: Deployment metadata: namespace: "api-controller" labels: app: postgresql name: postgresql spec: replicas: 1 selector: matchLabels: app: postgresql template: metadata: labels: app: postgresql spec: initContainers: - name: init-data image: busybox command: ['sh', '-c', 'rm -rf /var/lib/postgresql/data/* && mkdir -p /var/lib/postgresql/data/pgdata'] volumeMounts: - mountPath: "/var/lib/postgresql/data" name: "registry-pgdata" containers: - name: postgresql image: quay.io/debezium/postgres:13-alpine ports: - containerPort: 5432 env: - name: POSTGRES_DB value: registry - name: POSTGRES_USER value: apicurio - name: POSTGRES_PASSWORD value: registry - name: PGDATA value: "/var/lib/postgresql/data/pgdata" volumeMounts: - mountPath: "/var/lib/postgresql/data" name: "registry-pgdata" volumes: - name: registry-pgdata persistentVolumeClaim: claimName: registry-pvc --- apiVersion: v1 kind: Service metadata: namespace: "api-controller" labels: app: postgresql name: postgresql-service spec: ports: - name: http port: 5432 protocol: TCP targetPort: 5432 selector: app: postgresql type: ClusterIPapiVersion: v1 kind: PersistentVolumeClaim metadata: name: registry-pvc namespace: api-controller spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi # Adjust the storage size as needed --- apiVersion: apps/v1 kind: Deployment metadata: namespace: "api-controller" labels: app: postgresql name: postgresql spec: replicas: 1 selector: matchLabels: app: postgresql template: metadata: labels: app: postgresql spec: initContainers: - name: init-data image: busybox command: ['sh', '-c', 'rm -rf /var/lib/postgresql/data/* && mkdir -p /var/lib/postgresql/data/pgdata'] volumeMounts: - mountPath: "/var/lib/postgresql/data" name: "registry-pgdata" containers: - name: postgresql image: quay.io/debezium/postgres:13-alpine ports: - containerPort: 5432 env: - name: POSTGRES_DB value: registry - name: POSTGRES_USER value: apicurio - name: POSTGRES_PASSWORD value: registry - name: PGDATA value: "/var/lib/postgresql/data/pgdata" volumeMounts: - mountPath: "/var/lib/postgresql/data" name: "registry-pgdata" volumes: - name: registry-pgdata persistentVolumeClaim: claimName: registry-pvc --- apiVersion: v1 kind: Service metadata: namespace: "api-controller" labels: app: postgresql name: postgresql-service spec: ports: - name: http port: 5432 protocol: TCP targetPort: 5432 selector: app: postgresql type: ClusterIPCopy to Clipboard Copied! Toggle word wrap Toggle overflow 使用
api-controller命名空间中的以下 YAML 创建名为apicurio的 CR 和所需的路由:注意将
mycluster.example.com替换为集群主机名。# Replace mycluster.example.com with your cluster hostname # Create an API Controller custom resource apiVersion: registry.apicur.io/v1 kind: ApicurioRegistry3 metadata: name: apicurio namespace: api-controller spec: studioUi: enabled: true env: - name: APICURIO_REGISTRY_API_URL value: 'https://api-controller-app.apps.mycluster.example.com/apis/registry/v3' - name: APICURIO_REGISTRY_UI_URL value: 'https://api-controller-ui.apps.mycluster.example.com' ui: env: - name: REGISTRY_API_URL value: 'https://api-controller-app.apps.mycluster.example.com/apis/registry/v3' app: sql: dataSource: username: apicurio password: registry url: 'jdbc:postgresql://postgresql-service:5432/registry' --- # Create a route for the Apicurio Registry API apiVersion: route.openshift.io/v1 kind: Route metadata: name: api-controller-registry-api namespace: api-controller spec: host: api-controller-app.apps.mycluster.example.com path: / to: kind: Service name: apicurio-app-service port: targetPort: http tls: termination: edge insecureEdgeTerminationPolicy: Redirect wildcardPolicy: None --- # Create a route for the Apicurio Registry UI apiVersion: route.openshift.io/v1 kind: Route metadata: name: api-controller-registry-ui namespace: api-controller spec: host: api-controller-ui.apps.mycluster.example.com path: / to: kind: Service name: apicurio-ui-service port: targetPort: http tls: termination: edge insecureEdgeTerminationPolicy: Redirect wildcardPolicy: None --- # Create a route for the Apicurio Studio UI apiVersion: route.openshift.io/v1 kind: Route metadata: name: api-controller-studio-ui namespace: api-controller spec: host: api-controller-studio-ui.apps.mycluster.example.com path: / to: kind: Service name: apicurio-studio-ui-service port: targetPort: http tls: termination: edge insecureEdgeTerminationPolicy: Redirect wildcardPolicy: None# Replace mycluster.example.com with your cluster hostname # Create an API Controller custom resource apiVersion: registry.apicur.io/v1 kind: ApicurioRegistry3 metadata: name: apicurio namespace: api-controller spec: studioUi: enabled: true env: - name: APICURIO_REGISTRY_API_URL value: 'https://api-controller-app.apps.mycluster.example.com/apis/registry/v3' - name: APICURIO_REGISTRY_UI_URL value: 'https://api-controller-ui.apps.mycluster.example.com' ui: env: - name: REGISTRY_API_URL value: 'https://api-controller-app.apps.mycluster.example.com/apis/registry/v3' app: sql: dataSource: username: apicurio password: registry url: 'jdbc:postgresql://postgresql-service:5432/registry' --- # Create a route for the Apicurio Registry API apiVersion: route.openshift.io/v1 kind: Route metadata: name: api-controller-registry-api namespace: api-controller spec: host: api-controller-app.apps.mycluster.example.com path: / to: kind: Service name: apicurio-app-service port: targetPort: http tls: termination: edge insecureEdgeTerminationPolicy: Redirect wildcardPolicy: None --- # Create a route for the Apicurio Registry UI apiVersion: route.openshift.io/v1 kind: Route metadata: name: api-controller-registry-ui namespace: api-controller spec: host: api-controller-ui.apps.mycluster.example.com path: / to: kind: Service name: apicurio-ui-service port: targetPort: http tls: termination: edge insecureEdgeTerminationPolicy: Redirect wildcardPolicy: None --- # Create a route for the Apicurio Studio UI apiVersion: route.openshift.io/v1 kind: Route metadata: name: api-controller-studio-ui namespace: api-controller spec: host: api-controller-studio-ui.apps.mycluster.example.com path: / to: kind: Service name: apicurio-studio-ui-service port: targetPort: http tls: termination: edge insecureEdgeTerminationPolicy: Redirect wildcardPolicy: NoneCopy to Clipboard Copied! Toggle word wrap Toggle overflow
验证
导航到 api-controller- Studio-ui Route,再单击 Location URL。应该会显示 Apicurio Studio 控制台。