ALB Ingress Controller提供证书自动发现功能,ALB会根据Knative Service域名自动匹配发现证书。本文介绍如何配置HTTPS证书。
操作步骤
首先您需要创建并上传证书,然后在Knative Service开启TLS,ALB会根据Knative Service域名自动匹配发现证书。具体操作步骤如下。
- 执行以下命令,通过OpenSSL创建证书。
openssl genrsa -out albtop-key.pem 4096
openssl req -subj "/CN=helloworld.default.knative.top" -sha256 -new -key albtop-key.pem -out albtop.csr
echo subjectAltName = DNS:helloworld.default.knative.top > extfile.cnf
openssl x509 -req -days 3650 -sha256 -in albtop.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out albtop-cert.pem -extfile extfile.cnf
- 在数字证书管理服务控制台上传证书。具体操作,请参见上传证书。
- 使用以下YAML内容,在Knative Service服务开启TLS。
knative.k8s.alibabacloud/tls
配置为
true
,即可开启HTTPS证书访问。
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: helloworld
namespace: default
annotations:
knative.k8s.alibabacloud/tls: "true"
spec:
template:
spec:
containers:
- image: registry-vpc.cn-shenzhen.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
env:
- name: TARGET
value: "Knative"
- 执行以下命令,访问HTTPS服务。
curl -H "host: helloworld.default.knative.top" https://alb-ppcate4ox6ge9m1wik.cn-shenzhen.alb.aliyuncs.com -k
预期输出:
Hello Knative!
由预期输出得到,访问HTTPS服务成功。