This is unreleased documentation for SUSE® Rancher Manager v2.16 (Unreleased).

Legacy SUSE Rancher Prime CLI

This page is deprecated and contains information regarding the legacy SUSE Rancher Prime CLI and migration. Refer to updated documentation for information about the current SUSE Rancher Prime CLI.

The Rancher CLI (Command Line Interface) is a unified tool that you can use to interact with Rancher. With this tool, you can operate Rancher using a command line rather than the GUI.

Download Rancher CLI

Download the binary for your operating system and architecture from the Rancher CLI releases page.

Requirements

After you download the Rancher CLI, you need to make a few configurations. Rancher CLI requires:

  • Your Rancher Server URL, which is used to connect to Rancher Server.

  • An API Bearer Token, which is used to authenticate with Rancher. For more information about obtaining a Bearer Token, see Creating an API Key.

CLI Authentication

Before you can use Rancher CLI to control your Rancher Server, you must authenticate using an API Bearer Token. Log in using the following command (replace <BEARER_TOKEN> and <SERVER_URL> with your information):

$ ./rancher login https://<SERVER_URL> --token <BEARER_TOKEN>

If Rancher Server uses a self-signed certificate, Rancher CLI prompts you to continue with the connection.

Project Selection

Before you can perform any commands, you must select a Rancher project to perform those commands against. To select a project to work on, use the command ./rancher context switch. When you enter this command, a list of available projects displays. Enter a number to choose your project.

Example: ./rancher context switch Output

User:rancher-cli-directory user$ ./rancher context switch
NUMBER    CLUSTER NAME   PROJECT ID              PROJECT NAME
1         cluster-2      c-7q96s:p-h4tmb         project-2
2         cluster-2      c-7q96s:project-j6z6d   Default
3         cluster-1      c-lchzv:p-xbpdt         project-1
4         cluster-1      c-lchzv:project-s2mch   Default
Select a Project:

After you enter a number, the console displays a message that you’ve changed projects.

INFO[0005] Setting new context to project project-1
INFO[0005] Saving config to /Users/markbishop/.ranchcli2.json

Ensure you can run rancher kubectl get pods successfully.

Commands

The following commands are available for use in Rancher CLI.

Command Result

clusters, [cluster]

Performs operations on your clusters.

context

Switches between Rancher projects. For an example, see Project Selection.

inspect [OPTIONS] [RESOURCEID RESOURCENAME]

Displays details about Kubernetes resources or Rancher resources (i.e.: projects and workloads). Specify resources by name or ID.

kubectl

Runs kubectl commands.

login, [l]

Logs into a Rancher Server. For an example, see CLI Authentication.

machines, [machine]

Performs operations on machines.

namespaces, [namespace]

Performs operations on namespaces.

nodes, [node]

Performs operations on nodes.

projects, [project]

Performs operations on projects.

ps

Displays workloads in a project.

server

Performs operations for the server.

settings, [setting]

Shows the current settings for your Rancher Server.

ssh

Connects to one of your cluster nodes using the SSH protocol.

up

Applies compose config.

wait

Waits for resources cluster, app, project, multiClusterApp.

token

Authenticates and generates new kubeconfig token.

help, [h]

Shows a list of commands or help for one command.

Migrating the Legacy CLI to the Current CLI

The current CLI operates independently from legacy configurations. Configuration files and credentials attached to the legacy CLI do not import automatically. You must authenticate to each target server by running rancher auth login once per server.

Additionally, legacy cli2.json configuration files must also be removed as they often contain plaintext credentials. To remove the legacy file from the default location, run the below command based on your operating system. If you set the legacy CLI environment variable $RANCHER_CONFIG_DIR or passed --config to the legacy CLI, remove cli2.json from that respective directory instead and update the path in the command below accordingly.

  • Linux / macOS

  • Windows

rm ~/.rancher/cli2.json
rm "$HOME\.rancher\cli2.json"

Command Output and Execution Controls

Refer to the Command Output and Execution Controls section in the current CLI documentation for details on how command outputs, safety, and execution controls are handled.

Legacy Command Mapping

Every legacy command and subcommand below maps to exactly one of: a new spelling, a replacement recipe, or a documented removal. This table is exhaustive against the full legacy command inventory.

Legacy Command New Command Mapping

login (alias l)

rancher auth login

context switch

Removed - scope is per-invocation; set the active server pointer with rancher config use-server.

context current

Removed - scope is per-invocation; rancher config status shows the current server; rancher config list-servers lists all (Active marked with *).

