Joo's

아래 명령어를 치면 crossplane으로 생성된 managed resource를 다 확인할 수 있다.

kubectl -n {namespace} get managed

아래와 같은 식으로 나온다.

NAME                                                        SYNCED   READY   EXTERNAL-NAME          AGE
securitygroup.ec2.aws.upbound.io/securitygroup-2ran4j       True     True    sg-01c128d8c2792706f   49d
securitygroup.ec2.aws.upbound.io/securitygroup-4nqyg4       True     True    sg-0d32cf036a5717ac4   54d
securitygroup.ec2.aws.upbound.io/securitygroup-emr-master   False    True    sg-07f9b4784161047ee   96d
securitygroup.ec2.aws.upbound.io/securitygroup-emr-slave    False    True    sg-0f5f9db854367325a   96d

이 리소스 삭제하려면 아래와 같이 delete name을 하면 된다.

kubectl -n {namespace} delete securitygroup.ec2.aws.upbound.io/securitygroup-emr-master

근데 리소스가 너무 많아서 파이썬 실행해서 한번에 지우려고 함.

리소스에 지우려는 리소스 이름들 넣으면 됨.

import subprocess
import os

namespace = "wiseon-system"
resources = [
    "vpcendpointsubnetassociation.ec2.aws.upbound.io/vpcendpointsubnetassociation-5tdm53",
    "vpcendpointsubnetassociation.ec2.aws.upbound.io/vpcendpointsubnetassociation-h9e9gk",
    "vpcendpointsubnetassociation.ec2.aws.upbound.io/vpcendpointsubnetassociation-tbr3tc",
    "vpcendpointsubnetassociation.ec2.aws.upbound.io/vpcendpointsubnetassociation-xfnaz8"
]

kubeconfig = os.path.expanduser("~/.kube/config_aws")

for full_resource in resources:
    print(f"Deleting resource: {full_resource}")
    subprocess.run([
        "kubectl", "--kubeconfig", kubeconfig,
        "-n", namespace, "delete", full_resource
    ])

### 아래는 같은 이름을 가진 configmap을 삭제하는 거임. 안쓰면 주석 처리
    name = full_resource.split("/")[-1]
    print(f"Deleting ConfigMap: {name}")
    subprocess.run([
        "kubectl", "--kubeconfig", kubeconfig,
        "-n", namespace, "delete", "cm", name
    ])
profile

Joo's

@JooJY

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!