AWS EKS에서 EFS 드라이버를 설치한 뒤, EFS를 이용한 Dynamic Provisioning을 테스트 하는 문서
고려 사항
- Amazon EFS CSI 드라이버는 Windows 기반 컨테이너 이미지와 호환 안됨
- Dynamic Provisioning의 경우, 1.2 이상의 드라이버 필요
사전 확인
- 클러스터에 대한 AWS Identity and Access Management(IAM) OpenID Connect(OIDC) 제공자 필요
- aws-cli 버전 2.12.3 이상
# 버전확인
$ aws --version | cut -d / -f2 | cut -d ' ' -f1
- kubectl 버전은 Kubernetes 버전과 동일하거나 최대 하나 이전 또는 이후의 마이너 버전 필요
# 버전 확인
$ kubectl version
테스트 환경
- AWS EKS(Kubernetes 1.32)
- Karpenter 사용
설치
1. IAM Role 생성
본문에서는 AWS 관리 콘솔을 이용해 작업
1. AWS 관리 콘솔에서 IAM > 역할 접속
2. 아래와 같이 역할 생성
2.1. 1단계: 신뢰할 수 있는 엔터티 선택

2.2. 2단계: 권한 추가

2.3. 3단계: 이름 지정, 검토 및 생성
Role 이름 지정 및 검토 후 역할 생성
2.4. 신뢰할 수 있는 엔터티 수정
생성한 역할 > 신뢰 관계 > 신뢰할 수 있는 엔터티로 이동
신뢰할 수 있는 엔터티 아래와 같이 수정
<account-id>, <region-code>,<id> 값은 환경에 맞게 세팅
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::<account-id>:oidc-provider/oidc.eks.<region-code>.amazonaws.com/id/<id>"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"oidc.eks.<region-code>.amazonaws.com/id/<id>:aud": [
"system:serviceaccount:kube-system:efs-csi-controller-sa",
"sts.amazonaws.com"
]
}
}
}
]
}
2. AWS EFS CSI 드라이버 설치
본문에서는 EKS 추가 기능으로 드라이버 설치
1. EFS CSI 드라이버 설치
1.1. AWS 관리 콘솔 > EKS > 클러스터 > <클러스터명> 선택 > 추가 기능 > 추가 기능 가져오기
1.2. 1단계: Amazon EFS CSI 드라이버 선택
1.3. 2단계: 선택한 추가 기능 설정 구성
여기에서 이전 생성한 IAM Role 선택

1.4. 3단계: 검토 및 추가
1.5. 설치 후 확인
# efs-csi-controller pod 확인
kubectl get po -n kube-system | grep efs-csi-controller
# service account 확인
kubectl get sa -n kube-system | grep efs-*
# service account annotations 확인(이전 생성한 role arn, annotations에서 확인)
kubectl describe sa <service-account> -n kube-system
# outpu 예시
# Name: efs-csi-controller-sa
# Namespace: kube-system
# Labels: app.kubernetes.io/name=aws-efs-csi-driver
# Annotations: eks.amazonaws.com/role-arn: arn:aws:iam::<account>:role/<role-name>
3. EFS 파일 시스템 생성
참고: https://github.com/kubernetes-sigs/aws-efs-csi-driver/blob/master/docs/efs-create-filesystem.md
vpc_id=$(aws eks describe-cluster \
--name <클러스터 명> \
--query "cluster.resourcesVpcConfig.vpcId" \
--output text)
cidr_range=$(aws ec2 describe-vpcs \
--vpc-ids $vpc_id \
--query "Vpcs[].CidrBlock" \
--output text \
--region <리전 명>)
# 보안 그룹 생성
security_group_id=$(aws ec2 create-security-group \
--group-name <EFS Security Group 명> \
--description "EFS security group" \
--vpc-id $vpc_id \
--output text)
# 보안 그룹 id 확인
echo $security_group_id
# 보안 그룹 인바운드 설정
aws ec2 authorize-security-group-ingress \
--group-id $security_group_id \
--protocol tcp \
--port 2049 \
--cidr $cidr_range
# EFS 파일 시스템 설정
file_system_id=$(aws efs create-file-system \
--region <리전 명> \
--performance-mode generalPurpose \
--encrypted \
--tags Key=Name,Value=<파일시스템명> \
--query 'FileSystemId' \
--output text)
# 서브넷 id 확인
aws ec2 describe-subnets \
--filters "Name=vpc-id,Values=$vpc_id" \
--query 'Subnets[*].{SubnetId: SubnetId,AvailabilityZone: AvailabilityZone,CidrBlock: CidrBlock}' \
--output table
# 현 테스트 환경에선 eks 클러스터가 private 서브넷에 위치하기 때문에 private 서브넷들만 마운트 타겟
aws efs create-mount-target \
--file-system-id $file_system_id \
--subnet-id <서브넷 id> \
--security-groups $security_group_id
AWS 관리 콘솔 > Amazon EFS > 파일 시스템에서 생성된 파일 시스템 확인 가능
4. EFS를 사용한 Dynamic Provisioning 확인
# Dynamic Provisioning 확인
# storageclass.yaml 다운로드
curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-efs-csi-driver/master/examples/kubernetes/dynamic_provisioning/specs/storageclass.yaml
# 파일 시스템 id 확인
aws efs describe-file-systems --query "FileSystems[*].FileSystemId" --output text
# storageclass.yaml에서 fileSystemId를 조회한 파일 시스템 id 수정
vi storageclass.yaml
# kind: StorageClass
# apiVersion: storage.k8s.io/v1
# metadata:
# name: efs-sc
#provisioner: efs.csi.aws.com
#parameters:
# provisioningMode: efs-ap
# fileSystemId: <파일 시스템 id>
kubectl apply -f storageclass.yaml
# 확인
kubectl describe sc efs-sc
# pod.yaml 다운로드
curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-efs-csi-driver/master/examples/kubernetes/dynamic_provisioning/specs/pod.yaml
kubectl apply -f pod.yaml
# 확인
kubectl describe persistentvolumeclaim/efs-claim
kubectl describe pod/efs-app
kubectl logs <efs-csi-controller pod 명> \
-n kube-system \
-c csi-provisioner \
--tail 10
AWS 관리 콘솔 > Amazon EFS > 엑세스 포인트에서 생성된 리소르 확인 가능
문서의 끝.
참고
https://docs.aws.amazon.com/ko_kr/eks/latest/userguide/efs-csi.html
Amazon EFS를 사용한 탄력적 파일 시스템 저장 - Amazon EKS
Fargate에서 실행되는 포드는 수동 드라이버 설치 단계 없이 Amazon EFS 파일 시스템을 자동으로 탑재합니다.
docs.aws.amazon.com
'AWS' 카테고리의 다른 글
[AWS] MFA(Multi-Factor Authentication) 설정 (0) | 2024.08.08 |
---|---|
AWS 주요 개념 및 서비스 간단 정리 (0) | 2024.08.06 |