Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
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
Tags
more
Archives
Today
Total
관리 메뉴

클라우드 엔지니어 꿈나무

EKF EFS 구성 본문

AWS

EKF EFS 구성

새싹싹이 2024. 1. 7. 20:44

EFS : 여러 가용 용역에서 접근 가능한 파일 스토리지. 때문에 보안 그룹이 생성 필요

 

efs.tf

resource "aws_efs_file_system" "kang" {
  creation_token = "kang-efs"

  tags = {
    Name    = "kang-efs"
    purpose = "hands-on"
  }
}

resource "aws_security_group" "kang_efs" {
  name		= "kang-efs"
  description	= "efs mount"
  vpc_id		= var.vpc_id

  ingress {
    description	= "efs mount"
    from_port	= 2049
    to_port		= 2049
    protocol	= "tcp"
    cidr_blocks	= [
      "10.0.0.0/8",
      "172.16.0.0/16",
      "192.168.0.0/16"
    ]
  }
}

resource "aws_efs_mount_target" "kang_efs_mount" {
  count = length(var.private_subnets)
  subnet_id	= var.private_subnets[count.index]
  file_system_id	= aws_efs_file_system.kang.id
  security_groups = [aws_security_group.kang_efs.id]
}

 

 

기존 노드 그룹이 크기가 작아 karpenter 로 provisioner (management)로 생성

<<참고>>

하기 내용 중 provisioner.yaml 에 service 부분만 management로 바꿔줌

https://hiheey.tistory.com/159 

 

 

curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-efs-csi-driver/master/docs/iam-policy-example.json => iam 정책 다운로드

aws iam create-policy --policy-name AmazonEKS_EFS_CSI_Driver_Policy2 --policy-document file://iam-policy-example.json => iam 정책 생성

 

aws iam create-policy --policy-name AmazonEKS_EFS_CSI_Driver_Policy2 --policy-document file://iam-policy-example.json => 역할 생성 및 정책 연결

eksctl create iamserviceaccount --cluster kang-cluster --namespace kube-system --name efs-csi-controller-sa --attach-policy-arn arn:aws:iam::<계정id>:policy/AmazonEKS_EFS_CSI_Driver_Policy2 --approve --region ap-northeast-2 => 서비스어카운트 생성

(스크립트로 만들려 하기와 같이 실행)

 

helm repo add aws-efs-csi-driver https://kubernetes-sigs.github.io/aws-efs-csi-driver/   

helm repo update

helm upgrade -i aws-efs-csi-driver aws-efs-csi-driver/aws-efs-csi-driver \
    --namespace kube-system \
    --set image.repository=602401143452.dkr.ecr.ap-northeast-2.amazonaws.com/eks/aws-efs-csi-driver \
    --set controller.serviceAccount.create=false \
    --set controller.serviceAccount.name=efs-csi-controller-sa

=> csi-driver 생성 차트 만듦

 

생성 확인

 

efs-strageclass.yaml

#terraform 으로 생성한 efs 정보 끌고옴
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: aws-efs-sc
provisioner: efs.csi.aws.com
parameters:
  provisioningMode: efs-ap
  fileSystemId: fs-05ddd71a54150080f #efse 아이디
  directoryPerms: "700"
  gidRangeStart: "1000"
  gidRangeEnd: "2000"
  basePath: "/dynamic_provisioning

 

nginx.yaml

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: efs-claim
  namespace: stage
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: aws-efs-sc
  resources:
    requests:
      storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-efs
  namespace: stage
spec:
  selector:
    matchLabels:
      app: nginx-efs
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx-efs
    spec:
      containers:
      - name: nginx-efs
        image: nginx:1.14.2
        ports:
        - containerPort: 80
        resources:
          requests:
            cpu: 128m
            memory: 64Mi
          limits:
            cpu: 256m
            memory: 128Mi
        volumeMounts:
          - name: kang-efs
            mountPath: /opt/efs_data
      volumes:
        - name: kang-efs
          persistentVolumeClaim:
            claimName: efs-claim
      tolerations:  #provisioner 인 management와 연결
      - key: "management"  # 테인트 값 입력
        operator: "Equal"  # 테인트의 키와 값이 정확히 일치
        value: "true" 
        effect: "NoSchedule"

 

 

pvc / pv / pod 작동 확인

 

 

kubectl exec -n stage -it nginx-efs-55cb7cfc86-d8vkw bash => efs 작동 확인을 위하여 nginx pod 진입

쉘을 두 개 열어 각각 다른 pod 에 진입하고 디렉토리 및 파일을 생성하여 하기와 같이 efs로 마운트 된 것을 확인할 수 있다.

 

 

<<참고>>

eksctl delete iamserviceaccount --cluster kang-cluster --namespace kube-system --name efs-csi-controller-sa --region ap-northeast-2 => 애드온 삭제