在 Google Kubernetes Engine 上安装 Red Hat Developer Hub
使用 Operator 或 Helm Chart 在 Google Kubernetes Engine (GKE)上运行 Red Hat Developer Hub
摘要
前言 复制链接链接已复制到粘贴板!
您可以使用以下方法之一在 Google Kubernetes Engine (GKE)上安装 Red Hat Developer Hub:
- Red Hat Developer Hub Operator
- Red Hat Developer Hub Helm chart
第 1 章 使用 OLM 框架安装 Developer Hub Operator 复制链接链接已复制到粘贴板!
您可以使用 Operator Lifecycle Manager (OLM)框架在 GKE 上安装 Developer Hub Operator。之后,您可以继续在 GKE 中部署 Developer Hub 实例。
有关 OLM 的详情,请参考 Operator Lifecycle Manager (OLM) 文档。
先决条件
-
您已订阅了
registry.redhat.io。如需更多信息,请参阅 Red Hat Container Registry 身份验证。 - 已安装 Operator Lifecycle Manager (OLM)。有关安装和故障排除的更多信息,请参阅 如何获取 Operator Lifecycle Manager?
-
已安装
kubectl。如需更多信息,请参阅安装 kubetl。 - 已安装 Google Cloud CLI。如需更多信息,请参阅安装 gcloud CLI。
- 您已登录到 Google 帐户,并创建了 GKE Autopilot 或 GKE Standard 集群。
流程
使用以下命令连接到您的 GKE 集群:
gcloud container clusters get-credentials <cluster-name> \1 --location=<cluster-location>2 此命令将 Kubernetes 客户端配置为指向您的 GKE 集群。
在终端中运行以下命令,以创建安装 Operator 的
rhdh-operator命名空间:kubectl create namespace rhdh-operator使用以下命令创建 pull secret:
kubectl -n rhdh-operator create secret docker-registry rhdh-pull-secret \ --docker-server=registry.redhat.io \ --docker-username=<user_name> \1 --docker-password=<password> \2 --docker-email=<email>3 创建的 pull secret 用于从红帽生态系统中拉取 Developer Hub 镜像。
创建包含红帽生态系统中的 Operator 的
CatalogSource资源:CatalogSource资源示例cat <<EOF | kubectl -n rhdh-operator apply -f - apiVersion: operators.coreos.com/v1alpha1 kind: CatalogSource metadata: name: redhat-catalog spec: sourceType: grpc image: registry.redhat.io/redhat/redhat-operator-index:v4.18 secrets: - "rhdh-pull-secret" displayName: Red Hat Operators EOF按如下所示创建
OperatorGroup资源:OperatorGroup资源示例cat <<EOF | kubectl apply -n rhdh-operator -f - apiVersion: operators.coreos.com/v1 kind: OperatorGroup metadata: name: rhdh-operator-group EOF使用以下代码创建
Subscription资源:Subscription资源示例cat <<EOF | kubectl apply -n rhdh-operator -f - apiVersion: operators.coreos.com/v1alpha1 kind: Subscription metadata: name: rhdh namespace: rhdh-operator spec: channel: fast installPlanApproval: Automatic name: rhdh source: redhat-catalog sourceNamespace: rhdh-operator startingCSV: rhdh-operator.v1.6.3 EOF运行以下命令,以验证创建的 Operator 是否正在运行:
kubectl -n rhdh-operator get pods -w如果 Operator pod 显示
ImagePullBackOff状态,您可能需要直接在 Operator 部署清单中拉取镜像的权限。提示您可以在
deployment.spec.template.spec.imagePullSecrets列表中包括所需的 secret 名称,并使用kubectl get deployment -n rhdh-operator命令验证部署名称。例如:kubectl -n rhdh-operator patch deployment \ rhdh.fast --patch '{"spec":{"template":{"spec":{"imagePullSecrets":[{"name":"rhdh-pull-secret"}]}}}}' \ --type=merge
1.1. 使用 Operator 在 GKE 上部署 Developer Hub 实例 复制链接链接已复制到粘贴板!
您可以使用 Operator 在 GKE 中部署 Developer Hub 实例。
先决条件
- 集群管理员已安装了 Red Hat Developer Hub Operator。
-
您已订阅了
registry.redhat.io。如需更多信息,请参阅 Red Hat Container Registry 身份验证。 -
已安装
kubectl。如需更多信息,请参阅安装 kubetl。 - 您已为 Developer Hub 实例配置了域名。
- 您已保留了一个未附加到任何虚拟机(VM)的静态外部高级 IPv4 全局 IP 地址。如需更多信息,请参阅 保留新的静态外部 IP 地址
您已为域名配置了 DNS 记录,以指向已保留的 IP 地址。
注意您需要创建一个等于 IP 地址的
A记录。此过程最多可能需要一小时才能传播。
流程
使用以下模板创建一个包含
Developer Hub 配置文件的 app-config.yaml 配置映射:app-config.yamlapp-config.yaml片段apiVersion: v1 kind: ConfigMap metadata: name: my-rhdh-app-config data: "app-config.yaml": | app: title: Red Hat Developer Hub baseUrl: https://<rhdh_domain_name> backend: auth: externalAccess: - type: legacy options: subject: legacy-default-config secret: "${BACKEND_SECRET}" baseUrl: https://<rhdh_domain_name> cors: origin: https://<rhdh_domain_name>创建一个 &
lt;my_product_secrets> secret,并添加名为BACKEND_SECRET的键,并带有Base64 编码的字符串值,如下例所示:apiVersion: v1 kind: Secret metadata: name: <my_product_secrets>1 stringData: # TODO: See https://backstage.io/docs/auth/service-to-service-auth/#setup BACKEND_SECRET: "xxx"- 1
<my_product_secrets> 是您首选的 Developer Hub secret 名称,其中 <my_product_secrets> 指定 Developer Hub 中 secret 配置的标识符。
重要确保为每个 Developer Hub 实例使用唯一的
BACKEND_SECRET值。您可以使用以下命令生成密钥:
node-p'require("crypto").randomBytes(24).toString("base64")'要启用从 Red Hat Ecosystem Catalog 拉取 PostgreSQL 镜像,请在部署 Developer Hub 实例的命名空间中的 default 服务帐户中添加镜像 pull secret:
kubectl patch serviceaccount default \ -p '{"imagePullSecrets": [{"name": "rhdh-pull-secret"}]}' \ -n <your_namespace>使用以下模板创建
Backstage自定义资源(CR)文件:自定义资源片段
apiVersion: rhdh.redhat.com/v1alpha3 kind: Backstage metadata: # This is the name of your Developer Hub instance name: my-rhdh spec: application: imagePullSecrets: - "rhdh-pull-secret" route: enabled: false appConfig: configMaps: - name: my-rhdh-app-config extraEnvs: secrets: - name: <my_product_secrets>1 - 1
<my_product_secrets> 是您首选的 Developer Hub secret 名称,其中 <my_product_secrets> 指定 Developer Hub 中 secret 配置的标识符。
通过创建一个
ManagedCertificate对象来设置 Google 管理的证书,您必须附加到 Ingress,如下例所示:apiVersion: networking.gke.io/v1 kind: ManagedCertificate metadata: name: <rhdh_certificate_name> spec: domains: - <rhdh_domain_name>有关设置 Google 管理的证书的更多信息,请参阅设置 Google 管理的证书。
创建
FrontendConfig对象,来为重定向到 HTTPS 设置策略。您必须将此策略附加到 Ingress。FrontendConfig对象示例apiVersion: networking.gke.io/v1beta1 kind: FrontendConfig metadata: name: <ingress_security_config> spec: sslPolicy: gke-ingress-ssl-policy-https redirectToHttps: enabled: true有关将策略设置为重定向到 HTTPS 的更多信息,请参阅 HTTP 到 HTTPS 重定向。
使用以下模板创建入口资源,根据需要自定义名称:
ingress 资源配置示例
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: # TODO: this the name of your Developer Hub Ingress name: my-rhdh annotations: # If the class annotation is not specified it defaults to "gce". kubernetes.io/ingress.class: "gce" kubernetes.io/ingress.global-static-ip-name: <ADDRESS_NAME> networking.gke.io/managed-certificates: <rhdh_certificate_name> networking.gke.io/v1beta1.FrontendConfig: <ingress_security_config> spec: ingressClassName: gce rules: # TODO: Set your application domain name. - host: <rhdh_domain_name> http: paths: - path: / pathType: Prefix backend: service: # TODO: my-rhdh is the name of your `Backstage` custom resource. # Adjust if you changed it! name: backstage-my-rhdh port: name: http-backend
验证
-
等待
ManagedCertificate被置备。这个过程可能需要几小时时间。 -
Access RHDH with
https://<rhdh_domain_name>
其他信息
有关使用 TLS 的 Ingress 设置 GKE 的更多信息,请参阅 安全 GKE Ingress。
第 2 章 使用 Helm Chart 在 GKE 上安装 Developer Hub 复制链接链接已复制到粘贴板!
当您在 Google Kubernetes Engine (GKE)中安装 Developer Hub Helm Chart 时,它会编配 Developer Hub 实例的部署,它在 GKE 生态系统中提供了强大的开发人员平台。
先决条件
-
您已订阅了
registry.redhat.io。如需更多信息,请参阅 Red Hat Container Registry 身份验证。 -
已安装
kubectl。如需更多信息,请参阅安装 kubetl。 - 已安装 Google Cloud CLI。如需更多信息,请参阅安装 gcloud CLI。
- 您已登录到 Google 帐户,并创建了 GKE Autopilot 或 GKE Standard 集群。
- 您已为 Developer Hub 实例配置了域名。
- 您已保留了一个未附加到任何虚拟机的静态外部高级 IPv4 全局 IP 地址。如需更多信息,请参阅 保留新的静态外部 IP 地址
您已为域名配置了 DNS 记录,以指向已保留的 IP 地址。
注意您需要创建一个等于 IP 地址的
A记录。此过程最多可能需要一小时才能传播。- 已安装 Helm 3 或最新的。如需更多信息,请参阅安装 Helm。
流程
进入终端并运行以下命令,将包含 Developer Hub chart 的 Helm Chart 仓库添加到本地 Helm registry 中:
helm repo add openshift-helm-charts https://charts.openshift.io/使用以下命令创建 pull secret:
kubectl -n <your-namespace> create secret docker-registry rhdh-pull-secret \1 --docker-server=registry.redhat.io \ --docker-username=<user_name> \2 --docker-password=<password> \3 --docker-email=<email>4 创建的 pull secret 用于从红帽生态系统中拉取 Developer Hub 镜像。
通过创建一个需要附加到 ingress 的
ManagedCertificate对象来设置 Google 管理的证书。将
ManagedCertificate对象附加到入口的示例apiVersion: networking.gke.io/v1 kind: ManagedCertificate metadata: name: <rhdh_certificate_name> spec: domains: - <rhdh_domain_name>有关设置 Google 管理的证书的更多信息,请参阅设置 Google 管理的证书。
创建
FrontendConfig对象,来为重定向到 HTTPS 设置策略。您必须将此策略附加到 ingress。将
FrontendConfig对象附加到入口的示例apiVersion: networking.gke.io/v1beta1 kind: FrontendConfig metadata: name: <ingress_security_config> spec: sslPolicy: gke-ingress-ssl-policy-https redirectToHttps: enabled: true有关将策略设置为重定向到 HTTPS 的更多信息,请参阅 HTTP 到 HTTPS 重定向。
使用以下模板创建一个名为
values.yaml的文件:values.yaml文件示例global: host: <rhdh_domain_name> route: enabled: false upstream: service: type: NodePort ingress: enabled: true annotations: kubernetes.io/ingress.class: gce kubernetes.io/ingress.global-static-ip-name: <ADDRESS_NAME> networking.gke.io/managed-certificates: <rhdh_certificate_name> networking.gke.io/v1beta1.FrontendConfig: <ingress_security_config> className: gce backstage: image: pullSecrets: - rhdh-pull-secret podSecurityContext: fsGroup: 2000 postgresql: image: pullSecrets: - rhdh-pull-secret primary: podSecurityContext: enabled: true fsGroup: 3000 volumePermissions: enabled: true在终端中运行以下命令,以使用最新版本的 Helm Chart 并使用
values.yaml文件部署 Developer Hub:helm -n <your_namespace> install -f values.yaml <your_deploy_name> \ openshift-helm-charts/redhat-developer-hub \ --version 1.6.3有关最新的 Helm Chart 版本,请参阅此 Helm Chart 仓库。
验证
确认部署已完成。
kubectl get deploy <you_deploy_name>-developer-hub -n <your_namespace>验证是否已创建服务和入口。
kubectl get service -n <your_namespace> kubectl get ingress -n <your_namespace>注意等待
ManagedCertificate被置备。这个过程可能需要几小时时间。-
Access RHDH with
https://<rhdh_domain_name> 要升级部署,请使用以下命令:
helm -n <your_namespace> upgrade -f values.yaml <your_deploy_name> openshift-helm-charts/redhat-developer-hub --version <UPGRADE_CHART_VERSION>要删除部署,请使用以下命令:
helm -n <your_namespace> delete <your_deploy_name>