部署 WebSphere Liberty 操作程序样本应用程序
在安装操作程序后,应用程序管理员可以将 WebSphereLibertyApplication 的样本应用程序映像部署到 Kubernetes 环境。 使用 Red Hat® OpenShift® 控制台或 kubectl 或 oc 命令部署应用程序映像。
在所有名称空间或要部署样本应用程序的名称空间中,必须安装 WebSphere® Liberty 操作程序。
已部署的样本应用程序在浏览器中显示了该应用程序的系统属性。

使用 Red Hat OpenShift 控制台部署样本应用程序
- 在 Red Hat OpenShift 控制台导航菜单中,单击 。
- 在已安装的操作程序页面上,为样本创建一个项目。
- 从项目列表中选择操作符安装项目,并确保 IBM WebSphere Liberty 出现在已安装的操作员名称列表中。 该操作程序必须安装在集群上或要安装样本的项目中。
- 展开项目列表并单击创建项目。
- 在“创建项目”对话框中,指定名称值(例如
samplelibertyapp),然后单击创建。 - 在项目列表中选择
samplelibertyapp项目后,单击 IBM WebSphere Liberty 操作员。
- 在操作程序详细信息页面上,创建 WebSphereLibertyApplication 样本应用程序的实例。
- 单击 WebSphereLibertyApplication 选项卡。
- 单击创建 WebSphereLibertyApplication。

在创建 WebSphereLibertyApplication 页面上的表单视图或 YAML 视图中配置应用程序。 您可以使用 表单视图 来更改运算符参数值,然后使用 YAML 视图 来查看配置的应用程序 CR。
要在表单视图中配置应用程序,请完成以下步骤。
- 展开许可证并选择接受。
- 将公开值设置为
true。 - 单击创建。
要在 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- 在 Red Hat OpenShift 控制台导航菜单中,单击 以确保安装了样本应用程序的 pod 正在运行。
- 在 Red Hat OpenShift 控制台导航菜单中,单击 以查看样本应用程序的路径。 单击 位置 链接以运行样本应用程序并 在浏览器中查看。
使用 CLI 部署样本应用程序
- 为 WebSphereLibertyApplication 配置用于部署样本应用程序的定制资源 (CR) YAML 文件。 确保该 CR 包含以下设置。
对于
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 集群,那么不需要安装证书管理器。 - 将 CR 部署到 Kubernetes 环境中正在运行的集群。
要使用 CLI 来应用 CR,请运行 kubectl apply 或 oc 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
- 运行以下 kubectl apply 命令。
- 检查样本应用程序 pod 是否正在运行。
kubectl get pods -n samplelibertyappoc get pods -n samplelibertyapp - 获取该应用程序的路由。
kubectl get routes -n samplelibertyappoc 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 - 从路由中复制 URL (
HOST/PORT),并在浏览器中查看已部署的样本应用程序。