Red Hat Training

A Red Hat training course is available for OpenShift Container Platform

第 20 章 为 Amazon Web Services(AWS)配置

20.1. 概述

OpenShift Container Platform 可以配置为访问 AWS EC2 基础架构包括使用 AWS 卷作为应用程序数据的持久性存储。配置 AWS 后,必须在 OpenShift Container Platform 主机上完成一些额外的配置。

20.1.1. 为 Amazon Web Services(AWS)配置授权

权限 AWS 实例需要使用在创建时分配给实例的 access 和 secret 密钥或 IAM 角色来请求和管理 OpenShift Container Platform 中的负载均衡器和存储的 IAM 角色。

IAM 帐户或 IAM 角色必须具有以下策略权限才能拥有完整的云供应商功能。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "ec2:DescribeVolume*",
                "ec2:CreateVolume",
                "ec2:CreateTags",
                "ec2:DescribeInstances",
                "ec2:AttachVolume",
                "ec2:DetachVolume",
                "ec2:DeleteVolume",
                "ec2:DescribeSubnets",
                "ec2:CreateSecurityGroup",
                "ec2:DescribeSecurityGroups",
                "ec2:DeleteSecurityGroup",
                "ec2:DescribeRouteTables",
                "ec2:AuthorizeSecurityGroupIngress",
                "ec2:RevokeSecurityGroupIngress",
                "elasticloadbalancing:DescribeTags",
                "elasticloadbalancing:CreateLoadBalancerListeners",
                "elasticloadbalancing:ConfigureHealthCheck",
                "elasticloadbalancing:DeleteLoadBalancerListeners",
                "elasticloadbalancing:RegisterInstancesWithLoadBalancer",
                "elasticloadbalancing:DescribeLoadBalancers",
                "elasticloadbalancing:CreateLoadBalancer",
                "elasticloadbalancing:DeleteLoadBalancer",
                "elasticloadbalancing:ModifyLoadBalancerAttributes",
                "elasticloadbalancing:DescribeLoadBalancerAttributes"
            ],
            "Resource": "*",
            "Effect": "Allow",
            "Sid": "1"
        }
    ]
}
aws iam put-role-policy \
  --role-name openshift-role \
  --policy-name openshift-admin \
  --policy-document file: //openshift_iam_policy
aws iam put-user-policy \
  --user-name openshift-admin \
  --policy-name openshift-admin \
  --policy-document file: //openshift_iam_policy
注意

OpenShift 节点实例只需要 ec2:DescribeInstance 权限,但安装程序仅允许定义单个 AWS 访问密钥和 secret。这可绕过使用 IAM 角色,并将上面的权限分配给 master 实例,并将 ec2:DescribeInstance 分配给节点。

20.1.1.1. 在安装时配置 OpenShift Container Platform 云供应商

流程

要使用具有 access 和 secret 键的 IAM 帐户配置 Amazon Web Services 云供应商,请将以下值添加到清单中:

[OSEv3:vars]
openshift_cloudprovider_kind=aws
openshift_clusterid=openshift 1
openshift_cloudprovider_aws_access_key=AKIAJ6VLBLISADPBUA 2
openshift_cloudprovider_aws_secret_key=g/8PmDNYHVSQn0BQE+xtsHzbaZaGYjGNzhbdgwjH 3
1
分配给所有资源(实例、负载平衡器、vpc 等)的标签(用于 OpenShift)。
2
IAM 帐户使用的 AWS 访问密钥。
3
IAM 帐户使用的 AWS secret 密钥。

要使用 IAM 角色配置 Amazon Web Services 云供应商,请在清单中添加以下值:

[source,yaml]
----
[OSEv3:vars]
openshift_cloudprovider_kind=aws
openshift_clusterid=openshift 1
----
<1> A tag assigned to all resources (instances, load balancers, vpc, etc) used for OpenShift.
NOTE: The IAM role takes the place of needing an access and secret key.

20.1.1.2. 安装后配置 OpenShift Container Platform 云供应商

如果安装时没有提供 Amazon Web Services 云供应商值,则可以在安装后定义和创建配置。按照以下步骤配置配置文件,并为 AWS 手动配置 master 和节点

重要
  • 每个 master 主机、节点主机和子网必须具有 kubernetes.io/cluster/<clusterid>,Value=(owned|shared) 标签。
  • 一个安全组(最好链接到节点)必须具有 kubernetes.io/cluster/<clusterid>,Value=(owned|shared) 标签。

    • 不要使用 kubernetes.io/cluster/<clusterid>,Value=(owned|shared) 标签标记所有安全组,否则 Elastic Load Balancing(ELB)将无法创建负载均衡器。