OpenShift 4 之Knative(1) - 创建Knative无服务器架构环境(附视频)

36 篇文章 0 订阅
14 篇文章 0 订阅

OpenShift 4.x HOL教程汇总
说明:本文已经在OpenShift 4.13 + OpenShift Serverless 1.29.1 环境中验证

在OpenShift 4中提供了基于Knative的Serverless(无服务器架构)的运行环境,该环境相关资源是通过名为“OpenShift Serverless”的Operator创建的。本文说明如何创建一套基于Knative的Serverless运行环境。

安装Knative环境

安装OpenShift Serverless Operator

  1. 用集群管理员登录OpenShift Console控制台,进入Administrator视图。
  2. 进入Operators中的OperatorHub菜单,然后找到“OpenShift Serverless”,点击进入。
  3. 然后在右滑页面中点击Install。
  4. 在“Install Operator”页面中接受默认选项,再点击Install。
  5. 此后OpenShift会安装OpenShift Serverless环境,完成后可以在“Installed Operators”页面中查看安装完成的Red Hat OpenShift Serverless。
    在这里插入图片描述

安装Knative Serving环境

  1. 如果此时没有名为knative-serving的项目,则创建它,然后再并切换到该项目。
  2. 进入前面创建的“OpenShift Serverless”,点击“Knative Serving”下方的Create Instance链接。
    在这里插入图片描述
  3. 在“Create Knative Serving”页面用缺省配置创建一个“Knative Serving”。
kind: KnativeServing
apiVersion: operator.knative.dev/v1beta1
metadata:
  name: knative-serving
  namespace: knative-serving
spec: {}
  1. 执行命令查看Knative Serving状态,完成后应为以下状态:
$ oc get knativeserving.operator.knative.dev/knative-serving -n knative-serving --template='{{range .status.conditions}}{{printf "%s=%s\n" .type .status}}{{end}}'
DependenciesInstalled=True
DeploymentsAvailable=True
InstallSucceeded=True
Ready=True
VersionMigrationEligible=True
  1. 执行命令查看Knative Serving相关的Pod运行情况。
$ oc get pod -n knative-serving
NAME                                     READY   STATUS    RESTARTS   AGE
activator-75dfd89ddf-sbjhq                               2/2     Running     0          2m26s
activator-75dfd89ddf-zd9ln                               2/2     Running     0          2m26s
autoscaler-554f694ff7-8vpzc                              2/2     Running     0          2m26s
autoscaler-554f694ff7-hxqdn                              2/2     Running     0          2m26s
autoscaler-hpa-8459cdb7ff-lsxk9                          2/2     Running     0          2m23s
autoscaler-hpa-8459cdb7ff-tr8zl                          2/2     Running     0          2m23s
controller-9d97cfd75-jz6k4                               2/2     Running     0          2m17s
controller-9d97cfd75-tqvks                               2/2     Running     0          2m2s
domain-mapping-85f976d845-2sj6t                          2/2     Running     0          2m25s
domain-mapping-85f976d845-6r9pp                          2/2     Running     0          2m25s
domainmapping-webhook-6f86f7fdcf-54b4h                   2/2     Running     0          2m25s
domainmapping-webhook-6f86f7fdcf-gzl72                   2/2     Running     0          2m25s
storage-version-migration-serving-serving-0.26.0-wwz74   0/1     Completed   0          2m23s
webhook-745c7b586d-8s7tc                                 2/2     Running     0          2m24s
webhook-745c7b586d-wfgsk                                 2/2     Running     0          2m24s

安装Knative Eventing环境

  1. 如果此时没有名为knative-eventing的项目,则创建它,然后再并切换到该项目。
  2. 进入前面创建的“OpenShift Serverless”,点击“Knative Eventing”下方的Create Instance链接。
  3. 在“Create Knative Eventing”页面用缺省配置创建一个“Knative Eventing”。
