在OpenShift 4中提供了基于Knative的Serverless(无服务器架构)的运行环境,该环境相关资源是通过名为“OpenShift Serverless”的Operator创建的。由于Knative在运行的时候还依赖Istio相关功能,因此在OpenShift 4中OpenShift Serverless是和OpenShift ServiceMesh一起运行的。
本文说明如何创建一套基于Knative的Serverless运行环境。验证环境和相关软件版本:
- OpenShift 4.2.8/OpenShift 4.2.10
- Red Hat OpenShift Service Mesh 1.0.3
- OpenShift Serverless Operator 1.2.0/OpenShift Serverless Operator 1.3.0
- Knative Eventing v 0.10.0
- OpenShift Pipelines Operator 0.8.2
整个过程首先安装Service Mesh环境,然后安装Serverless环境,最后安装其它环境。
安装步骤
安装Service Mesh环境
- 用管理员登录OpenShift Console控制台。
- 创建istio-system项目并进入该项目。
- 进入OperatorHub,然后找到“Red Hat Service OpenShift Mesh”(不是Community版),点击进入。
- 然后点击Install,再点击Subscribe。
- 稍等一会可以看到下面4个安装好的Operator。
- 为了用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组件创建运行环境。
安装Knative Serving环境
- 用管理员登录OpenShift Console控制台。
- 创建knative-serving项目并进入该项目。
- 进入OperatorHub,然后找到“OpenShift Serverless Operator”,点击进入。
- 然后点击Install,再点击Subscribe。
- 在“OpenShift Serverless Operator”创建好后进入,用缺省配置创建一个“Knative Serving”。
- 执行命令查看Knative Serving状态,完成后应为以下状态:
$ oc get knativeserving/knative-serving -n knative-serving --template='{{range .status.conditions}}{{printf "%s=%s\n" .type .status}}{{end}}'
DependenciesInstalled=True
DeploymentsAvailable=True
InstallSucceeded=True
Ready=True
- 执行命令查看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环境
- 用管理员登录OpenShift Console控制台。
- 创建knative-eventing项目并进入该项目。
- 进入OperatorHub,然后找到“Knative Eventing Operator”,点击进入。
- 然后点击Install,再点击Subscribe。
- 在“Knative Eventing Operator”创建好后进入,用缺省配置创建一个“Knative Eventing”。
- 执行命令查看Knative Eventing相关的Pod运行情况:
$ oc get po -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
安装Knative环境
- 用管理员登录OpenShift Console控制台。
- 进入OperatorHub,然后找到“OpenShift Pipelines Operator ”,点击进入。
- 然后点击Install,再点击Subscribe。
整体环境确认
执行以下命令,应该看到相关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客户端
- 执行命令下载以下客户端程序。
$ 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
- 进入页面,下载yq程序。
- 执行以下命令。
$ chmod +x tn stern hey yq
验证
将openshift/hello-openshift镜像作为Serverless的Service部署,然后访问验证。
$ oc new project hello-openshift
$ kn service create hello-world --image=openshift/hello-openshift
$ kn route list -n hello-openshift
NAME URL READY
hello-openshift http://hello-openshift.quarkus.apps-crc.testing True
$ curl http://hello-openshift.quarkus.apps-crc.testing