### View and Modify Rancher Server Settings Source: https://context7.com/rancher/cli/llms.txt Commands for viewing and modifying Rancher server settings. Supports listing all settings, getting a specific setting's details, setting a new value, and resetting a setting to its default. ```bash # List all settings rancher settings ls # Get a specific setting with details rancher settings get server-url # Set a setting value rancher settings set ui-brand "My Company" # Reset a setting to default rancher settings set ui-brand --default ``` -------------------------------- ### Execute Kubectl Commands via Rancher CLI Source: https://context7.com/rancher/cli/llms.txt Commands for executing kubectl commands within the current cluster context. The CLI handles kubeconfig generation and authentication automatically. Supports various kubectl operations like getting, describing, applying, logging, and executing commands in pods. ```bash # Run kubectl commands directly rancher kubectl get pods # Get pods in all namespaces rancher kubectl get pods --all-namespaces # Describe a specific resource rancher kubectl describe deployment my-app # Apply a manifest rancher kubectl apply -f deployment.yaml # Get logs from a pod rancher kubectl logs my-pod-xxxxx # Execute command in a pod rancher kubectl exec -it my-pod-xxxxx -- /bin/sh # Port forward to a pod rancher kubectl port-forward my-pod-xxxxx 8080:80 ``` -------------------------------- ### Add Node to Cluster with Custom Labels (Bash) Source: https://context7.com/rancher/cli/llms.txt Adds a new node to an existing cluster with specified labels. This command can be used with custom labels for environment and tier. An example output shows how to run the rancher-agent in Docker for adding nodes. ```bash # Add node with custom labels rancher cluster add-node my-cluster --worker --label env=production --label tier=frontend # Example output: # Run this command on an existing machine already running a supported version of Docker: # sudo docker run -d --privileged --restart=unless-stopped --net=host \ # -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run \ # rancher/rancher-agent:v2.8.0 --server https://rancher.example.com \ # --token xxxxx --worker # Quiet mode for scripting rancher cluster add-node my-cluster --worker -q ``` -------------------------------- ### Manage Namespaces in Project (Bash) Source: https://context7.com/rancher/cli/llms.txt Manages Kubernetes namespaces within the current project context, including listing, creating, and deleting namespaces. Supports listing all namespaces in a cluster and creating namespaces with descriptions. ```bash # List namespaces in current project rancher namespaces ls # Example output: # ID NAME STATE PROJECT DESCRIPTION # cattle-s cattle-system active c-xxxxx:p-yyyyy # default default active c-xxxxx:p-xxxxx # kube-sys kube-system active c-xxxxx:p-yyyyy # List all namespaces in the cluster rancher namespaces ls --all-namespaces # Create a new namespace rancher namespace create my-namespace # Create namespace with description rancher namespace create my-namespace --description "Application namespace" ``` -------------------------------- ### List Projects in Cluster (Bash) Source: https://context7.com/rancher/cli/llms.txt Lists all projects within the current cluster context, displaying their ID, name, state, and description. Supports JSON output and quiet mode for listing only IDs. ```bash # List all projects in current cluster rancher projects ls # Example output: # ID NAME STATE DESCRIPTION # c-xxxxx:p-xxxxx Default active Default project created for the cluster # c-xxxxx:p-yyyyy System active System project created for the cluster # Output in JSON format rancher projects ls --format json # Quiet mode - only show IDs rancher projects ls -q ``` -------------------------------- ### Manage Rancher Server Configurations Source: https://context7.com/rancher/cli/llms.txt Commands for managing multiple Rancher server configurations, allowing users to switch between different environments. Includes commands to display the current server, list all configured servers, switch servers, and delete server configurations. ```bash # Display current server rancher server current # List all configured servers rancher server ls # Switch to a different server rancher server switch staging # Delete a server configuration rancher server delete staging ``` -------------------------------- ### Manage Rancher CLI Contexts Source: https://context7.com/rancher/cli/llms.txt Commands for managing the current working context, including displaying the current context and switching between projects. Supports interactive selection or direct specification by ID or name. ```bash # Display current context rancher context current # Switch to a different project (interactive selection) rancher context switch # Switch to a specific project by ID rancher context switch c-xxxxx:p-xxxxx # Switch to a project by name rancher context switch Default ``` -------------------------------- ### Create Project in Cluster (Bash) Source: https://context7.com/rancher/cli/llms.txt Creates a new project within a cluster for organizing namespaces and resources. Supports creating projects with descriptions and specifying a target cluster. ```bash # Create a project in the current cluster rancher project create my-project # Create project with description rancher project create my-project --description "Application workloads" # Create project in a specific cluster rancher project create my-project --cluster c-xxxxx ``` -------------------------------- ### Login to Rancher Server CLI Source: https://context7.com/rancher/cli/llms.txt Authenticates the CLI with a Rancher Server using an API token. This command establishes the connection, stores credentials in the local configuration file (~/.rancher/cli2.json), and sets the initial project context. It supports specifying a context, custom CA certificates for self-signed SSL, and naming the server configuration. ```bash # Login to a Rancher server with an API token rancher login https://rancher.example.com -t token-xxxxx:secretkey # Login with a specific context (cluster:project format) rancher login https://rancher.example.com -t token-xxxxx:secretkey --context c-m-xxxxx:p-xxxxx # Login with custom CA certificate for self-signed SSL rancher login https://rancher.example.com -t token-xxxxx:secretkey --cacert /path/to/ca.crt # Login and name the server configuration rancher login https://rancher.example.com -t token-xxxxx:secretkey --name production # Example output when multiple projects exist: # NUMBER CLUSTER NAME PROJECT ID PROJECT NAME PROJECT DESCRIPTION # 1 mycluster c-xxxxx:p-xxxxx Default Default project # 2 mycluster c-xxxxx:p-yyyyy System System project # Select a Project: 1 ``` -------------------------------- ### Create Custom Cluster CLI Source: https://context7.com/rancher/cli/llms.txt Creates a new custom cluster with specified configurations. This command allows setting the Kubernetes version, network provider, and importing RKE configuration files. It also supports creating a cluster marked for import, intended for existing Kubernetes clusters. ```bash # Create a basic custom cluster rancher cluster create my-new-cluster # Create cluster with description rancher cluster create my-new-cluster --description "Production workload cluster" # Create cluster with specific Kubernetes version rancher cluster create my-new-cluster --k8s-version v1.28.4-rancher1-1 # List available Kubernetes versions rancher cluster create my-new-cluster --k8s-version list # Create cluster with specific network provider rancher cluster create my-new-cluster --network-provider calico # Create cluster from RKE config file rancher cluster create my-new-cluster --rke-config /path/to/cluster.yaml # Create a cluster marked for import (for existing k8s clusters) rancher cluster create my-import-cluster --import # Example output: # Successfully created cluster my-new-cluster ``` -------------------------------- ### List Accessible Clusters CLI Source: https://context7.com/rancher/cli/llms.txt Lists all clusters accessible to the authenticated user. The output displays the current state, provider type, resource utilization (CPU, RAM, pods), and indicates the currently focused cluster. Supports outputting in JSON, YAML, or custom formats, and a quiet mode to show only IDs. ```bash # List all clusters rancher clusters ls # Example output: # CURRENT ID STATE NAME PROVIDER NODES CPU RAM PODS # * c-xxxxx active production Rancher Kubernetes Engine 3 2.50/8 4.00/16 GB 45/330 # Output in JSON format rancher clusters ls --format json # Output in YAML format rancher clusters ls --format yaml # Custom format output rancher clusters ls --format '{{.ID}} {{.Name}} {{.Cluster.State}}' # Quiet mode - only show IDs rancher clusters ls -q ``` -------------------------------- ### Inspect Rancher Resources with Rancher CLI Source: https://context7.com/rancher/cli/llms.txt Commands for displaying detailed information about any Rancher resource in JSON or YAML format. Supports specifying resource type, custom output formats, and including links. ```bash # Inspect a cluster rancher inspect --type cluster my-cluster # Inspect a project rancher inspect --type project my-project # Inspect without specifying type (searches common types) rancher inspect my-resource # Output in YAML format with links rancher inspect --type cluster my-cluster --format yaml --links # Custom format output rancher inspect --type cluster my-cluster --format '{{.id}} {{.name}}' ``` -------------------------------- ### Establish SSH Connections to Nodes via Rancher CLI Source: https://context7.com/rancher/cli/llms.txt Commands for establishing SSH connections to nodes provisioned through Rancher. It supports connecting by name, using external IP, specifying a user, and running remote commands. ```bash # SSH into a node by name rancher ssh worker-1 # SSH using the external IP address rancher ssh -e worker-1 # SSH with a specific login user rancher ssh -l ubuntu worker-1 # SSH using user@node syntax rancher ssh ubuntu@worker-1 # SSH and run a command rancher ssh worker-1 -- uptime # SSH and run multiple commands rancher ssh worker-1 -- netstat -tlnp ``` -------------------------------- ### Import Existing Cluster CLI Source: https://context7.com/rancher/cli/llms.txt Generates the kubectl command required to import an existing Kubernetes cluster into Rancher. The command provides both a standard version and an insecure variant for clusters using self-signed certificates. A quiet mode is available to output only the necessary commands. ```bash # Get import command for a cluster rancher cluster import my-import-cluster # Example output: # Run the following command in your cluster: # kubectl apply -f https://rancher.example.com/v3/import/xxxxx.yaml # # If you get an error about 'certificate signed by unknown authority'... # kubectl apply -f https://rancher.example.com/v3/import/xxxxx.yaml --insecure-skip-tls-verify # Quiet mode - output only the commands rancher cluster import my-import-cluster -q ``` -------------------------------- ### Manage Project Member Roles (Bash) Source: https://context7.com/rancher/cli/llms.txt Manages project membership by adding or removing role bindings for users at the project level. Supports adding/deleting roles and listing available project roles and members. ```bash # Add roles to a user on the current project rancher project add-member-role user1 create-ns services-manage # Add roles on a specific project rancher project add-member-role user1 project-owner --project-id c-xxxxx:p-yyyyy # Delete roles from a user rancher project delete-member-role user1 create-ns services-manage # List all available project roles rancher project list-roles # List current project members rancher project list-members # List members for a specific project rancher project list-members --project-id c-xxxxx:p-yyyyy ``` -------------------------------- ### Generate Cluster Kubeconfig (Bash) Source: https://context7.com/rancher/cli/llms.txt Generates and outputs the kubeconfig file for a specified cluster, enabling direct kubectl access. The output can be redirected to a file for persistent storage. ```bash # Get kubeconfig for a cluster rancher cluster kubeconfig my-cluster # Save kubeconfig to a file rancher cluster kubeconfig my-cluster > ~/.kube/my-cluster-config # Example output: # apiVersion: v1 # kind: Config # clusters: # - cluster: # server: https://rancher.example.com/k8s/clusters/c-xxxxx # certificate-authority-data: LS0t... # name: my-cluster # contexts: # - context: # cluster: my-cluster # user: my-cluster # name: my-cluster # current-context: my-cluster # users: # - name: my-cluster # user: # token: kubeconfig-user-xxxxx:xxxxxxxxx ``` -------------------------------- ### List CAPI Machines with Rancher CLI Source: https://context7.com/rancher/cli/llms.txt Command for listing CAPI (Cluster API) machines within the current cluster context. This helps in managing the underlying infrastructure of your Kubernetes clusters. ```bash # Lists CAPI (Cluster API) machines in the current cluster. rancher machine ls ``` -------------------------------- ### List and Delete Nodes with Rancher CLI Source: https://context7.com/rancher/cli/llms.txt Commands for listing all nodes in the current cluster, including options for JSON output, and for deleting single or multiple nodes. These are essential for cluster maintenance. ```bash # List all nodes in current cluster rancher nodes ls # Output in JSON format rancher nodes ls --format json # Delete a node rancher node delete m-xxxxx # Delete multiple nodes rancher node rm node1 node2 ``` -------------------------------- ### Manage Namespaces with Rancher CLI Source: https://context7.com/rancher/cli/llms.txt Commands for deleting and moving namespaces between projects within Rancher. These operations modify the organizational structure of your resources. ```bash # Delete a namespace rancher namespace delete my-namespace # Move namespace to a different project rancher namespace move my-namespace c-xxxxx:p-yyyyy ``` -------------------------------- ### Manage Cluster Member Roles (Bash) Source: https://context7.com/rancher/cli/llms.txt Manages cluster membership by adding or removing role bindings for users. Supports various cluster-level roles and allows operations on specific clusters. ```bash # Add roles to a user on the current cluster rancher cluster add-member-role user1 nodes-view projects-view # Add roles on a specific cluster rancher cluster add-member-role user1 cluster-admin --cluster-id c-xxxxx # Delete roles from a user rancher cluster delete-member-role user1 nodes-view projects-view # List all available cluster roles rancher cluster list-roles # Example output: # ID NAME # cluster-admin Cluster Admin # cluster-member Cluster Member # cluster-owner Cluster Owner # nodes-view Nodes View # projects-create Projects Create # projects-view Projects View # List current cluster members rancher cluster list-members # List members with custom format rancher cluster list-members --format json ``` -------------------------------- ### Add Node to Cluster CLI Source: https://context7.com/rancher/cli/llms.txt Outputs the Docker command necessary to add a node to an existing Rancher custom cluster. This command allows specifying node roles (e.g., worker, etcd, controlplane) and labels for the new node. ```bash # Get command to add a worker node rancher cluster add-node my-cluster --worker # Add node with multiple roles rancher cluster add-node my-cluster --etcd --controlplane --worker ``` -------------------------------- ### Wait for Rancher Resource State Source: https://context7.com/rancher/cli/llms.txt Commands for waiting until a Rancher resource reaches an active state, which is particularly useful in automation scripts. Supports specifying a custom timeout in seconds. ```bash # Wait for a cluster to become active rancher wait my-cluster # Wait with custom timeout (seconds) rancher wait my-cluster --timeout 300 # Wait for a project rancher wait c-xxxxx:p-yyyyy # Example usage in script: rancher cluster create my-cluster rancher wait my-cluster --timeout 600 rancher cluster add-node my-cluster --worker ``` -------------------------------- ### Delete Cluster (Bash) Source: https://context7.com/rancher/cli/llms.txt Permanently removes one or more clusters from Rancher management. Supports deletion by name, ID, or multiple cluster identifiers. ```bash # Delete a single cluster by name rancher cluster delete my-old-cluster # Delete a cluster by ID rancher cluster rm c-xxxxx # Delete multiple clusters rancher cluster delete cluster1 cluster2 cluster3 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.