Mudits
Mudits

Reputation: 1643

How to delete an API resource in Kubernetes?

I ran:

kubectl api-resources | grep "External"
externalmetrics                                     metrics.aws                    true         ExternalMetric

I want to delete this metrics.aws API resource, but I am not even sure how it was deployed. How can I delete this safely?

Upvotes: 11

Views: 12032

Answers (2)

confused genius
confused genius

Reputation: 3284

  • If it is a not a standard resource, then It might be implemented as a "Customer Resource Definition (crds)"
kubectl get crds | grep externalmetrics 
  • Check if there are any Custom Resources created under this crd and delete them if there any :
kubectl get externalmetrics
kubectl delete externalmetrics --all 
  • Then delete that CRD
kubectl delete crd externalmetrics
  • Check if it is gone from api-resources list
kubectl api-resources

Update:

If you see error: the server doesn't have a resource type "v1beta1" error then run the following command to remove it:

kubectl delete apiservice v1beta1.metrics.k8s.io

Upvotes: 15

I had a similar issue; I wanted to completely remove PodSecurityPolicy, which was added when installing a kube-prometheus chart.

podsecuritypolicies psp policy/v1beta1 false PodSecurityPolicy

This worked for me:

kubectl get apiservices.apiregistration.k8s.io -> this returns the list.

kubectl delete apiservice v1beta1.policy -> this deletes it.

Upvotes: 0

Related Questions