部署 WebSphere Liberty 操作程序样本应用程序

在安装操作程序后,应用程序管理员可以将 WebSphereLibertyApplication 的样本应用程序映像部署到 Kubernetes 环境。 使用 Red Hat® OpenShift® 控制台或 kubectloc 命令部署应用程序映像。

在所有名称空间或要部署样本应用程序的名称空间中,必须安装 WebSphere® Liberty 操作程序。

已部署的样本应用程序在浏览器中显示了该应用程序的系统属性。

成功部署的样本应用程序浏览器页面,其中应用程序的系统属性及其值以表格格式显示

使用 Red Hat OpenShift 控制台部署样本应用程序

  1. Red Hat OpenShift 控制台导航菜单中,单击 操作程序 > 已安装的操作程序
  2. 已安装的操作程序页面上,为样本创建一个项目。
    1. 项目列表中选择操作符安装项目,并确保 IBM WebSphere Liberty 出现在已安装的操作员名称列表中。 该操作程序必须安装在集群上或要安装样本的项目中。
    2. 展开项目列表并单击创建项目
    3. 在“创建项目”对话框中,指定名称值(例如 samplelibertyapp),然后单击创建
    4. 项目列表中选择 samplelibertyapp 项目后,单击 IBM WebSphere Liberty 操作员。
      在 " Red Hat OpenShift 已安装的操作程序" 页面上选择 IBM WebSphere Liberty 操作程序
  3. 操作程序详细信息页面上,创建 WebSphereLibertyApplication 样本应用程序的实例。
    1. 单击 WebSphereLibertyApplication 选项卡。
    2. 单击创建 WebSphereLibertyApplication
      单击创建WebSphereLibertyApplication按钮IBM WebSphere Liberty运营商详情页面
  4. 创建 WebSphereLibertyApplication 页面上的表单视图YAML 视图中配置应用程序。 您可以使用 表单视图 来更改运算符参数值,然后使用 YAML 视图 来查看配置的应用程序 CR。

    要在表单视图中配置应用程序,请完成以下步骤。

    1. 展开许可证并选择接受
    2. 公开值设置为 true
    3. 单击创建

    要在 YAML 视图中配置该应用程序,请确保 CR 包含以下更改。

    • 必须将 .spec.license.accept 参数设置为 true 才能接受许可证。
    • 必须将 .spec.expose 参数设置为 true 以使用路由公开应用程序,以便您可以运行和查看样本应用程序。

    不需要更改样本应用程序的 .spec.applicationImage 参数值。 它已指定 WebSphere Liberty 操作程序随附的样本应用程序的路径。

    完成更改后,YAML 类似于以下 CR。

    apiVersion: liberty.websphere.ibm.com/v1
    kind: WebSphereLibertyApplication
    metadata:
      name: websphereliberty-app-sample
      namespace: samplelibertyapp
    spec:
      license:
        accept: true
        edition: IBM WebSphere Application Server
        productEntitlementSource: Standalone
      applicationImage: >-
        icr.io/appcafe/open-liberty/samples/getting-started@sha256:e22dd56a05e44618a10d275d3ff07a38eb364c0f04f86ffe9618d83dd5467860
      manageTLS: true
      expose: true
  5. Red Hat OpenShift 控制台导航菜单中,单击 工作负载 > Pod 以确保安装了样本应用程序的 pod 正在运行。
  6. Red Hat OpenShift 控制台导航菜单中,单击 联网 > 路由 以查看样本应用程序的路径。 单击 位置 链接以运行样本应用程序并 在浏览器中查看

使用 CLI 部署样本应用程序

  1. WebSphereLibertyApplication 配置用于部署样本应用程序的定制资源 (CR) YAML 文件。 确保该 CR 包含以下设置。
    • .spec.license.accept 值必须指定 true

    • 如果您的产品版本不是缺省版本 IBM WebSphere Application Server(基本),那么 .spec.license.edition 值必须指定您的产品版本。 其他可用值包括 IBM WebSphere Application Server Liberty CoreIBM WebSphere Application Server Network Deployment

    • 如果您获得许可的产品不是缺省产品 Standalone(其中包括诸如 Liberty 之类的 WebSphere Application Server 产品),那么 .spec.license.productEntitlementSource 值必须指定另一个产品。 其他可用选项包括 IBM Cloud Pak for ApplicationsIBM WebSphere Application Server Family EditionIBM WebSphere Hybrid Edition

    • .spec.applicationImage 参数值必须指定 WebSphere Liberty 操作程序随附的样本应用程序的路径。

    • 必须将 .spec.expose 参数设置为 true 以使用路由公开应用程序,以便您可以运行和查看样本应用程序。

    对于 IBM WebSphere Application Server 独立产品,以下 CR 将 .spec.license.accept 设置为 true ,使用 .spec.applicationImage指定应用程序映像的路径,并将 .spec.expose 设置为 true

    apiVersion: liberty.websphere.ibm.com/v1
    kind: WebSphereLibertyApplication
    metadata:
      name: websphereliberty-app-sample
      namespace: samplelibertyapp
    spec:
      license:
        accept: true
        edition: IBM WebSphere Application Server
        productEntitlementSource: Standalone
      applicationImage: >-
        icr.io/appcafe/open-liberty/samples/getting-started@sha256:e22dd56a05e44618a10d275d3ff07a38eb364c0f04f86ffe9618d83dd5467860
      manageTLS: true
      expose: true

    缺省情况下,.spec.manageTLS 设置为 true,且无需在 CR 中指定。 如果将 CR 部署到 Kubernetes 集群,那么必须在 Kubernetes 集群上安装证书管理器。 如果将 CR 部署到 Red Hat OpenShift 集群,那么不需要安装证书管理器。

  2. 将 CR 部署到 Kubernetes 环境中正在运行的集群。

    要使用 CLI 来应用 CR,请运行 kubectl applyoc apply 命令。

    要运行 kubectl 命令,您需要使用 Kubernetes 命令行工具Red Hat OpenShift 命令行界面 (CLI)。 要运行 oc 命令,您需要 Red Hat OpenShift CLI。

    在以下 apply 命令中,将 CR-YAML 替换为 CR 文件名。

    • 运行以下 kubectl apply 命令。
      kubectl apply -f CR-YAML
    • 运行以下 oc apply 命令。
      oc apply -f CR-YAML
  3. 检查样本应用程序 pod 是否正在运行。
    kubectl get pods -n samplelibertyapp
    oc get pods -n samplelibertyapp
  4. 获取该应用程序的路由。
    kubectl get routes -n samplelibertyapp
    oc get routes -n samplelibertyapp

    输出包含一个 HOST/PORT 值,该值提供样本应用程序的 URL。

    NAME                          HOST/PORT                                                   PATH   SERVICES                      PORT       TERMINATION   WILDCARD
    websphereliberty-app-sample   websphereliberty-app-sample-samplelibertyapp.apps.ibm.com          websphereliberty-app-sample   9443-tcp   reencrypt     None
    
  5. 从路由中复制 URL (HOST/PORT),并在浏览器中查看已部署的样本应用程序