openshift 创建一个Serverless应用程序

本文涉及的产品
Serverless 应用引擎免费试用套餐包,4320000 CU,有效期3个月
函数计算FC,每月15万CU 3个月
简介: 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存储库。


相关实践学习
【AI破次元壁合照】少年白马醉春风,函数计算一键部署AI绘画平台
本次实验基于阿里云函数计算产品能力开发AI绘画平台,可让您实现“破次元壁”与角色合照,为角色换背景效果,用AI绘图技术绘出属于自己的少年江湖。
从 0 入门函数计算
在函数计算的架构中,开发者只需要编写业务代码,并监控业务运行情况就可以了。这将开发者从繁重的运维工作中解放出来,将精力投入到更有意义的开发任务上。
相关文章
|
5天前
|
存储 人工智能 Serverless
函数计算进化之路:AI 应用运行时的状态剖析
AI应用正从“请求-响应”迈向“对话式智能体”,推动Serverless架构向“会话原生”演进。阿里云函数计算引领云上 AI 应用 Serverless 运行时技术创新,实现性能、隔离与成本平衡,开启Serverless AI新范式。
147 12
|
5月前
|
SQL 分布式计算 Serverless
鹰角网络:EMR Serverless Spark 在《明日方舟》游戏业务的应用
鹰角网络为应对游戏业务高频活动带来的数据潮汐、资源弹性及稳定性需求,采用阿里云 EMR Serverless Spark 替代原有架构。迁移后实现研发效率提升,支持业务快速发展、计算效率提升,增强SLA保障,稳定性提升,降低运维成本,并支撑全球化数据架构部署。
531 56
鹰角网络:EMR Serverless Spark 在《明日方舟》游戏业务的应用
|
3月前
|
存储 编解码 Serverless
Serverless架构下的OSS应用:函数计算FC自动处理图片/视频转码(演示水印添加+缩略图生成流水线)
本文介绍基于阿里云函数计算(FC)和对象存储(OSS)构建Serverless媒体处理流水线,解决传统方案资源利用率低、运维复杂、成本高等问题。通过事件驱动机制实现图片水印添加、多规格缩略图生成及视频转码优化,支持毫秒级弹性伸缩与精确计费,提升处理效率并降低成本,适用于高并发媒体处理场景。
214 0
|
5月前
|
人工智能 开发框架 安全
Serverless MCP 运行时业界首发,函数计算让 AI 应用最后一公里提速
作为云上托管 MCP 服务的最佳运行时,函数计算 FC 为阿里云百炼 MCP 提供弹性调用能力,用户只需提交 npx 命令即可“零改造”将开源 MCP Server 部署到云上,函数计算 FC 会准备好计算资源,并以弹性、可靠的方式运行 MCP 服务,按实际调用时长和次数计费,欢迎你在阿里云百炼和函数计算 FC 上体验 MCP 服务。
503 30
|
11天前
|
人工智能 Kubernetes 安全
重塑云上 AI 应用“运行时”,函数计算进化之路
回顾历史,电网的修建,深刻地改变了世界的经济地理和创新格局。今天,一个 AI 原生的云端运行时的进化,其意义也远不止于技术本身。这是一次设计哲学的升华:从“让应用适应平台”到“让平台主动理解和适应智能应用”的转变。当一个强大、易用、经济且安全的 AI 运行时成为像水电一样的基础设施时,它将极大地降低创新的门槛。一个独立的开发者、一个小型创业团队,将有能力去创造和部署世界级的 AI 应用。这才是技术平权的真谛,是激发全社会创新潜能的关键。
|
8月前
|
人工智能 运维 物联网
云大使 X 函数计算 FC 专属活动上线!享返佣,一键打造 AI 应用
如今,AI 技术已经成为推动业务创新和增长的重要力量。但对于许多企业和开发者来说,如何高效、便捷地部署和管理 AI 应用仍然是一个挑战。阿里云函数计算 FC 以其免运维的特点,大大降低了 AI 应用部署的复杂性。用户无需担心底层资源的管理和运维问题,可以专注于应用的创新和开发,并且用户可以通过一键部署功能,迅速将 AI 大模型部署到云端,实现快速上线和迭代。函数计算目前推出了多种规格的云资源优惠套餐,用户可以根据实际需求灵活选择。
|
5月前
|
Cloud Native Serverless 流计算
云原生时代的应用架构演进:从微服务到 Serverless 的阿里云实践
云原生技术正重塑企业数字化转型路径。阿里云作为亚太领先云服务商,提供完整云原生产品矩阵:容器服务ACK优化启动速度与镜像分发效率;MSE微服务引擎保障高可用性;ASM服务网格降低资源消耗;函数计算FC突破冷启动瓶颈;SAE重新定义PaaS边界;PolarDB数据库实现存储计算分离;DataWorks简化数据湖构建;Flink实时计算助力风控系统。这些技术已在多行业落地,推动效率提升与商业模式创新,助力企业在数字化浪潮中占据先机。
339 12
|
5月前
|
人工智能 开发框架 运维
Serverless MCP 运行时业界首发,函数计算让 AI 应用最后一公里提速
Serverless MCP 运行时业界首发,函数计算支持阿里云百炼 MCP 服务!阿里云百炼发布业界首个全生命周期 MCP 服务,无需用户管理资源、开发部署、工程运维等工作,5 分钟即可快速搭建一个连接 MCP 服务的 Agent(智能体)。作为云上托管 MCP 服务的最佳运行时,函数计算 FC 为阿里云百炼 MCP 提供弹性调用能力。
 Serverless MCP 运行时业界首发,函数计算让 AI 应用最后一公里提速
|
11月前
|
存储 消息中间件 人工智能
ApsaraMQ Serverless 能力再升级,事件驱动架构赋能 AI 应用
本文整理自2024年云栖大会阿里云智能集团高级技术专家金吉祥的演讲《ApsaraMQ Serverless 能力再升级,事件驱动架构赋能 AI 应用》。
398 106
|
6月前
|
人工智能 运维 架构师
Serverless + AI 让应用开发更简单,加速应用智能化
Serverless + AI 让应用开发更简单,加速应用智能化
193 5

热门文章

最新文章

相关产品

  • 函数计算