8.3. 流程
使用您希望所有红帽构建的 Keycloak 客户端要连接的根域名创建一个 Route53 Hosted Zone。
记录"托管区域 ID",因为后续步骤中需要这个 ID。
检索与每个 ROSA 集群关联的 "Hosted zone ID" 和 DNS 名称。
对于 Primary 和 Backup 集群,请执行以下步骤:
- 登录到 ROSA 集群。
检索集群 LoadBalancer Hosted Zone ID 和 DNS 主机名
命令:
HOSTNAME=$(oc -n openshift-ingress get svc router-default \ -o jsonpath='{.status.loadBalancer.ingress[].hostname}' ) aws elbv2 describe-load-balancers \ --query "LoadBalancers[?DNSName=='${HOSTNAME}'].{CanonicalHostedZoneId:CanonicalHostedZoneId,DNSName:DNSName}" \ --region eu-west-1 \1 --output json
- 1
- 托管您的 ROSA 集群的 AWS 区域
输出:
[ { "CanonicalHostedZoneId": "Z2IFOLAFXWLO4F", "DNSName": "ad62c8d2fcffa4d54aec7ffff902c925-61f5d3e1cbdc5d42.elb.eu-west-1.amazonaws.com" } ]
注意运行 OpenShift 4.13 及更早版本的 ROSA 集群使用典型的负载均衡器,而不是应用程序负载均衡器。使用
aws elb describe-load-balancers
命令以及更新的查询字符串。
创建 Route53 健康检查
命令:
function createHealthCheck() { # Creating a hash of the caller reference to allow for names longer than 64 characters REF=($(echo $1 | sha1sum )) aws route53 create-health-check \ --caller-reference "$REF" \ --query "HealthCheck.Id" \ --no-cli-pager \ --output text \ --health-check-config ' { "Type": "HTTPS", "ResourcePath": "/lb-check", "FullyQualifiedDomainName": "'$1'", "Port": 443, "RequestInterval": 30, "FailureThreshold": 1, "EnableSNI": true } ' } CLIENT_DOMAIN="client.keycloak-benchmark.com" 1 PRIMARY_DOMAIN="primary.${CLIENT_DOMAIN}" 2 BACKUP_DOMAIN="backup.${CLIENT_DOMAIN}" 3 createHealthCheck ${PRIMARY_DOMAIN} createHealthCheck ${BACKUP_DOMAIN}
- 1
- 红帽构建的 Keycloak 客户端应连接到的域。这应该是用于创建 Hosted Zone 的根域的子域或子域。
- 2
- 用于主集群中的健康探测的子域
- 3
- 用于备份集群中的健康探测的子域
输出:
233e180f-f023-45a3-954e-415303f21eab 1 799e2cbb-43ae-4848-9b72-0d9173f04912 2
创建 Route53 记录集
命令:
HOSTED_ZONE_ID="Z09084361B6LKQQRCVBEY" 1 PRIMARY_LB_HOSTED_ZONE_ID="Z2IFOLAFXWLO4F" PRIMARY_LB_DNS=ad62c8d2fcffa4d54aec7ffff902c925-61f5d3e1cbdc5d42.elb.eu-west-1.amazonaws.com PRIMARY_HEALTH_ID=233e180f-f023-45a3-954e-415303f21eab BACKUP_LB_HOSTED_ZONE_ID="Z2IFOLAFXWLO4F" BACKUP_LB_DNS=a184a0e02a5d44a9194e517c12c2b0ec-1203036292.elb.eu-west-1.amazonaws.com BACKUP_HEALTH_ID=799e2cbb-43ae-4848-9b72-0d9173f04912 aws route53 change-resource-record-sets \ --hosted-zone-id Z09084361B6LKQQRCVBEY \ --query "ChangeInfo.Id" \ --output text \ --change-batch ' { "Comment": "Creating Record Set for '${CLIENT_DOMAIN}'", "Changes": [{ "Action": "CREATE", "ResourceRecordSet": { "Name": "'${PRIMARY_DOMAIN}'", "Type": "A", "AliasTarget": { "HostedZoneId": "'${PRIMARY_LB_HOSTED_ZONE_ID}'", "DNSName": "'${PRIMARY_LB_DNS}'", "EvaluateTargetHealth": true } } }, { "Action": "CREATE", "ResourceRecordSet": { "Name": "'${BACKUP_DOMAIN}'", "Type": "A", "AliasTarget": { "HostedZoneId": "'${BACKUP_LB_HOSTED_ZONE_ID}'", "DNSName": "'${BACKUP_LB_DNS}'", "EvaluateTargetHealth": true } } }, { "Action": "CREATE", "ResourceRecordSet": { "Name": "'${CLIENT_DOMAIN}'", "Type": "A", "SetIdentifier": "client-failover-primary-'${SUBDOMAIN}'", "Failover": "PRIMARY", "HealthCheckId": "'${PRIMARY_HEALTH_ID}'", "AliasTarget": { "HostedZoneId": "'${HOSTED_ZONE_ID}'", "DNSName": "'${PRIMARY_DOMAIN}'", "EvaluateTargetHealth": true } } }, { "Action": "CREATE", "ResourceRecordSet": { "Name": "'${CLIENT_DOMAIN}'", "Type": "A", "SetIdentifier": "client-failover-backup-'${SUBDOMAIN}'", "Failover": "SECONDARY", "HealthCheckId": "'${BACKUP_HEALTH_ID}'", "AliasTarget": { "HostedZoneId": "'${HOSTED_ZONE_ID}'", "DNSName": "'${BACKUP_DOMAIN}'", "EvaluateTargetHealth": true } } }] } '
输出:
/change/C053410633T95FR9WN3YI
等待 Route53 记录更新
命令:
aws route53 wait resource-record-sets-changed --id /change/C053410633T95FR9WN3YI
更新或创建红帽构建的 Keycloak 部署
对于 Primary 和 Backup 集群,请执行以下步骤:
- 登录到 ROSA 集群
确保
Keycloak
CR 有以下配置apiVersion: k8s.keycloak.org/v2alpha1 kind: Keycloak metadata: name: keycloak spec: hostname: hostname: ${CLIENT_DOMAIN} 1
- 1
- 用于连接到红帽构建的 Keycloak 的域客户端
为确保请求转发正常工作,请编辑红帽构建的 Keycloak CR,以指定客户端将访问红帽 Keycloak 实例的主机名。此主机名必须是 Route53 配置中使用的
$CLIENT_DOMAIN
。创建健康检查路由
命令:
cat <<EOF | oc apply -n $NAMESPACE -f - 1 apiVersion: route.openshift.io/v1 kind: Route metadata: name: aws-health-route spec: host: $DOMAIN 2 port: targetPort: https tls: insecureEdgeTerminationPolicy: Redirect termination: passthrough to: kind: Service name: keycloak-service weight: 100 wildcardPolicy: None EOF