14.5. 创建自定义域 Ingress Controller
创建并配置证书资源来为自定义域 Ingress Controller 置备证书:
注意以下示例使用单个域证书。还支持 SAN 和通配符证书。
$ cat << EOF | oc apply -f - apiVersion: cert-manager.io/v1 kind: Certificate metadata: name: custom-domain-ingress-cert namespace: openshift-ingress spec: secretName: custom-domain-ingress-cert-tls issuerRef: name: letsencrypt-production kind: ClusterIssuer commonName: "${DOMAIN}" dnsNames: - "${DOMAIN}" EOF
验证证书是否已发布:
注意Let's Encrypt 发布此证书需要几分钟时间。如果用时超过 5 分钟,请运行
oc -n openshift-ingress describe certificate.cert-manager.io/custom-domain-ingress-cert
来查看 cert-manager 报告的问题。$ oc -n openshift-ingress get certificate.cert-manager.io/custom-domain-ingress-cert
输出示例
NAME READY SECRET AGE custom-domain-ingress-cert True custom-domain-ingress-cert-tls 9m53s
创建新的
IngressController
资源:$ cat << EOF | oc apply -f - apiVersion: operator.openshift.io/v1 kind: IngressController metadata: name: custom-domain-ingress namespace: openshift-ingress-operator spec: domain: ${DOMAIN} defaultCertificate: name: custom-domain-ingress-cert-tls endpointPublishingStrategy: loadBalancer: dnsManagementPolicy: Unmanaged providerParameters: aws: type: NLB type: AWS scope: External type: LoadBalancerService EOF
警告此
IngressController
示例将在 AWS 帐户中创建可访问互联网的 Network Load Balancer (NLB)。要置备内部 NLB,请在创建IngressController
资源前将.spec.endpointPublishingStrategy.loadBalancer.scope
参数设置为Internal
。验证自定义域 IngressController 是否已成功创建了外部负载均衡器:
$ oc -n openshift-ingress get service/router-custom-domain-ingress
输出示例
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE router-custom-domain-ingress LoadBalancer 172.30.174.34 a309962c3bd6e42c08cadb9202eca683-1f5bbb64a1f1ec65.elb.us-east-1.amazonaws.com 80:31342/TCP,443:31821/TCP 7m28s
准备带有所需 DNS 更改的文档,为您的自定义域 Ingress Controller 启用 DNS 解析:
$ INGRESS=$(oc -n openshift-ingress get service/router-custom-domain-ingress -ojsonpath="{.status.loadBalancer.ingress[0].hostname}") $ cat << EOF > "${SCRATCH}/create-cname.json" { "Comment":"Add CNAME to custom domain endpoint", "Changes":[{ "Action":"CREATE", "ResourceRecordSet":{ "Name": "*.${DOMAIN}", "Type":"CNAME", "TTL":30, "ResourceRecords":[{ "Value": "${INGRESS}" }] } }] } EOF
提交您对 Amazon Route 53 的更改以进行传播:
$ aws route53 change-resource-record-sets \ --hosted-zone-id ${ZONE_ID} \ --change-batch file://${SCRATCH}/create-cname.json
注意虽然通配符 CNAME 记录避免需要为每个使用自定义域 Ingress Controller 部署的新应用程序创建新记录,但这些应用程序使用的证书 都不是 通配符证书。