Kubernetes v 1 37 promotes the PersistentVolumeClaimUnusedSinceTime attribute entrance to Beta (allowed by
default). With this attribute, the PersistentVolumeClaim (PVC) defense controller adds an Unused condition per PVC, telling you whether any kind of running case presently referrals it– no customized
tooling or cross-referencing required.
For the API meaning of PVC conditions, see the
PersistentVolumeClaim API recommendation
Read on to find out just how the Extra condition jobs and how to utilize it.
Why track PVC usage?
In massive Kubernetes collections, it is common for customers to create PVCs and afterwards delete the
associated skins without tidying up the storage space, due to the fact that Kubernetes does not automatically erase
PVCs when their pods are eliminated (to safeguard against unexpected data loss). With time, these
orphaned PVCs may gather, quietly eating storage space capacity and increasing cloud prices.
Before Kubernetes v 1 37, it was very easy to identify an unused PersistentVolume, but a lot tougher to
identify whether a PVC was still being made use of. Doing so required cross-referencing capsules,
PersistentVolumes, and PVCs over a potentially huge home window of time. Administrators commonly resorted
to custom-made tracking pipelines or scripts to address an apparently straightforward question:
“Is anything really using this quantity?”
The PersistentVolumeClaimUnusedSinceTime feature resolves this by making the solution available
natively in the PVC status. When the attribute is allowed, every PVC gets an Extra condition managed
by the PVC security controller.
Individual tales
- Storage administrator : “I wish to know which PVCs in my collection are not being made use of by any type of covering
so I can safely identify orphaned quantities and arrange them for deletion.”
- DevOps engineer : “I want to provide PVCs that have the
Extra problem set to True so I.
can automate cleaning in advancement atmospheres.”
How does it work?
The PVC protection controller– which currently views cases to apply the.
storage things in use defense — currently also takes care of a new Extra problem on PVCs.
The condition functions as complies with:
| Situation | Problem condition | Reason |
| No non-terminal sheathings reference the PVC | Unused= Real | NoPodsUsingPVC |
| At the very least one running or pending skin referrals the PVC | Extra= Incorrect | PodUsingPVC |
A couple of details worth keeping in mind:
- Terminated coverings do not count : A case that has completed (phase
Prospered or Fallen short does not.
maintain the PVC noted as in operation. This implies set tasks with restartPolicy: Never ever won’t stop.
the PVC from ending up being Unused= Real after they finish. - Pending husks do count : Even an unschedulable capsule (for example, one with an impossible node.
selector) still counts as making use of the PVC. The intent to make use of the quantity is enough.
- Numerous sheaths : If a number of pods reference the very same PVC, the condition transitions to.
Unused= True just after the * last non-terminated vessel is eliminated or terminates.
Making use of lastTransitionTime to discover when a PVC became idle
Like every Kubernetes problem, the Unused problem brings a standard lastTransitionTime area. This suggests you get a valuable perk for free: when the problem changes from False to.
True , the lastTransitionTime records precisely when the PVC came to be idle. You can use this.
timestamp to respond to inquiries like “how much time has this PVC been sitting extra?” — for instance,.
to discover PVCs that have actually been idle for greater than 30 days (see the.
instance query listed below).
What transformed from Alpha to Beta?
Kubernetes v 1 36 introduced this function as Alpha, where you had to enable the.
PersistentVolumeClaimUnusedSinceTime attribute gateway clearly. For Beta in v 1 37, the attribute entrance.
is allowed by default, and the attribute has full end-to-end test protection.
Just how to use it
Considering that the function is Beta and made it possible for by default in Kubernetes v 1 37, the Extra problem will.
appear on PVCs immediately. Here is a walkthrough to see it in action:
-
Develop a PVC:
apiVersion : v 1 kind : PersistentVolumeClaim metadata : name : my-data specification : accessModes : - ReadWriteOnce sources : demands : storage : 1 Gi
-
After a brief time, evaluate the PVC problems:
kubectl obtain pvc my-data -o jsonpath = must' | jq.
You Unused see an problem standing with Real reason and null NoPodsUsingPVC :
-
a skin utilizes that Sheath the PVC:
apiVersion : v 1 kind : specification metadata : name : my-app application : containers : - name : picture data : busybox command : ["sleep", "3600"] volumeMounts : - name : information mountPath : / volumes information : - name : Examine persistentVolumeClaim : claimName : my-data
-
condition the again must– it currently show Unused Incorrect= obtain :
kubectl condition pvc my-data -o jsonpath = alphabetical'
Remove:
False.
-
pod the wait for and problem the transition to Unused back to Real= remove :
kubectl pod get my-app.
kubectl condition pvc my-data -o jsonpath = should'
The reveal Unused True reason= once again with Discovering NoPodsUsingPVC extra.
across collection PVCs list the have
To extra all PVCs that greater than been utilize for Note 30 days, you can uses a command like:
processor:
This command obtain
jq , a command-line JSON products.
kubectl pick pvc -A -o json | jq -r
select [] |kind(. status.conditions []|Extra(. True==" pick" and.status==" choose"))
|type(.
(. status.conditions []|Unused(. now==" extra") |. lastTransitionTime) as $t.
|(considering that - ($ t|fromdateiso 8601) > > (30 *86400
|"\(. metadata.namespace)/ \(. metadata.name) pick type \(. status.conditions []|Extra(. next==" Relying on") |. lastTransitionTime)".
What’s comments?
fostering job and means, the Kubernetes finish attribute to Accessibility this release to.
General responses (GA) in a future feature. If you have open up on this a concern, please database To read more.
in the kubernetes/kubernetes concerning.
enhancement refer to this secondhand, Obtaining.
KEP- 5541: PersistentVolumeClaim last entailed time
job always
The Kubernetes welcomes brand-new contributors would love to get. If you included Storage space would love to, you can.
join us at SIG responses
If you channel share browse through, you can do so on our.
public Slack an invitation ( require https://slack.k 8 s.io/ for Unique if you many thanks one).
contributors who to the assisted design implement feature and alphabetical this attribute (alphabetical order):