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

在OpenShift 4中提供了基于Knative的Serverless(无服务器架构)的运行环境,该环境相关资源是通过名为“OpenShift Serverless”的Operator创建的。由于Knative在运行的时候还依赖Istio相关功能,因此在OpenShift 4中OpenShift Serverless是和OpenShift ServiceMesh一起运行的。

本文说明如何创建一套基于Knative的Serverless运行环境。验证环境和相关软件版本:

  1. OpenShift 4.2.8/OpenShift 4.2.10
  2. Red Hat OpenShift Service Mesh 1.0.3
  3. OpenShift Serverless Operator 1.2.0/OpenShift Serverless Operator 1.3.0
  4. Knative Eventing v 0.10.0
  5. OpenShift Pipelines Operator 0.8.2

整个过程首先安装Service Mesh环境,然后安装Serverless环境,最后安装其它环境。

安装步骤

  • 安装Service Mesh环境
  • 安装Knative环境
    • 安装Knative Serving环境
    • 安装Knative Eventing环境
    • 整体环境确认
  • 安装Knative客户端
  • 运行Hello应用验证

安装Service Mesh环境

  1. 用管理员登录OpenShift Console控制台。
  2. 创建istio-system项目并进入该项目。
  3. 进入OperatorHub,然后找到“Red Hat Service OpenShift Mesh”(不是Community版),点击进入。
  4. 然后点击Install,再点击Subscribe。
  5. 稍等一会可以看到下面4个安装好的Operator。
    OpenShift 4 之Knative(1) - 创建Knative无服务器架构环境_第1张图片
  6. 为了用Operator创建Service Mesh资源,先进入上图的“Red Hat OpenShift Service Mesh”(注意此时是在istio-system项目),使用缺省配置,创建一个“Istio Service Mesh Member Roll”和一个“Istio Service Mesh Control Plane”。该过程会比较长,可用以下命令查看后台Pod创建进度,完成后istio-system项目中应该有如下Pod:
$ oc get po -n istio-system
NAME                                     READY   STATUS    RESTARTS   AGE
grafana-56f9c8b54-8fpts                  2/2     Running   0          14m
istio-citadel-5d5c8687df-8rqmx           1/1     Running   0          17m
istio-egressgateway-6686d54c49-6r2xd     1/1     Running   0          14m
istio-galley-86d9d8d49b-hwlpn            1/1     Running   0          16m
istio-ingressgateway-56857ff7f7-4z99n    1/1     Running   0          14m
istio-pilot-fb5f78c44-zrjhq              2/2     Running   0          15m
istio-policy-56c77687b5-nnh6f            2/2     Running   0          16m
istio-sidecar-injector-b6985f8b8-l78mp   1/1     Running   0          14m
istio-telemetry-775f7df579-xts9k         2/2     Running   0          16m
jaeger-57776787bc-x8dn9                  2/2     Running   0          16m
kiali-967b567b6-s66h2                    1/1     Running   0          7m39s
prometheus-6488c47945-gsdtk              2/2     Running   0          17m

安装Knative环境

我们需要用分别用OpenShift Serverless Operator和Knative Eventing Operator为Knative中的Serving和Eventing组件创建运行环境。

说明:可能是由于OpenShift内置Knative版本升级原因,发现OpenShift的4.1版本和4.2版在部分Knative对象名本有差异,以下是根据OpenShift 4.2的《Installing OpenShift Serverless 》文档进行的安装操作。

安装Knative Serving环境

  1. 用管理员登录OpenShift Console控制台。
  2. 创建knative-serving项目并进入该项目。
  3. 进入OperatorHub,然后找到“OpenShift Serverless Operator”,点击进入。
  4. 然后点击Install,再点击Subscribe。
  5. 在“OpenShift Serverless Operator”创建好后进入,用缺省配置创建一个“Knative Serving”。
  6. 执行命令查看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
  1. 执行命令查看Knative Serving相关的Pod运行情况。
$ oc get pod -n knative-serving
NAME                                READY   STATUS    RESTARTS   AGE
activator-dfb5b7b67-wlrlt           1/1     Running   0          4m5s
autoscaler-85bb4898c5-jvn4x         1/1     Running   0          4m4s
autoscaler-hpa-865b6d49b7-2w8kw     1/1     Running   0          4m4s
controller-65c8dd48d6-mbczs         1/1     Running   0          4m
networking-istio-7c9fb7dd4c-dsczv   1/1     Running   0          3m59s
webhook-95969d4fc-rt96b             1/1     Running   0          3m59s

安装Knative Eventing环境

  1. 用管理员登录OpenShift Console控制台。
  2. 创建knative-eventing项目并进入该项目。
  3. 进入OperatorHub,然后找到“Knative Eventing Operator”,点击进入。
  4. 然后点击Install,再点击Subscribe。
  5. 在“Knative Eventing Operator”创建好后进入,用缺省配置创建一个“Knative Eventing”。
  6. 执行命令查看Knative Eventing相关的Pod运行情况:
$ oc get pod -n knative-eventing
NAME                                   READY   STATUS    RESTARTS   AGE
eventing-controller-5d5f979874-dzsw4   1/1     Running   0          3h18m
eventing-webhook-75bcb6d4bb-9jf5q      1/1     Running   0          3h18m
imc-controller-69c54bfdc8-l9gp5        1/1     Running   0          3h18m
imc-dispatcher-94bc9f6b6-mbzv6         1/1     Running   0          3h18m
sources-controller-5c6df78ffb-2gtj8    1/1     Running   0          3h18m

整体环境确认

执行以下命令,应该看到相关Pod:

$ oc get pod -n openshift-operators
NAME                                           READY   STATUS    RESTARTS   AGE
elasticsearch-operator-5984d5fbb4-xp2lb        1/1     Running   0          30m
istio-node-d572g                               1/1     Running   0          15m
istio-operator-65cc76b765-t9g4n                1/1     Running   0          30m
jaeger-operator-98dd965f5-wb4rz                1/1     Running   0          30m
kiali-operator-ff996fcc7-92zt6                 1/1     Running   0          30m
knative-eventing-operator-595b7b4998-pdx6m     1/1     Running   0          26m
knative-openshift-ingress-79b5f4d6dc-nzzc9     1/1     Running   0          28m
knative-serving-operator-5df5c87b64-g966d      1/1     Running   0          28m
openshift-pipelines-operator-64847498c-g255l   1/1     Running   0          25m

安装Knative客户端

  1. 执行命令下载以下客户端程序。
$ curl -Lo kn https://storage.googleapis.com/knative-nightly/client/latest/kn-linux-amd64
$ curl -Lo stern https://github.com/wercker/stern/releases/download/1.6.0/stern_linux_amd64
$ curl -Lo hey https://storage.googleapis.com/hey-release/hey_linux_amd64
$ curl -Lo yq https://github.com/mikefarah/yq/releases/download/3.2.1/yq_linux_amd64
  1. 执行以下命令。
$ chmod +x kn stern hey yq
$ sudo mv kn stern hey yq /usr/local/bin

运行Hello应用验证

将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 'kn-samples':
 
  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-fxpwx-1' is available at URL:
http://hello-world.hello-openshift.apps-crc.testing
 
$ kn route list 
NAME          URL                                                   READY
hello-world   http://hello-world.hello-openshift.apps-crc.testing   True
 
$ curl $(kn route list | grep hello-world | awk 'NR==1 {print $2}')
Hello OpenShift!

你可能感兴趣的:(OpenShift,4,Knative,Dev)