After a vSphere administrator assigns content libraries to a namespace or cluster, DevOps users can access the library and use its items to deploy VMs from VM images in the library. If the library assigned to the namespace is writable, the DevOps users with Edit permissions can also manage the library items and publish new VM images.

Note: There are no restrictions on the VM images that you use. If you want to test ready-to-use OVA images, you can download them from the Recommended Images page. Keep in mind that these images are for POC use only. In the production environment, create images with latest patches and required security settings that follow corporate security policies.

Prerequisites

As a DevOps user, make sure that you follow these requirements:

Procedure

  1. Manage the library items.
    1. Verify that the content libraries are available in the namespace.
      Note: If you want to manage library items in the library or publish VM images to the library, make sure that its writable status is true.
      kubectl get cl -n <namespace-name>
         NAME                   VSPHERENAME   TYPE    WRITABLE   STORAGETYPE   AGE
         cl-b585915ddxxxxxxxx   Test-ns-cl-1  Local   true       Datastore     3m9s
         cl-535d4b3dnxxxyyyyy   Test-ns-cl-1  Local   false      Datastore     3m9s
    2. Check the contents of the library.
      kubectl get clitem -n <namespace-name>
       NAME                 VSPHERENAME     CONTENTLIBRAYREF        TYPE   READY   AGE
       clitem-d2wnmq.....   item 1          cl-b585915ddxxxxxxxx    Ovf    True    26c
       clitem-55088d.....   item 2          cl-b585915ddxxxxxxxx    Ovf    True    26c
       clitem-xyzxyz.....   xyzxyz          cl-535d4b3dnxxxyyyyy    Ovf    True    26c
    3. Delete an image from the content library.
      Note: You can delete an item only from the library that is writable and if you have Edit permissions or permissions of a higher level.
      Once you delete the clitem, the corresponding vmi resource is also deleted.
      kubectl delete clitem clitem-55088d.....
       NAME                 VSPHERENAME     CONTENTLIBRAYREF        TYPE   READY   AGE
       clitem-d2wnmq.....   item 1          cl-b585915ddxxxxxxxx    Ovf    True    26c
       clitem-xyzxyz.....   xyzxyz          cl-535d4b3dnxxxyyyyy    Ovf    True    26c
    4. Get image details.
      kubectl get vmi -n <namespace-name>
       NAME              PROVIDER-NAME      CONTENT-LIBRAY-NAME    IMAGE-NAME VERSION   OS-TYPE        FORMAT   AGE
       vmi-d2wnmq.....   clitem-d2wnmq..... cl-b585915ddxxxxxxxx   item 1               ubuntu64guest  ovf      26c
       vmi-55088d.....   clitem-55088d..... cl-b585915ddxxxxxxxx   item 2               otherguest     ovf      26c
  2. Publish an image to the content library.
    1. Create a yaml file to deploy a source VM.
      Make sure that the imageName in the VirtualMachine spec references one of the VM images from the content library.
      For example, source-vm.yaml.
      apiVersion: vmoperator.vmware.com/v1alpha2
      kind: VirtualMachine
      metadata:
        name: source-vm
        namespace: test-publish-ns
      spec:
        className: best-effort-small
        storageClass: wcpglobal-storage-profile
        imageName: vmi-d2wnmq.....
        powerState: poweredOn
        vmMetadata:
          transport: CloudInit
    2. Obtain information about the deployed VM and connect to the VM to make sure it's running.
      You see the output similar to the following.
      kubectl get vm -n <namespace-name>
      NAME        POWER-STATE   CLASS             IMAGE           PRIMARY-IP        AGE
      source-vm   poweredOn     best-effort-small vmi-d2wnmq..... 192.168.000.00   9m32s
    3. Create a publish request for a new target image.
      For example, vmpub.yaml. In the request, indicate the name of the source VM and target content library where you want to publish your image. Make sure that the library is writable.
      apiVersion: vmoperator.vmware.com/v1alpha2
      kind: VirtualMachinePublishRequest
      metadata:
        name: vmpub-1
        namespace: test-publish-ns
      spec:
        source:
          apiVersion: vmoperator.vmware.com/v1alpha2
          kind: VirtualMachine
          name: source-vm # If empty, the name of this VirtualMachinePublishRequest will be used as the source VM name ("vmpub-1" in this example).
        target:
          item:
            name: publish-image-1 # If empty, the target item name is <source-vm-name>-image by default
          location:
            apiVersion: imageregistry.vmware.com/v1alpha2
            kind: ContentLibrary
            name: cl-b585915ddxxxxxxxx
      
    4. Describe the publish request.
      Make sure that the publish request in a Ready status with the ImageName set.
      kubectl describe vmpub vmpub-1 -n <namespace-name>
      ==================
      Status:
        imageName: vmi-12980cddd...
        ready: true
      ==================
    5. Verify that the new image is added to the content library after the publish request is complete.
      kubectl get vmi
       NAME              PROVIDER-NAME      CONTENT-LIBRAY-NAME    IMAGE-NAME      VERSION   OS-TYPE        FORMAT   AGE
       vmi-12980cddd..   clitem-12980cddd.. cl-b585915ddxxxxxxxx   publish-image-1           ubuntu64guest  ovf      7m12s
       vmi-d2wnmq.....   clitem-d2wnmq..... cl-b585915ddxxxxxxxx   item 1                    ubuntu64guest  ovf      26m
       vmi-55088d.....   clitem-55088d..... cl-b585915ddxxxxxxxx   item 2                    otherguest     ovf      26m
    You can use this new image to deploy a new VM.