CSI는 Kubernetes 클러스터 내에서 EFS를 사용하기 위한 드라이버로 EFS 파일 시스템을 마운트하여 컨테이너에 공유 스토리지를 제공, 관리할 수 있도록 합니다.
먼저, EKS에서 EFS의 역할부터 알아보도록 하겠습니다.
EFS는 EKS에서 여러 Pod들이 하나의 스토리지를 사용할 수 있도록 합니다.
하나의 AZ에서만 접근할 수 있는 EBS와 달리, EFS는 여러 가용 영역에서 접근할 수 있어 다른 Node에 배포되어 있는 Pod도 스토리지에 접근할 수 있습니다.
EFS를 사용하기 위해서는 드라이버가 설치되어야 하고 적절한 권한(AmazonElasticFileSystemFullAccess)이 필요합니다.
드라이버는 efs provisioner와 efs CSI driver가 있었는데 옛날 프로비저였던 efs provisioner 는 1.24버전 이후에는 사용하지 않고 현재는 CSI driver만 사용합니다.
CSI driver 장점
이전에는 각 플랫폼 별 드라이버를 따로 설치해야 하는 번거로움이 있었지만
CSI driver를 통해 하나의 드라이버로 모든 플랫폼을 제어할 수 있습니다.
CSI driver 특징
유연한 스토리지 공유: EFS CSI 드라이버는 Amazon EFS 파일 시스템을 Kubernetes 클러스터 내의 여러 컨테이너 간에 쉽게 공유할 수 있도록 합니다. 이를 통해 여러 컨테이너가 동일한 파일 시스템에 액세스하여 데이터를 공유하고 동기화할 수 있습니다.
동적 프로비저닝: EFS CSI 드라이버는 필요한 경우에 동적으로 EFS 파일 시스템을 프로비저닝합니다. 이는 클러스터 내에서 새로운 PVC (Persistent Volume Claim)를 생성할 때 필요한 파일 시스템을 자동으로 생성하고 마운트합니다.
쉬운 설정 및 관리: EFS CSI 드라이버는 Kubernetes의 CSI (Container Storage Interface) 표준을 따르므로, 설정 및 관리가 용이합니다. Kubernetes의 Persistent Volume 및 Persistent Volume Claim 개념과 함께 사용되며, 기존의 PVC 관리 방식과 일관된 방식으로 EFS를 사용할 수 있습니다.
스냅샷 및 복원: EFS CSI 드라이버를 사용하면 EFS 파일 시스템의 스냅샷을 생성하고 복원할 수 있습니다. 이는 파일 시스템의 상태를 특정 시점으로 저장하거나 이전 상태로 복원하는 데 유용합니다.
데이터 지속성 및 확장성: EFS는 데이터의 지속성과 확장성을 제공하는 관리형 파일 스토리지 서비스입니다. EFS CSI 드라이버를 통해 EFS를 사용하면 애플리케이션의 데이터를 신뢰성 있게 보호하고 필요한 경우 확장할 수 있습니다.
IAM 정책 및 역할 생성
IAM 정책문서 iam-policy-example.json다운로드
curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-efs-csi-driver/master/docs/iam-policy-example.json
정책 생성
aws iam create-policy \
--policy-name AmazonEKS_EFS_CSI_Driver_Policy \
--policy-document file://iam-policy-example.json
# Arn 메모
IAM 정책 연결
eksctl create iamserviceaccount \
--cluster myeks \
--namespace kube-system \
--name efs-csi-controller-sa \
--attach-policy-arn arn:aws:iam::계정ID:policy/AmazonEKS_EFS_CSI_Driver_Policy \
--approve \
--region ap-northeast-2
CSI driver 설치방법
helm을 통해 설치할 수 있습니다.
1. helm 설치
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 > get_helm.sh
chmod 700 get_helm.sh
./get_helm.sh
에러 발생 시
# get_helm.sh의 HELM_INSTALL_DIR을 $PATH와 일치하도록 수정한다.
helm not found. Is /usr/local/bin on your $PATH?
Failed to install helm
For support, go to https://github.com/helm/helm.
2. 레퍼지토리 추가
helm repo add aws-efs-csi-driver https://kubernetes-sigs.github.io/aws-efs-csi-driver/
#추가 후 업데이트
helm repo update
3. CSI driver 설치
# 아래 링크에서 리전별 image.repository값 확인
# https://docs.aws.amazon.com/ko_kr/eks/latest/userguide/add-ons-images.html
helm upgrade -i aws-efs-csi-driver aws-efs-csi-driver/aws-efs-csi-driver \
--namespace kube-system \
--set image.repository={리전별 값}/eks/aws-efs-csi-driver \
--set controller.serviceAccount.create=false \
--set controller.serviceAccount.name=efs-csi-controller-sa
EFS 파일 시스템 생성
VPC ID 검색 후 변수 저장
vpc_id=$(aws eks describe-cluster \
--name myeks \
--query "cluster.resourcesVpcConfig.vpcId" \
--output text)
CIDR 범위 변수 저장
cidr_range=$(aws ec2 describe-vpcs \
--vpc-ids $vpc_id \
--query "Vpcs[].CidrBlock" \
--output text \
--region ap-northeast-2)
Mount Point에 대한 Inbound SG 생성
security_group_id=$(aws ec2 create-security-group \
--group-name MyEfsSecurityGroup \
--description "My EFS security group" \
--vpc-id $vpc_id \
--output text)
Cluster VPC에 대한 CIDR -> Inbound Allow SG 생성
aws ec2 authorize-security-group-ingress \
--group-id $security_group_id \
--protocol tcp \
--port 2049 \
--cidr $cidr_range
EKS에 대한 파일 시스템 생성
file_system_id=$(aws efs create-file-system \
--region ap-northeast-2 \
--performance-mode generalPurpose \
--query 'FileSystemId' \
--output text)
Node IP와 Subnet ID, Subnet AZ 확인
aws ec2 describe-subnets \
--filters "Name=vpc-id,Values=$vpc_id" \
--query 'Subnets[*].{SubnetId: SubnetId,AvailabilityZone: AvailabilityZone,CidrBlock: CidrBlock}' \
--output table
Node 가 있는 Subnet에 대한 Mount Targets 추가
aws efs create-mount-target \
--file-system-id $file_system_id \
--subnet-id subnet-0d8be3835fe60e983 \
--security-groups $security_group_id
샘플 배포 테스트
참조 : https://kschoi728.tistory.com/94
출처 :
https://dev.to/awscommunity-asean/aws-eks-with-efs-csi-driver-and-irsa-using-cdk-dgc
'Docker & Kubenetes' 카테고리의 다른 글
Kubernetes - init container (0) | 2024.01.11 |
---|---|
Kubernetes Highly Available Clusters - 고가용성(HA) 클러스터 구축 (1) | 2023.11.20 |
Helm Operator (Helm Controller)에 대하여 (0) | 2023.10.13 |
쿠버네티스 Pod 배포 및 Upgrade 전략 (0) | 2023.10.04 |
쿠버네티스 Pod 배포 ( Taint & Toleration & Cordon & Drain ) (0) | 2023.09.11 |