Rancher CLI (rancher)
When to use
- Authenticate to a Rancher Server and work in terms of Rancher projects and clusters.
- Switch context to the project/cluster scope before running resource commands.
- Run
rancher kubectl …to execute kubectl against the cluster associated with the current Rancher context. - Inspect Rancher or Kubernetes resources via
inspect, list workloads withps, or use subcommands such asclusters,projects,namespaces,nodes,machines.
Prerequisites
rancherbinary installed (often downloaded from the Rancher UI CLI Downloads or rancher/cli releases). Documentation: Rancher CLI.- Rancher Server URL and a Bearer API token (API keys).
- After login, select a project with
rancher context switchbefore most operations; config is stored (e.g.~/.ranchcli2.jsonper upstream docs).
Patterns
- Help:
rancher --help,rancher <cmd> --help. - Login:
rancher login https://<SERVER_URL> --token <BEARER_TOKEN>. Self-signed certs may prompt to continue. - Context:
rancher context switch— pick the Rancher project (cluster + project) to target. - kubectl:
rancher kubectl get pods(and other kubectl subcommands) once context is valid. - Inspect:
rancher inspectfor Kubernetes or Rancher resources (see command help for options and resource IDs).
Core commands (orienting)
| Area | Examples |
|---|---|
| Session | rancher login, rancher token (kubeconfig token; see --help) |
| Context | rancher context switch |
| Clusters / projects | rancher clusters, rancher projects (see --help for subcommands) |
| Workloads | rancher ps, rancher namespaces |
| kubectl | rancher kubectl get pods, rancher kubectl describe … |
| Nodes / SSH | rancher nodes, rancher ssh (see --help) |
| Other | rancher inspect, rancher settings, rancher wait, rancher up |
Exact subcommands and flags depend on the CLI version; prefer rancher <cmd> --help.
Limitations
- The Rancher CLI cannot install Rancher dashboard apps or feature charts via Helm in the way the UI/charts flow does — see the official docs.
Safety
- Treat API bearer tokens like passwords; do not log or commit them.
- Operations on clusters, nodes, or workloads can be destructive — align with the user’s intent and environment (prod vs non-prod).
References
- Official documentation: Rancher CLI
- Local help:
rancher --help,rancher <cmd> --help(authoritative for your installedrancherversion)