AWS EKS에서 EFS을 사용한 PV 삭제 방법

인쇄

Overview

EBS의 경우에는 AWS console에서 EC2 서비스의 Elastic Block Store에서 조회 및 변경, 삭제가 가능합니다.

EFS의 경우에도 AWS console에서 EFS(Elastic File System) 서비스가 있기는 하지만 단위가 file system 입니다.

EFS storage class를 이용해서 생성한 PV(Persistent Volume)의 경우에는 해당 file system안에 특정 path의 folder로 구성되어 있으므로 직접 file system으로 접근해서 삭제해야 합니다.

이 문서는 EFS를 사용해서 만들어진 PV를 삭제하는 방법을 설명합니다.

노드에 접속

AWS console에서 EC2 서비스의 Instance를 통해서 인스턴스를 선택하신 후에 [연결] 버튼을 누르시고 sessions manager로 접속하시면 됩니다.

인스턴스에 EFS file system을 mount

https://docs.aws.amazon.com/efs/latest/ug/mounting-fs.html

1. Amazon EFS client 설치

아래 예에서는 yum을 이용해서 설치하였습니다.

https://docs.aws.amazon.com/efs/latest/ug/installing-amazon-efs-utils.html

# sudo yum install -y amazon-efs-utils
Loaded plugins: priorities, update-motd
amzn2-core                                                                            | 3.7 kB  00:00:00
Resolving Dependencies
--> Running transaction check
---> Package amazon-efs-utils.noarch 0:1.31.2-1.amzn2 will be installed
--> Processing Dependency: stunnel >= 4.56 for package: amazon-efs-utils-1.31.2-1.amzn2.noarch
--> Processing Dependency: python3 for package: amazon-efs-utils-1.31.2-1.amzn2.noarch
--> Running transaction check
---> Package python3.x86_64 0:3.7.10-1.amzn2.0.1 will be installed
--> Processing Dependency: python3-libs(x86-64) = 3.7.10-1.amzn2.0.1 for package: python3-3.7.10-1.amzn2.0.1.x86_64
--> Processing Dependency: python3-setuptools for package: python3-3.7.10-1.amzn2.0.1.x86_64
--> Processing Dependency: python3-pip for package: python3-3.7.10-1.amzn2.0.1.x86_64
--> Processing Dependency: libpython3.7m.so.1.0()(64bit) for package: python3-3.7.10-1.amzn2.0.1.x86_64
---> Package stunnel.x86_64 0:4.56-6.amzn2.0.3 will be installed
--> Running transaction check
---> Package python3-libs.x86_64 0:3.7.10-1.amzn2.0.1 will be installed
---> Package python3-pip.noarch 0:20.2.2-1.amzn2.0.3 will be installed
---> Package python3-setuptools.noarch 0:49.1.3-1.amzn2.0.2 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
=============================================================================================================
 Package                       Arch              Version                         Repository             Size
=============================================================================================================
Installing:
 amazon-efs-utils              noarch            1.31.2-1.amzn2                  amzn2-core             46 k
Installing for dependencies:
 python3                       x86_64            3.7.10-1.amzn2.0.1              amzn2-core             72 k
 python3-libs                  x86_64            3.7.10-1.amzn2.0.1              amzn2-core            9.2 M
 python3-pip                   noarch            20.2.2-1.amzn2.0.3              amzn2-core            2.0 M
 python3-setuptools            noarch            49.1.3-1.amzn2.0.2              amzn2-core            1.1 M
 stunnel                       x86_64            4.56-6.amzn2.0.3                amzn2-core            149 k
 
Transaction Summary
=============================================================================================================
Install  1 Package (+5 Dependent packages)
 
Total download size: 12 M
Installed size: 54 M
Downloading packages:
(1/6): python3-3.7.10-1.amzn2.0.1.x86_64.rpm                                          |  72 kB  00:00:00
(2/6): amazon-efs-utils-1.31.2-1.amzn2.noarch.rpm                                     |  46 kB  00:00:00
(3/6): python3-pip-20.2.2-1.amzn2.0.3.noarch.rpm                                      | 2.0 MB  00:00:00
(4/6): python3-libs-3.7.10-1.amzn2.0.1.x86_64.rpm                                     | 9.2 MB  00:00:00
(5/6): python3-setuptools-49.1.3-1.amzn2.0.2.noarch.rpm                               | 1.1 MB  00:00:00
(6/6): stunnel-4.56-6.amzn2.0.3.x86_64.rpm                                            | 149 kB  00:00:00
-------------------------------------------------------------------------------------------------------------
Total                                                                         46 MB/s |  12 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : python3-pip-20.2.2-1.amzn2.0.3.noarch                                                     1/6
  Installing : python3-setuptools-49.1.3-1.amzn2.0.2.noarch                                              2/6
  Installing : python3-3.7.10-1.amzn2.0.1.x86_64                                                         3/6
  Installing : python3-libs-3.7.10-1.amzn2.0.1.x86_64                                                    4/6
  Installing : stunnel-4.56-6.amzn2.0.3.x86_64                                                           5/6
  Installing : amazon-efs-utils-1.31.2-1.amzn2.noarch                                                    6/6
  Verifying  : python3-libs-3.7.10-1.amzn2.0.1.x86_64                                                    1/6
  Verifying  : python3-pip-20.2.2-1.amzn2.0.3.noarch                                                     2/6
  Verifying  : python3-setuptools-49.1.3-1.amzn2.0.2.noarch                                              3/6
  Verifying  : stunnel-4.56-6.amzn2.0.3.x86_64                                                           4/6
  Verifying  : python3-3.7.10-1.amzn2.0.1.x86_64                                                         5/6
  Verifying  : amazon-efs-utils-1.31.2-1.amzn2.noarch                                                    6/6
 
