AWS EKS 클러스터 구성하기 (실습)
EKS 클러스터 생성
이전에 VPC를 생성한 이후, EKS 클러스터를 생성하셔야 합니다. EKS 코드는 아래 레포지토리에 템플릿 형태로 있으며, terraform/eks/eksd_apnortheast2/eksdapne2-fvrr/terraform.tfvars
에 있는 값을 수정하시면 원하는 EKS Cluster 버전, Add-On으로 구성할 수 있습니다.
변수 설정
아래 내용에서 Cluster 버전에 따라 release version이 달라질 수 있습니다. release version은 AWS에서 공식으로 제공해주는 AMI 버전과 동일하게 가져갑니다.
그리고 그 아래 node group과 같은 경우에는, on-demand와 spot 두 가지 타입을 선언했지만 구성 이후 Karpenter를 활용하신다면 spot nodegroup은 필요 없어지게 됩니다.
master_role_arn, viewer_role_arn은 eks 생성 이후 eks/_module/aws_auth.tf
에서 config map으로 주입되는 값들입니다. 여기에 설정된 IAM User, Role Arn에 대해서만 EKS Cluster에 접근할 수 있게 됩니다. 이 기능은 EKS Access Entries로 대체될 예정입니다.
변수 값 중 제일 아래 3가지는 KMS, Parameter Store, SecretsManager에 접근할 수 있는 부분을 설정하게 됩니다. 이 부분은 추후 bootstrap 과정에서 External Sercets Operator에서 접근할 수 있는 ARN을 지정해주시면 됩니다.
# Basic Information
account_alias = "id"
product = "eks"
# Cluster information
cluster_version = "1.30"
release_version = "1.30.4-20240917"
# Service CIDR
service_ipv4_cidr = "172.20.0.0/16"
# Addon information
# https://docs.aws.amazon.com/eks/latest/userguide/managing-coredns.html
coredns_version = "v1.11.1-eksbuild.9"
# https://docs.aws.amazon.com/eks/latest/userguide/managing-kube-proxy.html
kube_proxy_version = "v1.30.0-eksbuild.3"
# https://docs.aws.amazon.com/eks/latest/userguide/managing-vpc-cni.html
vpc_cni_version = "v1.18.3-eksbuild.1"
# https://github.com/kubernetes-sigs/aws-ebs-csi-driver
ebs_csi_driver_version = "v1.34.0-eksbuild.1"
# https://github.com/aws/eks-pod-identity-agent
pod_identity_agent_version = "v1.3.2-eksbuild.2"
# Enable Public Access
enable_public_access = true
# Fargate Information
fargate_enabled = false
fargate_profile_name = ""
# Node Group configuration
node_group_configurations = [
{
name = "ondemand_1_30_4-20240917"
spot_enabled = false
release_version = "1.30.4-20240917"
disk_size = 20
ami_type = "AL2023_x86_64_STANDARD"
node_instance_types = ["t3.large"]
node_min_size = 2
node_desired_size = 2
node_max_size = 2
labels = {
"cpu_chip" = "intel"
}
},
{
name = "spot_1_30_4-20240917"
spot_enabled = true
disk_size = 20
release_version = "1.30.4-20240917"
ami_type = "AL2023_x86_64_STANDARD"
node_instance_types = ["t3.large"]
node_min_size = 2
node_desired_size = 2
node_max_size = 10
labels = {
"cpu_chip" = "intel"
}
},
]
additional_security_group_ingress = [
{
from_port = 443
to_port = 443
protocol = "TCP"
cidr_blocks = ["10.10.0.0/16"]
}
]
aws_auth_master_users_arn = [
"arn:aws:iam::<account-id>:user/xxxxx"
]
# Cluster Access
aws_auth_master_roles_arn = [
"${data.terraform_remote_state.iam.outputs.demo_arn}"
]
aws_auth_viewer_roles_arn = [
]
# Specified KMS ARNs accessed by ExternalSecrets
external_secrets_access_kms_arns = [
"${var.aws_kms_arn}"
]
# Specified SSM ARNs accessed by ExternalSecrets
external_secrets_access_ssm_arns = [
"*"
]
# Specified SecretsManager ARNs accessed by ExternalSecrets
external_secrets_access_secretsmanager_arns = [
"${data.terraform_remote_state.secretsmanager.outputs.aws_secretsmanager_id}"
]
배포 진행
먼저 로컬에서 terraform init
& terraform plan
으로 정상적으로 생성되는지를 확인해봅니다. 만약 Public Access를 False로 하셨다면 Local 환경에서는 EKS에 접근할 수 없습니다.
# module.eks.kubernetes_config_map.aws_auth will be created
+ resource "kubernetes_config_map" "aws_auth" {
+ data = (known after apply)
+ id = (known after apply)
+ metadata {
+ generation = (known after apply)
+ name = "aws-auth"
+ namespace = "kube-system"
+ resource_version = (known after apply)
+ uid = (known after apply)
}
}
Plan: 56 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ aws_iam_openid_connect_provider_arn = (known after apply)
+ aws_iam_openid_connect_provider_url = (known after apply)
+ aws_security_group_eks_cluster_default_id = (known after apply)
+ aws_security_group_eks_cluster_id = (known after apply)
+ aws_security_group_eks_node_group_id = (known after apply)
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.
terraform plan
결과 위와 같이 56개의 리소스가 생성되는 것을 확인할 수 있습니다. 이후 Apply를 통해서 EKS 클러스터와 관련된 리소스가 생성된 것을 확인하실 수 있고, 콘솔 창에서도 아래와 같이 지정한 이름대로 클러스터가 생성된 것을 확인할 수 있습니다.
module.eks.aws_eks_addon.ebs_csi: Still creating... [30s elapsed]
module.eks.aws_eks_addon.ebs_csi: Still creating... [40s elapsed]
module.eks.aws_eks_addon.ebs_csi: Still creating... [50s elapsed]
module.eks.aws_eks_addon.ebs_csi: Creation complete after 55s [id=eksdapne2-aolu:aws-ebs-csi-driver]
Apply complete! Resources: 56 added, 0 changed, 0 destroyed.
Outputs:
aws_iam_openid_connect_provider_arn = "arn:aws:iam::<account-id>:oidc-provider/oidc.eks.ap-northeast-2.amazonaws.com/id/<oidc-id>"
aws_iam_openid_connect_provider_url = "oidc.eks.ap-northeast-2.amazonaws.com/id/<oidc-id>"
aws_security_group_eks_cluster_default_id = "sg-0f11de133a8bd16f3"
aws_security_group_eks_cluster_id = "sg-030b9ed1097d127c9"
aws_security_group_eks_node_group_id = "sg-0d95d73be64aa27d8"

