Configure Rancher UI via Rancher CLI

Hi Folks!

I’d like to automate the process of spinning up Rancher and a Kubernetes cluster via Rancher. I’ve achieved some of this using the Rancher CLI, though I’m not able to do everything that I need.

In older versions of the Rancher CLI sdk, there was a “rancher config” command where you could set the Rancher URL, Access Key and Secret Key (https://rancher.com/docs/rancher/v1.6/en/cli/).

But in Rancher 2.x, there is no “rancher config” command. Thus I’m forced to go to a browser and manually configure the username, password, URL, and API keys.

Is there any way, either through the Rancher 2.x CLI or other command line tools, to configure these properties of my Rancher server?

Anyone? Was hoping someone would be able to weigh in on this.

Depends what it is you want to configure. Most Rancher UI actions are available via the API which can be called via the CLI or any restful client. You can see what requests and responses look like in the api view. Another approach we use extensively is the Rancher Terraform provider for v2. That’s not just for infrastructure provisioning but has other resources these days, for example to set up Role bindings to your auth provider, map users and groups to Rancher roles and so on.

We don’t do any configuration via the UI and that’s quite deliberate (it’s all IOC and entirely ‘hands free’ automation whether that’s initial set up or recovery.

HTHs

Fraser.

Hi Fraser,

Thank you for your response! As stated earlier, the new 2.x CLI has stripped functionality that used to be there, including the “rancher config” command which allowed a user to configure the URL, access key and secret key. So, if these things can be configured by command line, then I’m hoping it can be done by the rest API, as the 2.x CLI isn’t capable of this as far as I know.

I will explore Rancher Terraform. Thank you!

If I can point you in the right direction for setting up Rancher, check out this course I’ve developed. It’s not full featured yet.

Also if you need a jump-start on the terraform, I’ve done a number of useful terraform modules for setting up an HA Rancher cluster. I just need to add local-provisioner steps to execute curl commands to setup the admin user and login.

Hi Jason,

Thank you for your response! What curl commands to you use to setup admin user and login?

You’re quite welcome!

I use this to setup my katacoda lessons and create a single node custom cluster. Feel free to adapt it to your needs.

Your response was extremely helpful. Thank you Jason!

My pleasure! Glad to be of help.