openshift 创建一个Serverless应用程序

本文涉及的产品
简介: openshift 创建一个Serverless应用程序

文章目录

1. Serverless Lab

2. 将Barista应用程序转换为无服务器服务

2.1 Delete Barista Deployment and Service

2.2 Deploy Barista Component as Knative Service

3 更新咖啡店ConfigMap访问Knative咖啡师服务

3.1 Fix ConfigMap that Associates `coffee-shop` and `barista`

3.2 Restart coffee-shop Application

3.3 Access coffee-shop Web Application

4 Examine Logs

Red Hat OpenShift 4.8 环境集群搭建

openshift 如何输出json日志

openshfit Vertical Pod Autoscaler 实践

openshift Certified Helm Charts 实践

openshift 创建一个Serverless应用程序

openshift gitops 实践

openshift Tekton pipeline 实践

1. Serverless Lab

使用Knative Serverless,您可以轻松地在Kubernetes上运行无服务器容器。Knative负责网络、自动伸缩(甚至为零)和修订跟踪的细节。这让你能够专注于你的核心逻辑。

在本实验室中,您将学习如何将无服务器应用程序部署为“服务”应用程序。


Serverless服务

减少资源消耗的一种好方法是确定哪些服务需要24/7运行。示例咖啡店应用程序有三个组件: a database, a front-end coffee shop, and a service barista that makes drinks。似乎只有在咖啡订单实际提交时才需要咖啡师服务,而咖啡店前端应该始终运行。因此,有必要将咖啡师服务转换为无服务器服务,在不使用时可以扩展到零副本。


目标:


将咖啡师应用程序转换为无服务器服务

观察日志的变化

2. 将Barista应用程序转换为无服务器服务

咖啡师应用程序不需要一直运行。它只需要在创建新订单时运行。因此,当咖啡店没有流量时,应用程序不需要消耗资源。

2.1 Delete Barista Deployment and Service

Go to your Red Hat® OpenShift® Container Platform web console and log in as admin.

Use the perspective switcher to switch to the Developer perspective.

If a pop-up window appears, click Cancel.

In the navigation menu, click Topology.

A graphical representation of your application appears, displaying the app components, plus a cron job that orders drinks every minute:

1035234-20181020215539574-213176954.png

Click D barista to display the details panel.

You need to delete this barista OpenShift service and the baristadeployment before you can deploy a Knative service by the same name.

Click S barista to open the Service details page.

Select Actions → Delete Service and confirm.

Go back to Topology and click D barista again to verify that the service was deleted.

Select Actions → Delete deployment to delete the barista deployment.

Confirm the deletion.

2.2 Deploy Barista Component as Knative Service

在本节中,您将把咖啡师容器映像部署为Knative无服务器服务。Knative服务的API包不同于Kubernetes服务,扮演着不同的角色。


Kubernetes Service service.k8s.io/v1: Service is a named abstraction of software service (for example, mysql) consisting of a local port (for example 3306) that the proxy listens on, and the selector that determines which pods will answer requests sent through the proxy. https://kubernetes.io/docs/reference/kubernetes-api/service-resources/service-v1/


Knative Service serving.knative.dev/v1: A complete application: https://knative.dev/docs/reference/api/serving-api/#serving.knative.dev


On the navigation menu, click Add.

Click Container Images.

Fill in the Image stream from internal registry fields as follows:

Project: dev-coffeeshop

Image Stream: barista

Tag: latest

Complete the remaining fields as follows:

Runtime icon: select the Knative icon

Application: coffee-shop

Name: barista

Resources: select the Knative Service radio button

Create a route to the Application: check this box

Click Create

Expect the Topology view to appear with the new KSVC barista service along with its revision number.

3 更新咖啡店ConfigMap访问Knative咖啡师服务

The route to the barista part of the application has changed, so the coffee shop component cannot find it.


The old service URL was http://barista:8080/processes. The new service URL (Knative route) is http://barista.dev-coffeeshop.svc.cluster.local/processes. Knative使用项目名而不是服务名,并且端口现在由Knative处理。这将断开咖啡店应用程序和咖啡师应用程序之间的连接。


In this exercise, you reconnect them.

3.1 Fix ConfigMap that Associates coffee-shop and barista

The coffee-shop application gets its BARISTA_URL from a ConfigMap.


In the navigation menu, click ConfigMaps and then click CM coffee-shop.

Scroll down to the Data section and the BARISTA_URL of http://barista:8080/processes.

Select Actions → Edit ConfigMap.

In the YAML listing that opens, copy and paste the following URL into the BARISTA_URL value:

http://barista.dev-coffeeshop.svc.cluster.local/processes.

3.2 Restart coffee-shop Application

在本节中,您将向下扩展咖啡店部署并备份以获取ConfigMap更改。


Return to Topology and click D coffee-shop.

In the panel that appears, click the Details tab.

Expect to see three running pods.

3.使用箭头按钮来缩小到0,然后返回到3

3.3 Access coffee-shop Web Application

要确保coffee-shop应用程序工作,请在coffee-shop应用程序上单击Open URL,而不是barista应用程序:

1035234-20181020215539574-213176954.png

预计会出现一两行JSON输出。


Add /index.html to the end of the URL to access the application.

如果看到类似RESTEASY003210的错误…你走的是Knative barista的路线。这是错误的路线。使用coffee-shop路线代替。


