Skip to content
This repository has been archived by the owner on Aug 17, 2021. It is now read-only.

05 Use Rancher CLI

satrapu edited this page Oct 14, 2017 · 7 revisions

This page details how to use Rancher CLI against a running instance of Rancher server to perform CRUD tasks against its resources (e.g. environments, stacks,etc.).
This tool can be used to automate things, so that they may be invoked by a CI server like Jenkins.

More information can be found here and here.

Make sure you visit the examples too:

  1. Go to Rancher UI
  2. Go to menu → API → Keys
  3. Click the Add Environment button and give the API key a meaningful name
  4. Click the Create button and save the Access Key and Secret Key in a safe place for future references
  5. Go to the bottom right link "Download CLI" and click the appropriate Rancher CLI download link
  6. Unzip the downloaded file (rancher-windows-386-v0.6.3.zip) somewhere on your machine
  7. Create a new Rancher environment
    # Rancher environment is passed via --env <ENVIRONMENT_ID>
    .\rancher.exe --url http://192.168.99.101:8080 --access-key F830A6D384AF8C497D19 --secret-key NERNbgVkmVhpHEfNyMRtDd9avbQzJePkJx1dLxg7 env create newEnvironment
    
    # This command will fail with the following error message:  
    # FATA[0000] Resource type [project] is not creatable  
    # This happens since we're using an environment API key which grants access only to the resources of a specific environment.  
    # In order to create a new environment, we need to use an Account API Key!
  8. Go to menu, API → Keys and click the Add Account API Key
  9. Give the key a meaningful name and description and click the Create button
  10. Click the Create button and save the Access Key and Secret Key in a safe place for future references
  11. Re-run the command used for creating an environment and the result (the id of the newly created Rancher environment) should be printed inside the current terminal
    .\rancher.exe --url http://192.168.99.101:8080 --access-key 80805BE0AC79342F72C6 --secret-key PJygtZyy6RGcaBhKAF3cMmcU6dKMLFYfmYzvKq2S env create newEnvironment
    # 1a28
  12. As an exercise, use Rancher CLI commands for creating some of the Rancher objects you have previously created via Rancher UI
Clone this wiki locally