Search code examples
kuberneteskubernetes-pvc

List kubernetes pvc using labels of AGE


I have more than 4000 pvc in my kubernetes aws eks cluster.

From those 4000+ pvc I have to delete almost 3999 pvcs and not delete like 30 pvc.

I will be using the command:

kubectl delete pvc --field-selector metadata.name!=<name not to delete>

to test before I will be using

kubectl get pvc --field-selector metadata.name!=<name not to delete>
  • now when i use the command and add the pvc name of only ONE PVC in place of "name not to delete" the command works.. but when I add another pvc name rather than ONE like "kubectl get pvc --field-selector metadata.name!=pvc1 pvc2" .. it does NOT work

as I mentioned I do not want to delete 30 pvc but the rest 4000 I do want to delete... so I need to add those 30 pvc in front of the command. So I need help regarding that.

  • Now I also want to try to select resources in bacth by LABELS of AGE.. I only want to select pvc which are more than 2 days old.. how do I do that?

Solution

  • You can try

    kubectl get pvc --field-selector metadata.name!=pvc1,metadata.name!=pvc2
    

    See https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#get