How to delete PV using EFS in AWS EKS

Print

Overview

In the case of EBS, you can search, change, and delete in the Elastic Block Store of the EC2 service in the AWS console.

In the case of EFS, there is an EFS (Elastic File System) service in the AWS console, but the unit is a file system.

In the case of PV (Persistent Volume) created using the EFS storage class, it is configured as a folder with a specific path in the file system, so you must access the file system directly and delete it.

This document explains how to delete a PV created using EFS.

Connect to node

After selecting an instance through the EC2 service Instance in the AWS console, click the [Connect] button and connect to the sessions manager.

Mount the EFS file system on the instance

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

1. Install Amazon EFS client

In the example below, installation was done using 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. Mount EFS on Amazon EC2 Linux instances

You can mount it by choosing one of the three methods.

# 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/

Check the path of the EFS you want to access

# 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

Delete EFS directory

After deleting the directory as shown below, please delete the PV and PVC created using the EFS.

# 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


After the task is completed, umount EFS

# 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

Online consultation

Contact us

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.