본문 바로가기

TANGO/기본 환경 구성

Amazon EFS CSI Driver

1. Kubernetes Pods에 Amazon EFS Volumes을 구성하기 위하여 EFS Container Storage Interface (CSI) Driver를 설치한다.

$ kubectl apply -k "github.com/kubernetes-sigs/aws-efs-csi-driver/deploy/kubernetes/overlays/stable/?ref=release-1.0"

csi-driver/deploy/kubernetes/overlays/stable/?ref=release-1.0"
daemonset.apps/efs-csi-node created
csidriver.storage.k8s.io/efs.csi.aws.com configured
$kubectl get pods -n kube-system

NAME                                            READY   STATUS    RESTARTS   AGE
efs-csi-node-kfvlq                              3/3     Running   0          37s
efs-csi-node-ll6vs                              3/3     Running   0          37s
efs-csi-node-wv5sl                              3/3     Running   0          37s

 

2. EFS를 사용하여 persistent volume 생성

mkdir ~/environment/efs
cd ~/environment/efs
wget https://eksworkshop.com/beginner/190_efs/efs.files/efs-pvc.yaml

아래와 같은 yaml 파일을 다운 받았다.

~/environment/efs $ ls
efs-pvc.yaml  efs-pvc.yaml.1  efs-reader.yaml  efs-writer.yaml

efs-pvc.yaml의 내용은 다음과 같다.

apiVersion: v1
kind: Namespace
metadata:
  name: storage
  
---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: efs-sc
provisioner: efs.csi.aws.com

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: efs-pvc
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  storageClassName: efs-sc
  csi:
    driver: efs.csi.aws.com
    volumeHandle: EFS_VOLUME_ID

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: efs-storage-claim
  namespace: storage
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: efs-sc
  resources:
    requests:
      storage: 5Gi

 

위의 yaml에서 EFS ID를 실제 사용할 EFS File System ID로 교체한다.

sed -i "s/EFS_VOLUME_ID/$FILE_SYSTEM_ID/g" efs-pvc.yaml

 

이제 efs pvc를 생성한다.

$ kubectl apply -f efs-pvc.yaml

namespace/storage created
storageclass.storage.k8s.io/efs-sc created
persistentvolume/efs-pvc created
persistentvolumeclaim/efs-storage-claim created

efs pv와 pvc 상태를 확인한다.

$ kubectl get pvc -n storage

NAME                STATUS   VOLUME    CAPACITY   ACCESS MODES   STORAGECLASS   AGE
efs-storage-claim   Bound    efs-pvc   5Gi        RWX            efs-sc         53s
$ kubectl get pv
NAME      CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                       STORAGECLASS   REASON   AGE
efs-pvc   5Gi        RWX            Retain           Bound    storage/efs-storage-claim   efs-sc                  80s

 

efs-reader pod의 예시

apiVersion: v1
kind: Pod
metadata:
  name: efs-reader
  namespace: storage
spec:
  containers:
  - name: efs-reader
    image: busybox
    command: ["/bin/sh"]
    args: ["-c", "while true; do sleep 5; done"]
    volumeMounts:
    - name: efs-pvc
      mountPath: /shared
  volumes:
  - name: efs-pvc
    persistentVolumeClaim:
      claimName: efs-storage-claim

efs-writer pod의 예시

apiVersion: v1
kind: Pod
metadata:
  name: efs-writer
  namespace: storage
spec:
  containers:
  - name: efs-writer
    image: busybox
    command: ["/bin/sh"]    
    args: ["-c", "while true; do echo $POD_NAME.$POD_NAMESPACE - $(date -u) >> /shared/out.txt; sleep 5; done"]
    env:
    - name: POD_NAME
      valueFrom:
        fieldRef:
          fieldPath: metadata.name    
    - name: POD_NAMESPACE
      valueFrom:
        fieldRef:
          fieldPath: metadata.namespace           
    volumeMounts:
    - name: efs-pvc
      mountPath: /shared
  volumes:
  - name: efs-pvc
    persistentVolumeClaim:
      claimName: efs-storage-claim

'TANGO > 기본 환경 구성' 카테고리의 다른 글

MSK 구성 (미완료)  (0) 2021.05.09
Prometheus와 Grafana 구성  (0) 2021.05.08
AMAZON EBS CSI DRIVER  (1) 2021.05.08
AWS Load Balancer Controller (Ingress Controller) 설치  (0) 2021.05.08
kube-ops-view 설치  (0) 2021.05.08