0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【備忘】CLIベースでサクッとROSA with HCPを構築する

Last updated at Posted at 2024-10-23

はじめに

検証目的で新しく払い出したAWSアカウントに対して、極力CLIベースでそれなりのROSA with HCPクラスターを構築したい。

前提条件

  • ROSA with HCP v4.17.20
  • Macbook
    • 事前にocコマンド、rosaコマンド、terraformをインストールしておく
      • oc: 4.17.20
      • rosa: 1.2.46
      • terraform: 1.9.8
  • AWSアカウント
    • AdministratorAcces権限を持つIAMユーザーのキーとシークレット

手順

  • ROSAの有効化

    • https://console.aws.amazon.com/rosa から「使用を開始」を選択してROSA with HCPを有効化する
      1.png
    • Red Hatアカウントと自身のAWSアカウントをConnectする
      2.png
  • AWS CLIの設定

aws configure

export AWS_ACCESS_KEY_ID="aws account id"
export AWS_SECRET_ACCESS_KEY="aws secret key"
export AWS_DEFAULT_REGION="ap-northeast-1"
  • ROSA init
rosa init
  • ocm-roleを作成
    • 今回はOIDCプロバイダーも全部作って欲しいから、--adminオプションを追加
rosa create ocm-role --admin
  • user-roleを作成
rosa create user-role
  • account-rolesを作成
rosa create account-roles --hosted-cp --mode auto
  • OIDC Providerを作成
rosa create oidc-config
  • OIDC ProviderのConfig IDを変数に格納
    • 直前のコマンドの実行結果にIDが出力されているため、それを入力
export OIDC_CONFIG_ID="OIDCのID"
  • Operator Rolesを作成
    • Operator RolesのPrefix(任意の文字列)を変数に格納しておく
export OPERATOR_ROLE_PREFIX="ほげほげ"

rosa create operator-roles --prefix $OPERATOR_ROLE_PREFIX --oidc-config-id $OIDC_CONFIG_ID
  • VPCなどを作成
    • main.tfを作成(以下をそのままコピペ)
main.tf
provider "aws" {
}

variable "cluster_name" {
  type    = string
}

variable "aws_region" {
  type    = string
}

locals {

  vpc = {
    name = "${var.cluster_name}-vpc"
    cidr = "10.0.0.0/16"

    public_subnets = [
      "10.0.0.0/20",
      "10.0.16.0/20",
      "10.0.32.0/20",
    ]

    private_subnets = [
      "10.0.128.0/20",
      "10.0.144.0/20",
      "10.0.160.0/20",
    ]

    tags = {
      Terraform    = "true"
      service      = "ROSA"
      cluster_name = var.cluster_name
    }
  }
}

data "aws_caller_identity" "current" {}

data "aws_availability_zones" "available" {}

module "vpc" {
  source = "terraform-aws-modules/vpc/aws"

  name                 = local.vpc.name
  cidr                 = local.vpc.cidr
  enable_dns_hostnames = true

  azs = [
    data.aws_availability_zones.available.names[0],
    data.aws_availability_zones.available.names[1],
    data.aws_availability_zones.available.names[2],
  ]

  public_subnets  = local.vpc.public_subnets
  private_subnets = local.vpc.private_subnets

  enable_nat_gateway     = true
  single_nat_gateway     = false
  one_nat_gateway_per_az = true

  tags = local.vpc.tags
}

resource "local_file" "subnet_ids" {
  content  = join(",", concat(module.vpc.public_subnets, module.vpc.private_subnets))
  filename = "subnet_ids.txt"
}

output "vpc_cidr_block" {
  value = module.vpc.vpc_cidr_block
}

output "azs" {
  value = module.vpc.azs
}

output "aws_region" {
  value = var.aws_region
}
  • Terraform実行
    • クラスター名を変数に格納しておく
export CLUSTER_NAME="ROSAクラスター名"

terraform init
terraform apply -var "cluster_name=$CLUSTER_NAME" -var "aws_region=$AWS_DEFAULT_REGION"
  • 作成したSubnet IDを変数に格納
export SUBNET_IDS=$(cat subnet_ids.txt)
  • cluster-adminユーザーのパスワードを設定
export CLUSTER_ADMIN_PASSWORD="password"
  • ROSAクラスター作成
export ROSA_VERSION="4.17.20"
rosa create cluster --cluster-name $CLUSTER_NAME --sts \
    --operator-roles-prefix $OPERATOR_ROLE_PREFIX \
    --oidc-config-id $OIDC_CONFIG_ID \
    --region $AWS_DEFAULT_REGION \
    --version $ROSA_VERSION \
    --min-replicas 3 \
    --max-replicas 3 \
    --compute-machine-type m6a.xlarge \
    --machine-cidr 10.0.0.0/16 \
    --service-cidr 172.30.0.0/16 \
    --pod-cidr 10.128.0.0/14 \
    --host-prefix 23 \
    --subnet-ids $SUBNET_IDS \
    --enable-autoscaling \
    --create-admin-user \
    --cluster-admin-password $CLUSTER_ADMIN_PASSWORD \
    --hosted-cp
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?