aws/efs

EFS Dynamic provisioning with iam option

gepp 2024. 6. 10. 16:29

 

EFS 를 동적 프로비저닝 및 iam option 을 통한 IRSA 로 EFS 접근 시 구성

PVC 에 iam 마운트 옵션을 정의하고 동적 프로비저닝에 의해 자동 생성된 PV는 이를 상속받습니다.

해당 구성은 EKS Fargate 가 아닌 EKS EC2 Node 사용 시 동적 프로비저닝 예시입니다.

 

 

Sample of storageclass.yaml

allowVolumeExpansion: true
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  annotations:
    storageclass.kubernetes.io/is-default-class: "true" # true or false
  name: default-efs
mountOptions:
  - iam
  - tls
parameters:
  directoryPerms: "755" # directory permission value of 755 allows the directory user owner to list files, create files, and mount, and all other users to list files and mount.
  fileSystemId: fs-xxxxxxxx # replace this with the efs id actually created on your env
  provisioningMode: efs-ap
  gidRangeStart: "1000"
  gidRangeEnd: "2000"
  basePath: "/data" # whatever you want
  encrypted: "true" # in case you use encryption on your EFS
provisioner: efs.csi.aws.com
reclaimPolicy: Delete
volumeBindingMode: Immediate

 

tls option 은 deprecated 되었다고 로그가 확인되어, tls 는 뺐고 (default 가 tls enabled) EFS 가 암호화 되어있어 encrypted: true 를 넣었습니다.

 

Sample of pvc.yaml

 

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: efs-pvc-test
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: default-efs
  resources:
    requests:
      storage: 1Gi # adjust this depending on your requirement

 

 

Sample of serviceaccount.yaml

 

apiVersion: v1
kind: ServiceAccount
metadata:
  annotations:
    eks.amazonaws.com/role-arn: arn:aws:iam::<account number>:role/<iam role name>
  name: test
  namespace: <your namespace>

 

테스트 시에는 IAM 역할 없이 마운트 잘 되었고 eks node(ec2) 역할에 권한이 있었다.

 

 

Sample of efs-test-pod.yaml

 

apiVersion: v1
kind: Pod
metadata:
  name: efs-testpod-01
spec:
  serviceAccountName: test
  containers:
    - name: alpine
      image: alpine
      command: ["/bin/sh"]
      args: ["-c", "echo 'Starting Nginx'; echo 'Log entry: $(date)' >> /usr/share/nginx/html/log.txt; sleep infinity"]
      volumeMounts:
        - name: efs-volume
          mountPath: /usr/share/nginx/html
  volumes:
    - name: efs-volume
      persistentVolumeClaim:
        claimName: efs-pvc-test

 

 

Pod 아웃바운드 보안그룹에 NFS 포트(port 2049) 허용, EFS 보안그룹에 pod 보안그룹 인입에 대한 NFS 포트 허용이 되어있어야 하고,

IRSA 용 IAM 역할의 권한에 해당 서비스(EFS)에 접근할 권한이 포함되어 있어야 합니다.