Create kubernetes namespace in VCenter with Postman rest API

I have previously stood up VMware Cloud Foundation 4 on DellEMC VxRail 7. After deploying VCF on VxRail, I then created the NSX-T edge cluster and installed the solution for Kubernetes Workload Management. More information on this can be found at VMware: https://blogs.vmware.com/cloud-foundation/2020/03/10/delivering-kubernetes-at-cloud-scale-with-vmware-cloud-foundation-4/

Download and install Postman from https://www.postman.com/

Open Postman and create an environment profile.

Create the values you’ll use to authenticate to your setup like below.

Click Update to save the environment settings and close that window.

Next create a collection

Click ‘Add reqeust’ or right click your collection and create a new request.

Give your request a name and click Save.

Change it from a GET request to a POST request. Update the Authorization to type Basic Auth and update the username and password. In this example, we will login to the environment using the following POST request:

https://{{vc}}/rest/com/vmware/cis/session

Click Save, and click Send for this request. The response should be Status: 200 OK. and you will see the following information.

One can do Basic Auth as well as inherit auth from parent. This just means you’ll have to type in the credentials for each request you make and save. Below is similar results using Basic Auth instead of inherit auth from parent.

We are now authenticated and we can begin to list and query information to make the new namespace.

Make a new request and give it a meaningful name like Namespace list.

https://{{vc}}/api/vcenter/namespaces/instances

Click Send and you should see something like below.

Notice we have a namespace called demo1 that I previously created. Let’s see if we can get more information on this namespace. Let’s make a new query on demo1.

I’m going to make a new Get request called namespace demo1 details.

Insert the following for this Get request.

https://{{vc}}/api/vcenter/namespaces/instances/demo1

Let’s save the Get request to the collection and click Send. We should see something similar to below.

Let’s take a look in vCenter and see what is looks there. As we can tell from the rest API and from the vCenter GUI, no user has been assigned to this namespace and no storage policy has been configured.

I’m going to add a user and storage policy to this namespace and review the REST API again. First I’ll need to create a user for this namespace.

Now that I have a user, I can add it to the demo1 namespace.

I will also assign a storage policy while I’m here.

The result looks like below.

OK. Now let’s flip back over to Postman and run the namespace demo1 details Get request again. Notice we have more information, including the user demouser who has edit role and a storage policy UUID string.

Let’s create a new namespace called demo2.

This will be a post request and we will have to change the Body to raw and add the following:

{
    "cluster": "domain-c10",
    "namespace": "demo2"
}

We got an error…

We forgot to add the Content-Type key value and set to application/json. Update the Headers to include the following header.

Click Send after updating the header. After clicking Send we should see a Status 204 No Content message.

Looking back into vCenter we see the new namespace demo2.

Let’s run the Get Namespace List instances request again. We can see both namespaces listed.

https://{{vc}}/api/vcenter/namespaces/instances

We will now set the user and storage policy for demo2 namespace. I’m going to create a new request and call it set-permission-storage-policy-demo2. This will be a PUT request. We will also need to add the Headers key value Content-Type application/json.

Add the API URL: https://{{vc}}/api/vcenter/namespaces/instances/demo2

Also click on Body and set to raw format. Using the information from the output of demo1 we can add the storage policy to demo2.

{
    "access_list": [
        {
            "domain": "vsphere.local",
            "role": "EDIT",
            "subject": "demouser",
            "subject_type": "USER"
        }
    ],
    "description": "",
    "storage_specs": [
        {
            "limit": 0,
            "policy": "aa6d5a82-1c88-45da-85d3-3d74b91a5bad"
        }
    ]
}

Save and click Send.

This should return Status 204 No Content.

Let’s flip back over into vCenter and check.

We have successfully created and set a user to a namespace as well as assigned a storage policy to the namespace.

Thanks,

Reference:

https://developer.vmware.com/docs/vsphere-automation/latest/vcenter/namespaces/instances/

Published by Ben

I do stuff in the datacenter.

Leave a comment

Your email address will not be published. Required fields are marked *