Skip to content

Latest commit

 

History

History
215 lines (140 loc) · 5.07 KB

rancher.md

File metadata and controls

215 lines (140 loc) · 5.07 KB

Rancher

Rancher is a dashboard UI for managing Kubernetes clusters.

You can manage both on-premise clusters, eg. installed with RKE2 kubernetes distribution, or cloud clusters like AWS EKS (I've done both).

Install Rancher

Ready to install Kustomize + Helm:

HariSekhon/Kubernetes-configs - rancher/

Readme Card

Rancher CLI

Install & authenticate doc.

Automated in DevOps-Bash-tools repo:

install_rancher_cli.sh

Create an API token at https://$RANCHER_HOST/dashboard/account.

Export environment variables for the newly created access key and secret key:

export RANCHER_HOST=...
export RANCHER_ACCESS_KEY=...
export RANCHER_SECRET_KEY=...

Authenticate the Rancher CLI:

rancher login "https://$RANCHER_HOST" --token "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY"

You'll be prompted for a project.

See the list of servers you're logged in to:

rancher server ls

Show the current cluster/project context:

rancher context current

Switch to another project in Rancher, will prompt with a list of projects:

rancher context switch

Show Rancher settings:

rancher settings ls

To get just a single setting, eg. to retrieve the rancher server version:

rancher settings get server-version

Get Rancher server version using json format to parse and extract just the value field containing the version string:

rancher settings get server-version -o json | jq -r '.Setting.value'

Command Reference

https://ranchermanager.docs.rancher.com/reference-guides/cli-with-rancher/rancher-cli#commands

rancher --help

Example usage

Tip: you can leave the ls off several of the commands to list clusters, nodes / machines, namespaces etc., but not server.

List clusters:

rancher clusters  # ls

List projects:

rancher projects ls

List servers on the currently selected cluster:

rancher nodes  # ls

List servers across all clusters and their status:

rancher machines  # ls
  • unfortunately neither of these above two commands list the RKE2 versions on each node like the UI does
  • the ID column has different contents between nodes and machines commands
  • nodes shows a State column (eg. active/cordoned) as well as two additional fields Pool and Description which may be empty, while machines shows a Phase field which contains Running/Provisioning

Show workloads in the current project:

rancher ps

Show namespaces:

rancher namespaces  # ls

Run kubectl proxied commands (slow):

rancher kubectl ...

List pods via kubectl:

rancher kubectl get pods -A

Faster is to download the kubeconfig and use direct kubectl.

Kubectl UI Shell

There is a Kubectl shell in the top right of the Rancher UI (Ctrl-` keyboard shortcut).

The problem with this shell is that it is for beginner / light use only.

You'll get 1/3 to 2/3 of a web page shell height without localized shell environment and DevOps-Bash-tools scripts to make it easier to work with Kubernetes.

It'll also cut out on you if you have a network wifi change.

Set up your local kubectl kubeconfig instead for serious usage.

Set up local kubectl - Download Rancher Kubeconfig

You can download the kubeconfig for a cluster from the UI, see the Download Kubeconfig button on the top right.

Using script in DevOps-Bash-tools, download all kubeconfigs to a directory structure with .envrc in each directory to auto-load them via a simple cd to each directory:

rancher_kube_creds.sh

Rancher Fleet

Fleet documentation.

  • CRDS + Controller to pull Kubernetes yaml from Git
  • dynamically converts to Helm charts to deploy. Is this actually idempotent like ArgoCD / FluxCD?

Has a separate chart repo to Rancher:

brew install helm
helm repo add fleet https://rancher.github.io/fleet-helm-charts/

Install Fleet:

helm -n cattle-fleet-system install --create-namespace --wait fleet-crd fleet/fleet-crd
helm -n cattle-fleet-system install --create-namespace --wait fleet fleet/fleet

Get fleet status:

kubectl -n fleet-local get fleet