Remove–PersistentVolume - anongitmous/k8sShell GitHub Wiki

Remove the Kubernetes persistent volume resource(s).

Syntax

Remove-PersistentVolume

[-PersistentVolumes] <Mtf.Kubernetes.Models.V1K8sPersistentVolume[]>
[<K8sShellRemoveParameters>]
[<K8sShellCommonCore>]
[<CommonParameters>]

Description

Removes persistent volume resource objects from the cluster.

See the example output.

Examples

ℹ️ See A Note about the Examples

1. Delete all persistent volumes from the currently-active cluster

Get-PersistentVolumes | Remove-PersistentVolume

  • The results from Get–PersistentVolumes are piped into Remove-PersistentVolume
  • If there is no currently active namespace (i.e. namespace is $null or an empty string ''), then this would delete all persistent volumes from all namespaces.
  • Using aliasing, the above can be shortened to
    ksgpv | ksrpv

2. Delete the persistent volume named 'my_pv'

Get-PersistentVolumes | Where-Object {$_.Name -match 'my_pv'} | Remove-PersistentVolume

  • To do a trial run, utilize the -DryRun All option:
    Get-PersistentVolumes | Where-Object {$_.Name -match 'my_pv'} | Remove-PersistentVolume -DryRun All
  • Using aliasing, the previous can be shortened to
    ksgpv | ? {$_.Name -match 'my_pv'} | ksrpv -DryRun All

3. Delete all persistent volumes that are not bound

Get-PersistentVolumes | Where-Object {$_.Status -notmatch 'bound'} | Remove-PersistentVolume

  • To do a trial run, utilize the -DryRun All option:
    Get-PersistentVolumes | Where-Object {$_.Status -notmatch 'bound'} | Remove-PersistentVolume -DryRun All
  • Using aliasing, the previous can be shortened to
    ksgpv | ? {$_.Status -notmatch 'bound'} | ksrpv -DryRun All

Parameters

-PersistentVolumes

  • Specifies the persistent volume(s) to delete.
Type: Mtf.Kubernetes.Models.V1K8sPersistentVolume[]
Aliases:
Position: 0
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

See Remove Parameters
See Common Parameters/Non-namespaced Core Context

Inputs

  • Mtf.Kubernetes.Models.V1K8sPersistentVolume
    You can pipe persistent volume object(s) to this cmdlet.

Outputs

Mtf.Kubernetes.K8sWrapperCommon.K8sObjectDeleterResponse<k8s.Models.V1PersistentVolume>

Example

(the DryRun parameter was used here)
image

Notes

K8sShell includes the following alias for Remove-PersistentVolume:

  • ksrpv

Related