기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
테라폼으로 클러스터 만들기
사용 AWS ParallelCluster시 AWS ParallelCluster 이미지와 클러스터를 생성하거나 업데이트할 때 생성된 AWS 리소스에 대한 비용만 지불하면 됩니다. 자세한 정보는 AWS 에서 사용하는 서비스 AWS ParallelCluster을 참조하세요.
사전 조건
-
테라폼 v1.5.7+가 설치되어 있습니다.
-
AWS ParallelCluster APIv3.8.0+가 계정에 배포되었습니다. 테라폼으로 ParallelCluster API 배포하기 섹션을 참조하십시오.
-
API를 호출할 권한이 있는 IAM 역할. ParallelCluster [필수 권한] 을 참조하십시오.
테라폼 프로젝트 정의
이 튜토리얼에서는 클러스터를 배포하기 위한 간단한 Terraform 프로젝트를 정의합니다.
라는 디렉터리를 생성합니다.
my-clusters
생성하는 모든 파일은 이 디렉터리 내에 있습니다.
파일을
terraform.tf
생성하여 ParallelCluster 제공자를 가져오십시오.terraform { required_version = ">= 1.5.7" required_providers { aws-parallelcluster = { source = "aws-tf/aws-parallelcluster" version = "1.0.0" } } }
파일을
providers.tf
생성하여 ParallelCluster 및 AWS 제공자를 구성합니다.provider "aws" { region = var.region profile = var.profile } provider "aws-parallelcluster" { region = var.region profile = var.profile api_stack_name = var.api_stack_name use_user_role = true }
ParallelCluster모듈을 사용하여 리소스를 정의하는 파일을
main.tf
생성합니다.module "pcluster" { source = "aws-tf/parallelcluster/aws" version = "1.0.0" region = var.region api_stack_name = var.api_stack_name api_version = var.api_version deploy_pcluster_api = false template_vars = local.config_vars cluster_configs = local.cluster_configs config_path = "config/clusters.yaml" }
파일을
clusters.tf
생성하여 여러 클러스터를 Terraform 로컬 변수로 정의합니다.참고
요소 내에 여러 클러스터를 정의할 수 있습니다.
cluster_config
모든 군집에 대해 지역 변수 내에서 군집 속성을 명시적으로 정의 (참조DemoCluster01
) 하거나 외부 파일을 참조 (참조) 할 수 있습니다.DemoCluster02
구성 요소 내에서 설정할 수 있는 클러스터 속성을 검토하려면 을 참조하십시오. 클러스터 구성 파일
클러스터 생성을 위해 설정할 수 있는 옵션을 검토하려면 을 참조하십시오pcluster create-cluster.
locals { cluster_configs = { DemoCluster01 : { region : local.config_vars.region rollbackOnFailure : false validationFailureLevel : "WARNING" suppressValidators : [ "type:KeyPairValidator" ] configuration : { Region : local.config_vars.region Image : { Os : "alinux2" } HeadNode : { InstanceType : "t3.small" Networking : { SubnetId : local.config_vars.subnet } Iam : { AdditionalIamPolicies : [ { Policy : "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore" } ] } } Scheduling : { Scheduler : "slurm" SlurmQueues : [{ Name : "queue1" CapacityType : "ONDEMAND" Networking : { SubnetIds : [local.config_vars.subnet] } Iam : { AdditionalIamPolicies : [ { Policy : "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore" } ] } ComputeResources : [{ Name : "compute" InstanceType : "t3.small" MinCount : "1" MaxCount : "4" }] }] SlurmSettings : { QueueUpdateStrategy : "TERMINATE" } } } } DemoCluster02 : { configuration : "config/cluster_config.yaml" } } }
파일을
config/clusters.yaml
생성하여 여러 클러스터를 YAML 구성으로 정의합니다.DemoCluster03: region: ${region} rollbackOnFailure: true validationFailureLevel: WARNING suppressValidators: - type:KeyPairValidator configuration: config/cluster_config.yaml DemoCluster04: region: ${region} rollbackOnFailure: false configuration: config/cluster_config.yaml
Terraform 변수를 삽입할 수 있는 표준 ParallelCluster 구성 파일인 파일을 생성합니다.
config/cluster_config.yaml
구성 요소 내에서 설정할 수 있는 클러스터 속성을 검토하려면 을 참조하십시오. 클러스터 구성 파일
Region: ${region} Image: Os: alinux2 HeadNode: InstanceType: t3.small Networking: SubnetId: ${subnet} Iam: AdditionalIamPolicies: - Policy: arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore Scheduling: Scheduler: slurm SlurmQueues: - Name: queue1 CapacityType: ONDEMAND Networking: SubnetIds: - ${subnet} Iam: AdditionalIamPolicies: - Policy: arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore ComputeResources: - Name: compute InstanceType: t3.small MinCount: 1 MaxCount: 5 SlurmSettings: QueueUpdateStrategy: TERMINATE
파일을
clusters_vars.tf
생성하여 클러스터 구성에 삽입할 수 있는 변수를 정의합니다.이 파일을 사용하면 지역 및 서브넷과 같은 클러스터 구성에서 사용할 수 있는 동적 값을 정의할 수 있습니다.
이 예제는 프로젝트 변수에서 직접 값을 검색하지만 값을 결정하려면 사용자 지정 로직을 사용해야 할 수도 있습니다.
locals { config_vars = { subnet = var.subnet_id region = var.cluster_region } }
파일을
variables.tf
생성하여 이 프로젝트에 삽입할 수 있는 변수를 정의합니다.variable "region" { description = "The region the ParallelCluster API is deployed in." type = string default = "us-east-1" } variable "cluster_region" { description = "The region the clusters will be deployed in." type = string default = "us-east-1" } variable "profile" { type = string description = "The AWS profile used to deploy the clusters." default = null } variable "subnet_id" { type = string description = "The id of the subnet to be used for the ParallelCluster instances." } variable "api_stack_name" { type = string description = "The name of the CloudFormation stack used to deploy the ParallelCluster API." default = "ParallelCluster" } variable "api_version" { type = string description = "The version of the ParallelCluster API." }
terraform.tfvars
파일을 만들어 변수에 임의의 값을 설정합니다.아래 파일은 스택 이름과 함께 이미 배포된 기존 ParallelCluster API 3.10.0을 사용하여 서브넷
eu-west-1
subnet-123456789
내에 클러스터를 배포합니다.us-east-1
MyParallelClusterAPI-310
region = "us-east-1" api_stack_name = "MyParallelClusterAPI-310" api_version = "3.10.0" cluster_region = "eu-west-1" subnet_id = "subnet-123456789"
파일을
outputs.tf
생성하여 이 프로젝트에서 반환되는 출력을 정의합니다.output "clusters" { value = module.pcluster.clusters }
프로젝트 디렉토리는 다음과 같습니다.
my-clusters ├── config │ ├── cluster_config.yaml - Cluster configuration, where terraform variables can be injected.. │ └── clusters.yaml - File listing all the clusters to deploy. ├── clusters.tf - Clusters defined as Terraform local variables. ├── clusters_vars.tf - Variables that can be injected into cluster configurations. ├── main.tf - Terraform entrypoint where the ParallelCluster module is configured. ├── outputs.tf - Defines the cluster as a Terraform output. ├── providers.tf - Configures the providers: ParallelCluster and AWS. ├── terraform.tf - Import the ParallelCluster provider. ├── terraform.tfvars - Defines values for variables, e.g. region, PCAPI stack name. └── variables.tf - Defines the variables, e.g. region, PCAPI stack name.
클러스터 배포
클러스터를 배포하려면 표준 Terraform 명령을 순서대로 실행합니다.
참고
이 예시에서는 계정에 ParallelCluster API를 이미 배포했다고 가정합니다.
프로젝트 빌드:
terraform init
배포 계획 정의:
terraform plan -out tfplan
계획 배포:
terraform apply tfplan
클러스터와 함께 ParallelCluster API 배포
ParallelCluster API를 배포하지 않았는데 클러스터와 함께 배포하려는 경우 다음 파일을 변경하십시오.
main.tf
module "pcluster" { source = "aws-tf/aws/parallelcluster" version = "1.0.0" region = var.region api_stack_name = var.api_stack_name api_version = var.api_version deploy_pcluster_api = true template_vars = local.config_vars cluster_configs = local.cluster_configs config_path = "config/clusters.yaml" }
providers.tf
provider "aws-parallelcluster" { region = var.region profile = var.profile endpoint = module.pcluster.pcluster_api_stack_outputs.ParallelClusterApiInvokeUrl role_arn = module.pcluster.pcluster_api_stack_outputs.ParallelClusterApiUserRole }
필요한 권한
Terraform으로 클러스터를 배포하려면 다음 권한이 필요합니다.
-
API와의 상호 작용을 담당하는 ParallelCluster API 역할을 맡으십시오. ParallelCluster
-
ParallelCluster API AWS CloudFormation 스택을 설명하여 존재하는지 확인하고 해당 매개변수와 출력을 검색합니다.
{ "Version": "2012-10-17", "Statement": [ { "Action": "sts:AssumeRole", "Resource": "arn:
PARTITION
:iam::ACCOUNT
:role/PCAPIUserRole-*", "Effect": "Allow", "Sid": "AssumePCAPIUserRole" }, { "Action": [ "cloudformation:DescribeStacks" ], "Resource": "arn:PARTITION
:cloudformation:REGION
:ACCOUNT
:stack/*", "Effect": "Allow", "Sid": "CloudFormation" } ] }