☁️
클라우드
EKS
Elastic Kubernetes Service
AWS 관리형 Kubernetes. 컨트롤 플레인 자동 관리. Fargate 통합.
Elastic Kubernetes Service
AWS 관리형 Kubernetes. 컨트롤 플레인 자동 관리. Fargate 통합.
Amazon EKS(Elastic Kubernetes Service)는 AWS에서 제공하는 완전 관리형 Kubernetes 서비스입니다. 컨트롤 플레인(API 서버, etcd, 스케줄러)을 AWS가 관리해주므로 운영 부담 없이 프로덕션 급 Kubernetes를 사용할 수 있습니다.
EKS의 핵심 구성 요소:
노드 타입 비교:
# eksctl로 EKS 클러스터 생성 (가장 간단한 방법)
eksctl create cluster \
--name my-cluster \
--version 1.29 \
--region ap-northeast-2 \
--nodegroup-name standard-workers \
--node-type t3.medium \
--nodes 3 \
--nodes-min 2 \
--nodes-max 5 \
--managed
# Fargate 프로파일 추가
eksctl create fargateprofile \
--cluster my-cluster \
--name fp-default \
--namespace default
# 스팟 인스턴스 노드 그룹 추가 (비용 절감)
eksctl create nodegroup \
--cluster my-cluster \
--name spot-workers \
--node-type t3.large \
--nodes 3 \
--spot \
--instance-types t3.large,t3a.large,m5.large
# AWS Load Balancer Controller 설치
eksctl create iamserviceaccount \
--cluster=my-cluster \
--namespace=kube-system \
--name=aws-load-balancer-controller \
--attach-policy-arn=arn:aws:iam::aws:policy/ElasticLoadBalancingFullAccess \
--override-existing-serviceaccounts \
--approve
# 클러스터 삭제
eksctl delete cluster --name my-cluster --region ap-northeast-2
# Terraform EKS 클러스터 구성
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "~> 20.0"
cluster_name = "my-cluster"
cluster_version = "1.29"
cluster_endpoint_public_access = true
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
# 클러스터 애드온
cluster_addons = {
coredns = {
most_recent = true
}
kube-proxy = {
most_recent = true
}
vpc-cni = {
most_recent = true
}
}
# 관리형 노드 그룹
eks_managed_node_groups = {
# 일반 워크로드용
general = {
instance_types = ["t3.medium"]
capacity_type = "ON_DEMAND"
min_size = 2
max_size = 10
desired_size = 3
labels = {
workload = "general"
}
}
# 스팟 인스턴스 (비용 절감)
spot = {
instance_types = ["t3.large", "t3a.large", "m5.large"]
capacity_type = "SPOT"
min_size = 0
max_size = 10
desired_size = 2
labels = {
workload = "spot"
}
taints = [{
key = "spot"
value = "true"
effect = "NO_SCHEDULE"
}]
}
}
# Fargate 프로파일
fargate_profiles = {
kube_system = {
name = "kube-system"
selectors = [
{ namespace = "kube-system" }
]
}
}
tags = {
Environment = "production"
Terraform = "true"
}
}
# IRSA (IAM Roles for Service Accounts)
module "irsa_s3" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
version = "~> 5.0"
role_name = "my-app-s3-role"
oidc_providers = {
main = {
provider_arn = module.eks.oidc_provider_arn
namespace_service_accounts = ["default:my-app"]
}
}
role_policy_arns = {
s3_read = "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
}
}
# kubeconfig 업데이트
aws eks update-kubeconfig \
--region ap-northeast-2 \
--name my-cluster
# 클러스터 정보 확인
kubectl cluster-info
kubectl get nodes -o wide
# EKS 네임스페이스별 Pod 배치 확인
kubectl get pods -A -o wide
# EKS에서 ALB Ingress 사용
cat <<EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-app-ingress
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-app
port:
number: 80
EOF
# IRSA로 Pod에 AWS 권한 부여
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ServiceAccount
metadata:
name: my-app
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::123456789:role/my-app-s3-role
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
serviceAccountName: my-app # IRSA 연결
containers:
- name: app
image: my-app:latest
# AWS SDK가 자동으로 IRSA 자격 증명 사용
EOF
# 노드 그룹 스케일링
kubectl scale deployment my-app --replicas=10