일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 단기 합격
- karpenter
- Terraform
- Jenkins
- storageclass
- aews ci/cd
- AWS
- HPA
- VPA
- volume
- 도커
- 공부 방법
- docker
- kubernetes
- 외부 모듈
- keda
- CAS
- aews vault
- 클라우드 국비지원교육 후기
- POD
- Python
- 합격 후기
- 국비지원교육
- aews
- 클라우드 엔지니어
- observability
- 클라우드 국비지원교육
- EKS
- eks endpoint access
- k8s
- Today
- Total
모험가
AEWS 3주차 - Storage(EFS, Spot Node Group) 본문
본 글은 가시다님이 진행하시는 AEWS(AWS EKS Workshop Study)를 참여하여 정리한 글입니다. 모르는 부분이 많아서 틀린 내용이 있다면 말씀 부탁드리겠습니다! |
EFS
EBS Controller와 동일하게 EFS Controller을 설치하여 EFS와 Pod를 연결할 수 있습니다.
* 실습을 진행하기 전에 우선 EFS를 생성합니다.
# EFS 정보 확인
aws efs describe-file-systems --query "FileSystems[*].FileSystemId" --output text
# ISRA 설정 : 고객관리형 정책 AmazonEKS_EFS_CSI_Driver_Policy 사용
eksctl create iamserviceaccount \
--name efs-csi-controller-sa \
--namespace kube-system \
--cluster ${CLUSTER_NAME} \
--attach-policy-arn arn:aws:iam::aws:policy/service-role/AmazonEFSCSIDriverPolicy \
--approve \
--role-only \
--role-name AmazonEKS_EFS_CSI_DriverRole
# Amazon EFS CSI driver addon 배포(설치)
export ACCOUNT_ID=$(aws sts get-caller-identity --query 'Account' --output text)
eksctl create addon --name aws-efs-csi-driver --cluster ${CLUSTER_NAME} --service-account-role-arn arn:aws:iam::${ACCOUNT_ID}:role/AmazonEKS_EFS_CSI_DriverRole --force
kubectl get sa -n kube-system efs-csi-controller-sa -o yaml | head -5
# 확인
eksctl get addon --cluster ${CLUSTER_NAME}
이제 addon을 설치하였으니 pod가 EFS를 사용하도록 합니다.
pv,pvc,pod 확인
# [운영 서버 EC2]
# 실습 코드 clone
git clone https://github.com/kubernetes-sigs/aws-efs-csi-driver.git /root/efs-csi
cd /root/efs-csi/examples/kubernetes/multiple_pods/specs && tree
# EFS 스토리지클래스 생성 및 확인
cat storageclass.yaml
kubectl apply -f storageclass.yaml
kubectl get sc efs-sc
# PV 생성 및 확인 : volumeHandle을 자신의 EFS 파일시스템ID로 변경
EfsFsId=$(aws efs describe-file-systems --query "FileSystems[*].FileSystemId" --output text)
sed -i "s/fs-4af69aab/$EfsFsId/g" pv.yaml
cat pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: efs-pv
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
storageClassName: efs-sc
csi:
driver: efs.csi.aws.com
volumeHandle: <fs-xxxxxx>
kubectl apply -f pv.yaml
kubectl get pv; kubectl describe pv
# pvc 생성
kubectl apply -f claim.yaml
kubectl get pvc
EFS와 pod 연동
# 파드 생성
kubectl apply -f pod1.yaml,pod2.yaml
# 파드 정보 확인
kubectl get pods
kubectl exec -ti app1 -- sh -c "df -hT -t nfs4"
kubectl exec -ti app2 -- sh -c "df -hT -t nfs4"
위에서는 pv를 생성하고 pvc생성해서 pod를 만들때 이용하였습니다.
그러면 EBS처럼 Dynamic Provisioning 을 이용하며, 다수의 Pod가 EFS 파일 시스템을 이용하도록 해보겠습니다.
Dynamic Provisioning for EFS
# [운영 서버 EC2]
# EFS 스토리지클래스 생성 및 확인
curl -s -O https://raw.githubusercontent.com/kubernetes-sigs/aws-efs-csi-driver/master/examples/kubernetes/dynamic_provisioning/specs/storageclass.yaml
cat storageclass.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: efs-sc
provisioner: efs.csi.aws.com
parameters:
provisioningMode: efs-ap # The type of volume to be provisioned by Amazon EFS. Currently, only access point based provisioning is supported (efs-ap).
fileSystemId: <이 부분을 바꿔주시면 됩니다.?
directoryPerms: "700" # The directory permissions of the root directory created by the access point.
gidRangeStart: "1000" # optional, The starting range of the Posix group ID to be applied onto the root directory of the access point. The default value is 50000.
gidRangeEnd: "2000" # optional, The ending range of the Posix group ID. The default value is 7000000.
basePath: "/dynamic_provisioning" # optional, The path on the file system under which the access point root directory is created. If the path isn't provided, the access points root directory is created under the root of the file system.
subPathPattern: "${.PVC.namespace}/${.PVC.name}" # optional, A pattern that describes the subPath under which an access point should be created. So if the pattern were ${.PVC.namespace}/${PVC.name}, the PVC namespace is foo and the PVC name is pvc-123-456, and the basePath is /dynamic_provisioner the access point would be created at /dynamic_provisioner/foo/pvc-123-456
ensureUniqueDirectory: "true" # optional # A boolean that ensures that, if set, a UUID is appended to the final element of any dynamically provisioned path, as in the above example. This can be turned off but this requires you as the administrator to ensure that your storage classes are set up correctly. Otherwise, it's possible that 2 pods could end up writing to the same directory by accident. Please think very carefully before setting this to false!
reuseAccessPoint: "false" # optional
# 코드 수정(filesystemId)
vi storageclass.yaml
# 배포
kubectl apply -f storageclass.yaml
kubectl get sc efs-sc
# 파드 생성 및 확인
curl -s -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 get pvc,pv,pod
로그를 확인해보면 pvc을 감지하고 controller가 Dynamic하게 pv를 생성해서 attach함을 확인할 수 있습니다.
Spot Node Group
Spot Instance란?
Spot Instance는 온디맨드에 비해 최대 90%까지 저렴하게 사용할 수 있는 EC2 인스턴스입니다. 하지만 Spot Instance의 가격은 수요와 공급에 따라 실시간으로 변동되며, 사용자가 지정한 최대 가격을 초과하면 인스턴스가 중단될 수 있습니다. Spot Instance는 언제든 중단될 수 있기 때문에, 내결함성이 높고 중단에 대비할 수 있는 워크로드에 적합합니다. 예를 들어 배치 처리, 분산 컴퓨팅, 무상태 워크로드 등의 경우에 Spot Instance를 활용할 수 있습니다 |
즉 상태 비저장 API 서비스를 실행하는 것은 Spot Instance node group에 사용하기 적합합니다.
이제 instance-selecter을 설치합니다.
# [운영서버 EC2] ec2-instance-selector 설치
curl -Lo ec2-instance-selector https://github.com/aws/amazon-ec2-instance-selector/releases/download/v2.4.1/ec2-instance-selector-`uname | tr '[:upper:]' '[:lower:]'`-amd64 && chmod +x ec2-instance-selector
mv ec2-instance-selector /usr/local/bin/
ec2-instance-selector --version
# 적절한 인스턴스 스펙 선택을 위한 도구 사용
ec2-instance-selector --vcpus 2 --memory 4 --gpus 0 --current-generation -a x86_64 --deny-list 't.*' --output table-wide
# 노드 그룹 생성
NODEROLEARN=$(aws iam list-roles --query "Roles[?contains(RoleName, 'nodegroup-ng1')].Arn" --output text)
echo $NODEROLEARN
aws eks create-nodegroup \
--cluster-name <클러스터 이름> \
--nodegroup-name managed-spot \
--subnets <서브넷id1> <서브넷id2> <서브넷id3> \
--node-role $NODEROLEARN \
--instance-types c5.large c5d.large c5a.large \
--capacity-type SPOT \
--scaling-config minSize=2,maxSize=3,desiredSize=2 \
--disk-size 20
# 노드 확인
kubectl get nodes -L eks.amazonaws.com/capacityType,eks.amazonaws.com/nodegroup
CAPACITYTPE에 ON_DEMAND와 SPOT으로 타입을 확인 가능합니다.
콘솔에서도 확인이 가능합니다. 그사이에 벌써 1대가 지워지고 새롭게 띄워졌네요
Pod 실행 및 확인
#
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: busybox
spec:
terminationGracePeriodSeconds: 3
containers:
- name: busybox
image: busybox
command:
- "/bin/sh"
- "-c"
- "while true; do date >> /home/pod-out.txt; cd /home; sync; sync; sleep 10; done"
nodeSelector:
eks.amazonaws.com/capacityType: SPOT
EOF
# 파드가 배포된 노드 정보 확인
kubectl get pod -owide
이렇게 SPOT node group에 pod를 실행해보았습니다.
'쿠버네티스 > AEWS' 카테고리의 다른 글
AEWS 4주차 - Observability(Cloudwatch Observability, Metrics-server & kwatch) (0) | 2025.02.28 |
---|---|
AEWS 4주차 - Observability(Monitoring, EKS 컨트롤 플레인, 파드 로깅) (0) | 2025.02.27 |
AEWS 3주차 - Storage(PV, PVC, EBS) (0) | 2025.02.21 |
AEWS 2주차 - Networking(네트워크 분석 툴 Kubeskoop 설치) (0) | 2025.02.13 |
AEWS 2주차 - Networking(ExternalDNS, CoreDNS) (0) | 2025.02.13 |