Installed:
  amazon-efs-utils.noarch 0:1.31.2-1.amzn2
 
Dependency Installed:
  python3.x86_64 0:3.7.10-1.amzn2.0.1               python3-libs.x86_64 0:3.7.10-1.amzn2.0.1
  python3-pip.noarch 0:20.2.2-1.amzn2.0.3           python3-setuptools.noarch 0:49.1.3-1.amzn2.0.2
  stunnel.x86_64 0:4.56-6.amzn2.0.3
 
Complete!

2. Amazon EC2 Linux instances에 EFS mount

3가지 방법 중 한 가지를 선택해서 mount 하시면 됩니다.

# file system : ID를 이용한 방법
# sudo mount -t efs file-system-id efs-mount-point/
ex) sudo mount -t efs fs-12345678 efs/
 
 
# file system : DNS를 이용한 방법
# sudo mount -t -efs -o tls file-system-dns-name efs-mount-point/
ex) sudo mount -t -efs -o tls fs-12345678.efs.us-east-2.amazonaws.com efs/
 
# file system : IP address를 이용한 방법
sudo mount -t efs -o tls,mounttargetip=mount-target-ip file-system-id efs-mount-point/
ex) sudo mount -t efs -o tls,mounttargetip=192.0.2.0 fs-12345678 efs/

접근하고자 하는 EFS의 path 확인

# file system : ID를 이용한 방법
[ec2-user@ip-10-0-0-185 ~]$ sudo mount -t nfs fs-12345678.efs.ap-northeast-2.amazonaws.com:/ ~/efs-mount-point

# 정상적으로 mount되었는지 확인
[ec2-user@ip-10-0-0-185 ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 482M 0 482M 0% /dev
tmpfs 492M 0 492M 0% /dev/shm
tmpfs 492M 404K 492M 1% /run
tmpfs 492M 0 492M 0% /sys/fs/cgroup
/dev/xvda1 8.0G 1.5G 6.6G 19% /
tmpfs 99M 0 99M 0% /run/user/1000
fs-12345678.efs.ap-northeast-2.amazonaws.com:/ 8.0E 52G 8.0E 1% /home/ec2-user/efs-mount-point

# mount한 directory에 접근
$ cd /home/ec2-user/efs-mount-point
 
# directory 내용 확인
[ec2-user@ip-10-0-0-185 efs-mount-point]$ ll
합계 12
drwxr-xr-x 99 root root 14336 8월 12 06:16 zcp
 
[ec2-user@ip-10-0-0-185 efs-mount-point]$ cd zcp/
 
# [PVC name]-[PV name] 형태로 directory name인 것을 확인
[ec2-user@ip-10-0-0-185 zcp]$ ll
합계 392
...
drwxrws--x 14 root 40002 6144 8월 24 05:06 zcp-jenkins-pvc-989eddc5-271d-48a9-89c0-5df551589e47
drwxrws--x 2 root 40004 6144 9월 29 2020 zcp-registry-harbor-jobservice-pvc-119bd214-0bee-4885-8c42-0a121b90abe1
drwxr-xr-x 2 root root 6144 9월 9 05:32 zcp-test-pvc-119bd214-0bee-4885-8c42-0a121b90abe1

EFS directory 삭제

아래와 같이 directory를 삭제하신 후 해당 EFS를 사용해서 만들어진 PV 및 PVC를 삭제하시기 바랍니다.

# test directory 삭제 후 확인
[ec2-user@ip-10-0-0-185 zcp]$ sudo rm -rf zcp-test-pvc-119bd214-0bee-4885-8c42-0a121b90abe1
[ec2-user@ip-10-0-0-185 zcp]$ ll
합계 388
...
drwxrws--x  2 root 40003 6144  8월 11  2020 zcp-jenkins-mvn-repo-pvc-8846add2-14ee-4fb7-bbe6-5beb473d6420
drwxrws--x 14 root 40002 6144  8월 24 05:06 zcp-jenkins-pvc-989eddc5-271d-48a9-89c0-5df551589e47
drwxrws--x  2 root 40004 6144  9월 29  2020 zcp-registry-harbor-jobservice-pvc-119bd214-0bee-4885-8c42-0a121b90abe1


작업완료 후 EFS umount

# device 이름으로 umount
[ec2-user@ip-10-0-0-185 zcp]$ sudo umount fs-12345678.efs.ap-northeast-2.amazonaws.com:/

# mount한 directory 이름으로 unmount
[ec2-user@ip-10-0-0-185 zcp]$ sudo umount /home/ec2-user/efs-mount-point

온라인상담

문의하기

이 답변이 유용합니까? 아니오

Send feedback
도움이 되어드리지 못해 죄송합니다. 아티클 개선을 위해 의견을 제공해 주시기 바랍니다.