WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Automation / Mapping between vSphere Container Volume to Persistent Volume Claim (PVC) in vSphere 7.0 Update 1 using PowerCLI

Mapping between vSphere Container Volume to Persistent Volume Claim (PVC) in vSphere 7.0 Update 1 using PowerCLI

11.04.2020 by William Lam // 1 Comment

With the introduction of the vSphere Container Storage Interface (CSI) 2.1, it looks like the previous method outlined by Cormac Hogan no longer applies when looking to map between a vSphere Container Volume (CV), which is a vSphere construct to the underlying Persistent Volume Claim (PVC), which is a Kubernetes construct.


William Arroyo, a K8s Solution Engineer recently noticed this behavior change and was asking if there was a way to use PowerCLI to still perform this look up. Given I had provided the original PowerCLI snippet on Cormac's blog, I was curious myself and since I had just rebuilt my vSphere with Tanzu environment, I figured I take a quick look to see where this new information might now be placed.

I did also want to mention that you can easily find this information using the vSphere UI by just clicking on the "Details" box next to the PVC


With the latest PowerCLI 12.1 release, we have a number of Cloud Native Storage (CNS) cmdlets that we can leverage and after a quick minute of poking around, this new information can be found using the Get-CnsVolume cmdlet and using the ExtensionData property to get more detailed properties.

You can specify either the filename and/or ID to the cmdlet. In my example, the vSphere CV has label of pvc-31fc30d4-a5a2-438d-9f07-b90e0a67d3ab and we just need to pass that using the following command:

(Get-CnsVolume -Name pvc-31fc30d4-a5a2-438d-9f07-b90e0a67d3ab).ExtensionData.Metadata


The Metadata.EntityMetadata is what we are after and as you can see from the output, we can see both the PVC ID which is pvc-f8777fc1-8408-423b-8cd0-e30907512270 and even the PVC Label which is called pvc-test

If we now take a look from the Kubernetes perspective and using kubectl to retrieve our PVC using:

kubectl get pvc


We can see that the information matches.

If we wanted to get information about the the exact VMDK path, we can use the Get-VDisk cmdlet and pass in the vSphere CV

Get-VDisk | select Name, Filename

More from my site

  • How to clean up stale vSphere Container Volumes & First Class Disks?
  • How to simulate Persistent Memory (PMem) in vSphere 6.7 for educational purposes? 
  • vGhetto Lab #NotSupported Slides Posted
  • How to Create Manifest File for OVF Signing
  • VMware VSX - One plugin download site to rule them all?

Categories // Automation, Cloud Native, PowerCLI Tags // CSI, Persistent Memory, vSphere Container Volume

Comments

  1. *protectedMadhusudan says

    08/09/2024 at 2:40 pm

    Hi William,

    Thanks for the wonderful post, after referring to your articles, need your help on below, how do I get the VM Name for any PVC. I am unable to the VM Name using Get-CnsVolume. But from GUI, we can see the VM Name for mapped PVC

    Please help!!

    Get-CnsVolume | select Name, @{N='VM_Name';E={$_.ExtensionData.Metadata.EntityMetadata.EntityName}}, @{N='CapacityGB';E={[math]::round($_.CapacityMB/1024)}}, Datastore, @{N='EntityType';E={$_.Metadata.CnsEntityMetadata.EntityType}}, @{N='KubernetesClusterId';E={$_.Metadata.CnsEntityMetadata.KubernetesClusterId}}, @{N='Namespace';E={$_.Metadata.CnsEntityMetadata.Namespace}}, @{N='Label';E={$_.Metadata.CnsEntityMetadata.Label}}, @{N='Path';E={$_.ExtensionData.backingobjectdetails.BackingDiskPath}} | ft -auto

    Reply

Thanks for the comment!Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Thank Author

Author

William is Distinguished Platform Engineering Architect in the VMware Cloud Foundation (VCF) Division at Broadcom. His primary focus is helping customers and partners build, run and operate a modern Private Cloud using the VMware Cloud Foundation (VCF) platform.

Connect

  • Bluesky
  • Email
  • GitHub
  • LinkedIn
  • Mastodon
  • Reddit
  • RSS
  • Twitter
  • Vimeo

Recent

  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025
  • Quick Tip - Validating Broadcom Download Token  05/01/2025
  • Supported chipsets for the USB Network Native Driver for ESXi Fling 04/23/2025
  • vCenter Identity Federation with Authelia 04/16/2025
  • vCenter Server Identity Federation with Kanidm 04/10/2025

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2025

 

Loading Comments...