생성한 EKS에 접근하기 위해서는 aws-auth에 접근 가능한 Role로 Assume한 상태이거나 User인 상태여야 합니다. 그 후, 아래 명령어를 실행해봅니다.
aws eks update-kubeconfig --name eksdapne2-aolu
> Updated context arn:aws:eks:ap-northeast-2:<account-id>:cluster/eksdapne2-aolu in /Users/test/.kube/config
위와 같이 Kubenetes의 Context가 Local에 설정되었다면, Kubectl 명령어를 통해 접근해보도록 합니다.
kubectl get nodes
> NAME STATUS ROLES AGE VERSION
ip-10-20-109-16.ap-northeast-2.compute.internal Ready <none> 6m6s v1.30.4-eks-a737599
ip-10-20-80-110.ap-northeast-2.compute.internal Ready <none> 6m12s v1.30.4-eks-a737599
ip-10-20-88-229.ap-northeast-2.compute.internal Ready <none> 6m13s v1.30.4-eks-a737599
ip-10-20-98-126.ap-northeast-2.compute.internal Ready <none> 6m7s v1.30.4-eks-a737599
kubectl get ns
> NAME STATUS AGE
default Active 27m
kube-node-lease Active 27m
kube-public Active 27m
kube-system Active 27m
이후 작업
이후에는 EKS 클러스터에서 아래의 Bootstrap 과정을 통해서 ArgoCD를 셋팅하고 기본적인 add-on(External Secrets, ALB Controller 등)을 설치하면 됩니다.
Last updated