点一杯饮料,并验证咖啡师应用程序可以扩展到处理请求

Expect to see some beverages already ordered by the order-drinks cron job. Your order is at the bottom of the list.


The order-drinks cron job orders two new drinks every minute from the coffee-shop application in the dev-coffeeshop namespace.

4 Examine Logs

如果您返回Kibana接口,您会看到结构化类型中现在有更多的字段。它们大多是当您从Kubernetes部署更改为Knative应用程序时,应用程序捕获的应用程序异常。


返回Kibana web界面,从左侧导航面板单击Discovery。

从“可用字段”一节中,将*t* structured.error.message添加到日志发现中。

使用顶部的时间滑块来关注带有错误消息的事件。

希望很容易找到错误消息,例如“RESTEASY004655: Unable to invoke r .”

java.net.NoRouteToHostException: No route to host (Host unreachable)".

您使用Knative将一个无服务器应用程序部署为一个服务应用程序。

现在,在下一个模块中,我们将继续学习GitOps。使用GitOps,您可以将咖啡馆应用程序的部署自动化到生产环境,所有这些都来自一个Git存储库。


相关实践学习
基于函数计算一键部署掌上游戏机
本场景介绍如何使用阿里云计算服务命令快速搭建一个掌上游戏机。
建立 Serverless 思维
本课程包括: Serverless 应用引擎的概念, 为开发者带来的实际价值, 以及让您了解常见的 Serverless 架构模式
相关文章
|
1月前
|
人工智能 Serverless 测试技术
nacos常见问题之Serverless 应用引擎2.0不支持 MSE nacos如何解决
Nacos是阿里云开源的服务发现和配置管理平台,用于构建动态微服务应用架构;本汇总针对Nacos在实际应用中用户常遇到的问题进行了归纳和解答,旨在帮助开发者和运维人员高效解决使用Nacos时的各类疑难杂症。
23 0
|
1月前
|
监控 Serverless 数据库
Serverless 应用引擎常见问题之biphon-education-配置了SLS后一直重启如何解决
Serverless 应用引擎(Serverless Application Engine, SAE)是一种完全托管的应用平台,它允许开发者无需管理服务器即可构建和部署应用。以下是Serverless 应用引擎使用过程中的一些常见问题及其答案的汇总:
28 5
|
1月前
|
运维 Serverless 调度
Serverless 应用引擎常见问题之事件中心看不着如何解决
Serverless 应用引擎(Serverless Application Engine, SAE)是一种完全托管的应用平台,它允许开发者无需管理服务器即可构建和部署应用。以下是Serverless 应用引擎使用过程中的一些常见问题及其答案的汇总:
33 4
|
1月前
|
JSON Serverless API
Serverless 应用引擎常见问题之query参数无法取到上一步传输过来的jjson参数如何解决
Serverless 应用引擎(Serverless Application Engine, SAE)是一种完全托管的应用平台,它允许开发者无需管理服务器即可构建和部署应用。以下是Serverless 应用引擎使用过程中的一些常见问题及其答案的汇总:
158 3
|
1月前
|
监控 Serverless 对象存储
Serverless 应用引擎常见问题之用ECI部署Traefik时设置如何解决
Serverless 应用引擎(Serverless Application Engine, SAE)是一种完全托管的应用平台,它允许开发者无需管理服务器即可构建和部署应用。以下是Serverless 应用引擎使用过程中的一些常见问题及其答案的汇总:
237 2
|
1月前
|
监控 Serverless 测试技术
Serverless 应用引擎常见问题之做的web服务计费如何解决
Serverless 应用引擎(Serverless Application Engine, SAE)是一种完全托管的应用平台,它允许开发者无需管理服务器即可构建和部署应用。以下是Serverless 应用引擎使用过程中的一些常见问题及其答案的汇总:
407 3
|
1月前
|
机器学习/深度学习 人工智能 Cloud Native
Serverless 应用引擎常见问题之改配置变慢如何解决
Serverless 应用引擎(Serverless Application Engine, SAE)是一种完全托管的应用平台,它允许开发者无需管理服务器即可构建和部署应用。以下是Serverless 应用引擎使用过程中的一些常见问题及其答案的汇总:
398 3
|
1月前
|
缓存 Java Serverless
Serverless 应用引擎常见问题之安装完serverless dev报错如何解决
Serverless 应用引擎(Serverless Application Engine, SAE)是一种完全托管的应用平台,它允许开发者无需管理服务器即可构建和部署应用。以下是Serverless 应用引擎使用过程中的一些常见问题及其答案的汇总:
30 4
|
1月前
|
弹性计算 监控 Serverless
Serverless 应用引擎常见问题之相同的配置(4U8G)需要多个实例来扛如何解决
Serverless 应用引擎(Serverless Application Engine, SAE)是一种完全托管的应用平台,它允许开发者无需管理服务器即可构建和部署应用。以下是Serverless 应用引擎使用过程中的一些常见问题及其答案的汇总:
71 5
|
1月前
|
监控 关系型数据库 Serverless
Serverless 应用引擎常见问题之工作流这执行输出通过jsonpath过滤如何解决
Serverless 应用引擎(Serverless Application Engine, SAE)是一种完全托管的应用平台,它允许开发者无需管理服务器即可构建和部署应用。以下是Serverless 应用引擎使用过程中的一些常见问题及其答案的汇总:
391 3

相关产品

  • 函数计算