help (alias h)

Removed - there is no help command; add --help or -h to any command (rancher get pod --help), or run rancher schema for every command and flag.

clusters ls

rancher get clusters

clusters create

rancher create cluster <name> --import (imported), --custom (custom cluster), or --machine-config <kind/name> --cloud-credential <id> (node-driver).

clusters import

Removed - handled in clusters create.

clusters add-node

Removed - RKE1 node-driver docker-command workflow; no CAPI/RKE2 equivalent surfaced.

clusters delete (alias rm)

rancher delete provisioning-cluster <name> --apply --yes - the cluster kind itself is Deletable: false; deletion goes through the backing provisioningcluster kind.

clusters export

Removed - no export/backup command surfaced.

clusters kubeconfig (alias kf)

rancher kubeconfig --cluster <id>

clusters add-member-role

rancher grant <subject> --role <r> --cluster <c> --apply --yes

clusters delete-member-role

rancher revoke <subject> [--role <r>] --cluster <c> --apply --yes

clusters list-roles

rancher get roletemplates - filter the context field (cluster/project, and empty is admitted by the webhook): -o json + data.(context=="cluster"), or read the CONTEXT table column.

clusters list-members

rancher get clusterroletemplatebindings --cluster <id> (MEMBER/ROLE/CLUSTER table; add -o json for full objects).

machines ls

rancher get machines

namespaces ls

rancher get namespaces --cluster <c> (--project <p> lists a project’s project namespaces).

namespaces create

rancher create namespace <name> --cluster <c> [--project <p>]

namespaces delete (alias rm)

rancher delete namespace <name> --cluster <c>

namespaces move

rancher project remove-namespace <ns> --cluster <c> then rancher project add-namespace <ns> --project <new> --cluster <c> - an explicit two-step, never an implicit move.

nodes ls

rancher get nodes --cluster <c>

nodes delete (alias rm)

Removed - the node kind is Deletable: false; use kubectl delete node via rancher kubeconfig --cluster <id> + kubectl, or the Rancher UI.

projects ls

rancher get projects

projects create

rancher create project --display-name <name> --cluster <id> [--description] [--quota-limit …​] [--namespace-default-quota …​] [--container-default-resource-limit …​] - the positional argument of create project is an id, not the display name.

projects delete (alias rm)

rancher delete project <id> --cluster <c>

projects add-member-role

rancher grant <subject> --role <r> --project <p> --cluster <c> --apply --yes

projects delete-member-role

rancher revoke <subject> [--role <r>] --project <p> --cluster <c> --apply --yes

projects list-roles

rancher get roletemplates - filter the context field: -o json + data.(context=="project"), or read the CONTEXT table column.

projects list-members

rancher get projectroletemplatebindings --project <p> --cluster <c> -o json

ps

rancher get deployments --cluster <c> / rancher get pods --cluster <c> (+ rancher inspect deployment <name> --cluster <c> --namespace <ns>)

inspect <type> <id>

rancher get <kind> <name> -o json (+ rancher inspect pod/deployment/project composites).

kubectl …

One-time rancher kubeconfig --cluster <id> + native kubectl (merge recipe command below in rancher kubeconfig); auth get-token handles credentials transparently.

server current

rancher config status / rancher config list-servers (Active marked with *).

server delete

rancher config delete-server <name>

server ls

rancher config list-servers

server switch

rancher config use-server

settings ls

rancher get settings

settings get

rancher get setting <name>

settings set

rancher patch setting <name> --patch '<RFC 6902 JSON patch>' --apply

ssh <node>

Removed - RKE1/node-driver only, Norman-only; keep the legacy binary for this capability.

token

Existing Rancher-generated kubeconfigs that call rancher token --server <url> --user <user-id> keep working after a binary swap - the shim delegates to auth get-token machinery and also takes --cacerts <path>. Regenerate kubeconfigs (rancher kubeconfig --cluster <id>) to move them to auth get-token directly. Server-side token management: rancher get tokens / create token / delete token. Local exec-credential cache: auth list-tokens / auth delete-token.

token delete

rancher auth delete-token

up -f compose.yml

Removed - compose-era, no replacement.

wait <type> <id>

rancher get <kind> <name> --wait

Rancher CLI Help

Once logged into Rancher Server using the CLI, enter ./rancher --help for a list of commands.

All commands accept the --help flag, which documents each command’s usage.

Limitations

The Rancher CLI cannot be used to install dashboard apps or Rancher feature charts.