apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: <service_name>
annotations:
serving.knative.openshift.io/disableRoute: "true"
spec:
template:
spec:
containers:
- image: <image>
...
如果要配置 Knative 服务以便在 OpenShift Container Platform 上使用您的 TLS 证书,则必须禁用 OpenShift Serverless 运算符自动创建服务路由的功能,而应手动为服务创建路由。
完成以下步骤后,不会创建 `knative-serving-ingress` 命名空间中的默认 OpenShift Container Platform 路由。但是,应用程序的 Knative 路由仍然在此命名空间中创建。 |
必须在 OpenShift Container Platform 集群上安装 OpenShift Serverless 运算符和 Knative Serving 组件。
安装 OpenShift CLI (oc
)。
创建一个包含 `serving.knative.openshift.io/disableRoute=true` 注解的 Knative 服务
`serving.knative.openshift.io/disableRoute=true` 注解指示 OpenShift Serverless 不要自动为您创建路由。但是,服务仍然显示 URL 并达到 `Ready` 状态。在您创建具有与 URL 中主机名相同的主机名的路由之前,此 URL 无法在外部工作。 |
创建 Knative `Service` 资源
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: <service_name>
annotations:
serving.knative.openshift.io/disableRoute: "true"
spec:
template:
spec:
containers:
- image: <image>
...
应用 `Service` 资源
$ oc apply -f <filename>
可选。使用 `kn service create` 命令创建 Knative 服务
$ kn service create <service_name> \
--image=gcr.io/knative-samples/helloworld-go \
--annotation serving.knative.openshift.io/disableRoute=true
验证没有为服务创建 OpenShift Container Platform 路由
$ $ oc get routes.route.openshift.io \
-l serving.knative.openshift.io/ingressName=$KSERVICE_NAME \
-l serving.knative.openshift.io/ingressNamespace=$KSERVICE_NAMESPACE \
-n knative-serving-ingress
您将看到以下输出
No resources found in knative-serving-ingress namespace.
在 `knative-serving-ingress` 命名空间中创建 `Route` 资源
apiVersion: route.openshift.io/v1
kind: Route
metadata:
annotations:
haproxy.router.openshift.io/timeout: 600s (1)
name: <route_name> (2)
namespace: knative-serving-ingress (3)
spec:
host: <service_host> (4)
port:
targetPort: http2
to:
kind: Service
name: kourier
weight: 100
tls:
insecureEdgeTerminationPolicy: Allow
termination: edge (5)
key: |-
-----BEGIN PRIVATE KEY-----
[...]
-----END PRIVATE KEY-----
certificate: |-
-----BEGIN CERTIFICATE-----
[...]
-----END CERTIFICATE-----
caCertificate: |-
-----BEGIN CERTIFICATE-----
[...]
-----END CERTIFICATE----
wildcardPolicy: None
1 | OpenShift Container Platform 路由的超时值。必须将其设置为与 `max-revision-timeout-seconds` 设置相同的值(默认为 `600s`)。 |
2 | OpenShift Container Platform 路由的名称。 |
3 | OpenShift Container Platform 路由的命名空间。这必须是 `knative-serving-ingress`。 |
4 | 外部访问的主机名。您可以将其设置为 `<service_name>-<service_namespace>.<domain>`。 |
5 | 您要使用的证书。目前,仅支持 `edge` 终止。 |
应用 `Route` 资源
$ oc apply -f <filename>