×

遵循本研讨会,在AWS上部署带有托管控制平面(HCP)集群的Red Hat OpenShift Service on AWS (ROSA)示例。然后,您可以在后续教程中使用您的集群。

教程目标
  • 学习创建集群先决条件

    • 创建一个虚拟私有云 (VPC) 示例

    • 创建OpenID Connect (OIDC) 资源示例

  • 创建示例环境变量

  • 部署ROSA集群示例

先决条件
  • ROSA版本1.2.31或更高版本

  • Amazon Web Service (AWS) 命令行界面 (CLI)

  • ROSA CLI (rosa)

创建集群先决条件

在部署带有HCP集群的ROSA之前,您必须同时拥有VPC和OIDC资源。我们将首先创建这些资源。ROSA使用自带VPC (BYO-VPC) 模型。

创建VPC

  1. 确保您的AWS CLI (aws) 已配置为使用ROSA可用的区域。通过运行以下命令查看AWS CLI支持的区域

    $ rosa list regions --hosted-cp
  2. 创建VPC。在本教程中,以下脚本创建VPC及其必需组件。它使用在您的aws CLI中配置的区域。

    #!/bin/bash
    
    set -e
    ##########
    # This script will create the network requirements for a ROSA cluster. This will be
    # a public cluster. This creates:
    # - VPC
    # - Public and private subnets
    # - Internet Gateway
    # - Relevant route tables
    # - NAT Gateway
    #
    # This will automatically use the region configured for the aws cli
    #
    ##########
    
    VPC_CIDR=10.0.0.0/16
    PUBLIC_CIDR_SUBNET=10.0.1.0/24
    PRIVATE_CIDR_SUBNET=10.0.0.0/24
    
    # Create VPC
    echo -n "Creating VPC..."
    VPC_ID=$(aws ec2 create-vpc --cidr-block $VPC_CIDR --query Vpc.VpcId --output text)
    
    # Create tag name
    aws ec2 create-tags --resources $VPC_ID --tags Key=Name,Value=$CLUSTER_NAME
    
    # Enable dns hostname
    aws ec2 modify-vpc-attribute --vpc-id $VPC_ID --enable-dns-hostnames
    echo "done."
    
    # Create Public Subnet
    echo -n "Creating public subnet..."
    PUBLIC_SUBNET_ID=$(aws ec2 create-subnet --vpc-id $VPC_ID --cidr-block $PUBLIC_CIDR_SUBNET --query Subnet.SubnetId --output text)
    
    aws ec2 create-tags --resources $PUBLIC_SUBNET_ID --tags Key=Name,Value=$CLUSTER_NAME-public
    echo "done."
    
    # Create private subnet
    echo -n "Creating private subnet..."
    PRIVATE_SUBNET_ID=$(aws ec2 create-subnet --vpc-id $VPC_ID --cidr-block $PRIVATE_CIDR_SUBNET --query Subnet.SubnetId --output text)
    
    aws ec2 create-tags --resources $PRIVATE_SUBNET_ID --tags Key=Name,Value=$CLUSTER_NAME-private
    echo "done."
    
    # Create an internet gateway for outbound traffic and attach it to the VPC.
    echo -n "Creating internet gateway..."
    IGW_ID=$(aws ec2 create-internet-gateway --query InternetGateway.InternetGatewayId --output text)
    echo "done."
    
    aws ec2 create-tags --resources $IGW_ID --tags Key=Name,Value=$CLUSTER_NAME
    
    aws ec2 attach-internet-gateway --vpc-id $VPC_ID --internet-gateway-id $IGW_ID > /dev/null 2>&1
    echo "Attached IGW to VPC."
    
    # Create a route table for outbound traffic and associate it to the public subnet.
    echo -n "Creating route table for public subnet..."
    PUBLIC_ROUTE_TABLE_ID=$(aws ec2 create-route-table --vpc-id $VPC_ID --query RouteTable.RouteTableId --output text)
    
    aws ec2 create-tags --resources $PUBLIC_ROUTE_TABLE_ID --tags Key=Name,Value=$CLUSTER_NAME
    echo "done."
    
    aws ec2 create-route --route-table-id $PUBLIC_ROUTE_TABLE_ID --destination-cidr-block 0.0.0.0/0 --gateway-id $IGW_ID > /dev/null 2>&1
    echo "Created default public route."
    
    aws ec2 associate-route-table --subnet-id $PUBLIC_SUBNET_ID --route-table-id $PUBLIC_ROUTE_TABLE_ID > /dev/null 2>&1
    echo "Public route table associated"
    
    # Create a NAT gateway in the public subnet for outgoing traffic from the private network.
    echo -n "Creating NAT Gateway..."
    NAT_IP_ADDRESS=$(aws ec2 allocate-address --domain vpc --query AllocationId --output text)
    
    NAT_GATEWAY_ID=$(aws ec2 create-nat-gateway --subnet-id $PUBLIC_SUBNET_ID --allocation-id $NAT_IP_ADDRESS --query NatGateway.NatGatewayId --output text)
    
    aws ec2 create-tags --resources $NAT_IP_ADDRESS --resources $NAT_GATEWAY_ID --tags Key=Name,Value=$CLUSTER_NAME
    sleep 10
    echo "done."
    
    # Create a route table for the private subnet to the NAT gateway.
    echo -n "Creating a route table for the private subnet to the NAT gateway..."
    PRIVATE_ROUTE_TABLE_ID=$(aws ec2 create-route-table --vpc-id $VPC_ID --query RouteTable.RouteTableId --output text)
    
    aws ec2 create-tags --resources $PRIVATE_ROUTE_TABLE_ID $NAT_IP_ADDRESS --tags Key=Name,Value=$CLUSTER_NAME-private
    
    aws ec2 create-route --route-table-id $PRIVATE_ROUTE_TABLE_ID --destination-cidr-block 0.0.0.0/0 --gateway-id $NAT_GATEWAY_ID > /dev/null 2>&1
    
    aws ec2 associate-route-table --subnet-id $PRIVATE_SUBNET_ID --route-table-id $PRIVATE_ROUTE_TABLE_ID > /dev/null 2>&1
    
    echo "done."
    
    # echo "***********VARIABLE VALUES*********"
    # echo "VPC_ID="$VPC_ID
    # echo "PUBLIC_SUBNET_ID="$PUBLIC_SUBNET_ID
    # echo "PRIVATE_SUBNET_ID="$PRIVATE_SUBNET_ID
    # echo "PUBLIC_ROUTE_TABLE_ID="$PUBLIC_ROUTE_TABLE_ID
    # echo "PRIVATE_ROUTE_TABLE_ID="$PRIVATE_ROUTE_TABLE_ID
    # echo "NAT_GATEWAY_ID="$NAT_GATEWAY_ID
    # echo "IGW_ID="$IGW_ID
    # echo "NAT_IP_ADDRESS="$NAT_IP_ADDRESS
    
    echo "Setup complete."
    echo ""
    echo "To make the cluster create commands easier, please run the following commands to set the environment variables:"
    echo "export PUBLIC_SUBNET_ID=$PUBLIC_SUBNET_ID"
    echo "export PRIVATE_SUBNET_ID=$PRIVATE_SUBNET_ID"
    其他资源
    • 有关VPC要求的更多信息,请参阅VPC文档

  3. 脚本输出命令。将命令设置为环境变量以存储子网ID以供以后使用。复制并运行命令

    $ export PUBLIC_SUBNET_ID=$PUBLIC_SUBNET_ID
    $ export PRIVATE_SUBNET_ID=$PRIVATE_SUBNET_ID
  4. 通过运行以下命令确认您的环境变量

    $ echo "Public Subnet: $PUBLIC_SUBNET_ID"; echo "Private Subnet: $PRIVATE_SUBNET_ID"
    示例输出
    Public Subnet: subnet-0faeeeb0000000000
    Private Subnet: subnet-011fe340000000000

