Anyway to create volumes without using the BUI

We cant’ figure out how to do this using the API based on the current documentation.

Apparently the rancher 2.0 cli doesn’t have support for volumes like 1.6.

Is there any documented, reliable, working way to create persistent volumes without using the BUI?

This is a show-stopper for us.

Are you trying to create Persistent Volume claims? There is an API endpoint for it. The API is pretty self-documented.

https://<your-rancher>/v3/project/<clusterid>:<projectid>/persistentVolumeClaims/

In the browser click on the + Create button to see the syntax for it.

Now I get this 10 minutes after I think I figured it out. =)

Although I’m just using clusterid and no project id.

I’m using this url:
POST /v3/clusters/CLUSTERID/persistentvolumes/

With the following data structure (doing this in python):

    data = {
            'accessModes': [ 'ReadWriteOnce' ],
            'capacity':    { 'storage': "%dGi" % cfg['volsize'] },
            'hostPath':    { 'kind': "",
                             'path': cfg['volpath'] },
            'name': cfg['volname'],
            'nodeAffinity': {
                             'required': {
                                          'nodeSelectorTerms': [
                                                                { 'matchExpressions': [
                                                                                       { 'key': 'kubernetes.io/hostname',
                                                                                         'operator': 'In',
                                                                                         'type': '/v3/cluster/schemas/nodeSelectorRequirement',
                                                                                         'values': [ cfg['storage_node'] ]
                                                                                       }
                                                                                      ]
                                                                }
                                                               ]
                                         }
            },
            'persistentVolumeReclaimPolicy': cfg['storage_reclaim'],
            'storageClassId': cfg['storage_class'],
            'type': 'persistentVolume'
    }

I compared a volume created in the BUI vs. one created this way and they seem to match. I think I set all the keys I needed. These luns appear to be working, although waiting for our DBA’s to get into the office and confirm it works from their point of view.

What did you mean click on the “+ Create” button to see the supported syntax? I don’t see this anywhere.

You using rancher 2.0?

In your web browser, If you use the URL I gave, and enter in your host, cluster and project IDs, you will get a JSON response that shows all of the current PVCs for that project. You can also go to https://<your-rancher>/v3/cluster/<clusterid>/persistentVolumes/ to see your PVs.

On the right side, there is a box with buttons in it. Use a browser, not curl, or an API viewer.

40%20AM

1 Like

Thx for the help!

Have this working as well as submitting workloads via the API now.