aws/k8s, eks study
Delete multiple fargate profiles by Python script
gepp
2024. 4. 1. 17:02
python3이상, boto3 설치 필요
import boto3
import time
aws_profile = "your aws profile"
aws_region = "your region"
session = boto3.Session(
profile_name=aws_profile,
region_name=aws_region
)
eks_client = session.client('eks')
cluster_name = 'your cluster name'
# 해당 클러스터의 모든 Fargate 프로필 이름 가져오기
response = eks_client.list_fargate_profiles(clusterName=cluster_name)
profiles = response['fargateProfileNames']
# 각 Fargate 프로필 삭제
for profile in profiles:
print(f"Deleting Fargate profile: {profile}")
eks_client.delete_fargate_profile(clusterName=cluster_name, fargateProfileName=profile)
# 삭제 상태 확인
while True:
try:
eks_client.describe_fargate_profile(clusterName=cluster_name, fargateProfileName=profile)
print(f"Waiting for {profile} to be deleted...")
time.sleep(10)
except eks_client.exceptions.ResourceNotFoundException:
print(f"{profile} deleted.")
break
print("All Fargate profiles have been deleted.")