创建您的OIDC配置

在本教程中,我们将在创建OIDC配置时使用自动模式。我们还将OIDC ID存储为环境变量以供以后使用。该命令使用ROSA CLI创建集群唯一的OIDC配置。

  • 通过运行以下命令创建OIDC配置

    $ export OIDC_ID=$(rosa create oidc-config --mode auto --managed --yes -o json | jq -r '.id')

创建额外的环境变量

  • 运行以下命令来设置环境变量。这些变量使运行创建ROSA集群的命令更容易

    $ export CLUSTER_NAME=<cluster_name>
    $ export REGION=<VPC_region>

    运行rosa whoami查找VPC区域。

创建集群

  1. 可选:运行以下命令以创建帐户范围的角色和策略,包括Operator策略以及AWS IAM角色和策略

    仅当您第一次在此帐户中部署ROSA且尚未创建帐户角色和策略时,才完成此步骤。

    $ rosa create account-roles --mode auto --yes
  2. 运行以下命令以创建集群

    $ rosa create cluster --cluster-name $CLUSTER_NAME \
    --subnet-ids ${PUBLIC_SUBNET_ID},${PRIVATE_SUBNET_ID} \
    --hosted-cp \
    --region $REGION \
    --oidc-config-id $OIDC_ID \
    --sts --mode auto --yes

集群在大约10分钟后准备就绪。集群将在您选择的区域中的三个AWS可用区中拥有控制平面,并在您的AWS帐户中创建两个工作节点。

检查安装状态

  1. 运行以下命令之一以检查集群的状态

    • 要详细查看集群状态,请运行

      $ rosa describe cluster --cluster $CLUSTER_NAME
    • 要简要查看集群状态,请运行

      $ rosa list clusters
    • 要查看日志的进度,请运行

      $ rosa logs install --cluster $CLUSTER_NAME --watch
  2. 状态更改为“就绪”后,您的集群即已安装。工作节点上线可能还需要几分钟。