Installing kubectl plugin with krew: unused-pvc

2 min read | by Jordi Prats

Krew is a plugin manager for kubectl (v1.12 or higher), we will need to install krew first. To be able to test the unused-volumes plugin we will have to create a PersistentVolumeClaim that we won't use on any pot:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: demo-pvc
  namespace: kube-system
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

Let's apply the yaml file to create the PVC:

$ kubectl apply -f demopvc.yaml 
persistentvolumeclaim/demo-pvc created

We can check that we have the PersistentVolumeClaim created an at least another one that we are currently using for testing the plugin:

$ kubectl get pvc -A
NAMESPACE     NAME       STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
jenkins       jenkins    Bound    pvc-e301a8da-bb95-4a44-99a9-b15f331cbfff   8Gi        RWO            standard       29d
kube-system   demo-pvc   Bound    pvc-297a4ab2-2710-46b1-8e7b-12922e0b6de0   10Gi       RWO            standard       22h

Now we will have to update the local copy of the plugin index to be able to install the plugin just like we do with apt-get update:

$ kubectl krew update
Updated the local copy of plugin index.

Then we can install the unused-volumes plugin:

$ kubectl krew install unused-volumes
Updated the local copy of plugin index.
Installing plugin: unused-volumes
Installed plugin: unused-volumes
\
 | Use this plugin:
 |  kubectl unused-volumes
 | Documentation:
 |  https://github.com/dirathea/kubectl-unused-volumes
/
WARNING: You installed plugin "unused-volumes" from the krew-index plugin repository.
   These plugins are not audited for security by the Krew maintainers.
   Run them at your own risk.

If we just execute the plugin using kubectl unused-volumes:

$ kubectl unused-volumes 
Name      Volume Name                               Size  Reason        Used By
demo-pvc  pvc-297a4ab2-2710-46b1-8e7b-12922e0b6de0  10Gi  No Reference         

We can see that it shows the PVC that we just created but we haven't assigned yet.


Posted on 13/01/2021