kind: KnativeEventing
apiVersion: operator.knative.dev/v1beta1
metadata:
  name: knative-eventing
  namespace: knative-eventing
spec: {}
  1. 我们可以查看pod的资源,在部署完成应该有如下运行的pod。
NAME                                                    READY   STATUS      RESTARTS   AGE
eventing-controller-6f7bb85d7-jjz7d                     2/2     Running     0          3m18s
eventing-controller-6f7bb85d7-wxpq4                     2/2     Running     0          3m18s
eventing-webhook-5b55d5b588-pg7w2                       2/2     Running     0          3m17s
eventing-webhook-5b55d5b588-x6xs7                       2/2     Running     0          3m17s
imc-controller-7b788b9687-dndvc                         2/2     Running     0          3m13s
imc-controller-7b788b9687-tps8h                         2/2     Running     0          3m13s
imc-dispatcher-5976cc978-gx4sx                          2/2     Running     0          3m13s
imc-dispatcher-5976cc978-mndzq                          2/2     Running     0          3m13s
mt-broker-controller-76d66bb7bc-fdcgt                   2/2     Running     0          3m11s
mt-broker-controller-76d66bb7bc-k5272                   2/2     Running     0          3m11s
mt-broker-filter-7c88cb89b5-p77k4                       2/2     Running     0          3m12s
mt-broker-filter-7c88cb89b5-xj28v                       2/2     Running     0          3m12s
mt-broker-ingress-d5f9cbf49-5ggfz                       2/2     Running     0          3m11s
mt-broker-ingress-d5f9cbf49-wts6t                       2/2     Running     0          3m11s
strg-version-migration-eventing-eventing-0.26.0-xpnlt   0/1     Completed   0          3m10s
sugar-controller-6f8d87db6b-4qfxp                       2/2     Running     0          3m11s
sugar-controller-6f8d87db6b-qbnd4                       2/2     Running     0          3m11s
  1. 执行以下命令,查看knative-eventing对象的状态。
$ oc get knativeeventing.operator.knative.dev/knative-eventing -n knative-eventing --template='{{range .status.conditions}}{{printf "%s=%s\n" .type .status}}{{end}}'
DependenciesInstalled=True
DeploymentsAvailable=True
InstallSucceeded=True
Ready=True
VersionMigrationEligible=True

安装Knative客户端

执行命令下载Knative客户端程序。

$ curl -L https://mirror.openshift.com/pub/openshift-v4/clients/serverless/latest/kn-linux-amd64.tar.gz | tar -xzf -
$ sudo mv kn-linux-amd64 /usr/local/bin/kn

运行Hello应用验证Knative Serving环境

将openshift/hello-openshift镜像作为Serverless的Service部署,然后访问验证。

$ oc new-project hello-openshift
$ kn service create hello-world --image=openshift/hello-openshift
Creating service 'hello-world' in namespace 'hello-openshift':
 
  0.237s The Route is still working to reflect the latest desired specification.
  0.267s Configuration "hello-world" is waiting for a Revision to become ready.
 27.592s ...
 27.780s Ingress has not yet been reconciled.
 27.880s Ready to serve.
 
Service 'hello-world' created to latest revision 'hello-world-00001' is available at URL:
https://hello-world-hello-openshift.apps.cluster-229bt.229bt.sandbox886.opentlc.com
 
$ kn route list 
NAME          URL                                                                                   READY
hello-world   https://hello-world-hello-openshift.apps.cluster-229bt.229bt.sandbox886.opentlc.com   True

$ curl -k $(kn route list hello-world --no-headers | awk 'NR==1 {print $2}')
Hello OpenShift!

查看“无服务器”控制台

以下是管理员的“无服务器”控制台:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

演示视频

视频

参考

以下示例需要安装JDK11环境。
https://github.com/knative/docs/tree/main/code-samples/serving/hello-world/helloworld-java-spring

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值