Installing Rancher on Ubuntu

Overview

**Rancher is a powerful open-source platform designed to simplify the management of Kubernetes clusters. Whether you are running Kubernetes in a home lab or in a production environment, Rancher provides a streamlined web interface for deploying, managing and scaling your clusters. Rancher’s intuitive web interface allows you to manage multiple clusters from a single dashboard, offering features like centralized monitoring, logging and alerting. In this guide, we will walk you through the installation of RKE2 (Rancher Kubernetes Engine 2) on an Ubuntu server, which is a key component of Rancher’s ecosystem. Each step includes explanations to help you understand what's happening in the background.

Prerequisites

  • A server running Ubuntu (18.04 or higher recommended).
  • Root or sudo privileges to install and configure the system.
  • Internet access on the server to download required files.

Deploying Rancher

1. Create or Edit the Configuration Directory

RKE2 configuration files are stored under /etc/rancher/rke2. Start by creating the necessary directories if they don't already exist and prepare to configure RKE2.

sudo mkdir -p /etc/rancher/rke2

The vi command opens a file editor (you can use any editor like nano or vim if preferred). In this case, you're creating or modifying the config.yml file under /etc/rancher/rke2.

This file is used to store key configuration settings that control how RKE2 operates.

2. Add Configuration to config.yml

Now, populate the config.yml file with the following content:

token: your-cluster-token
tls-san:
  - "your.server.ip"
write-kubeconfig-mode: "0644"
node-name: "server1"

This configuration specifies important details such as:

  • token: Used for cluster communication, ensuring secure connections between nodes.
  • tls-san: The SAN (Subject Alternative Name) is an IP address or hostname that clients can use to access the API server securely.
  • write-kubeconfig-mode: Sets the permission mode for the kubeconfig file (in this case, 0644), allowing read access for non-root users.
  • node-name: Assigns a custom name to the node (in this example, it's set to server1).

You need to replace "your-cluster-token" with the actual token used for your cluster and "your.server.ip" with your server's actual IP address.

3. Install RancherD (Rancher Daemon)

Now, we need to install RancherD, which simplifies the management of Kubernetes clusters.

curl -sfl https://raw.githubusercontent.com/rancher/rancher/master/cmd/rancherd/install.sh | sh -

This command uses curl to download and execute the RancherD install script from Rancher's official GitHub repository. The options used are:

  • -s: Silent mode, which hides progress and error messages.
  • -f: Fail silently on server errors.
  • -l: Follow redirects if the URL is redirected.

RancherD sets up a Kubernetes control plane with minimal effort, automating much of the underlying configuration for you. This simplifies the management of Kubernetes clusters and helps streamline the deployment process.

4. Verify RancherD Installation

Once the script finishes running, you can verify that RancherD has been installed correctly:

rancherd --help

This command checks if the rancherd binary is available and displays its help message. Seeing the help message confirms that RancherD has been successfully installed and is ready for use.

5. Enable and Start RancherD Service

RancherD runs as a systemd service. To ensure it starts automatically and is running, execute the following commands:

systemctl enable rancherd-server.service
systemctl start rancherd-server.service
  • systemctl enable rancherd-server.service: Ensures that the RancherD server service starts automatically on boot, so it remains active across reboots.

  • systemctl start rancherd-server.service: Starts the RancherD service immediately, allowing you to begin interacting with it without having to reboot the system.

6. Monitor RancherD Service Progress

To check the service logs and monitor the progress of the RancherD service starting up:

journalctl -u rancherd-server.service -f
  • journalctl -u rancherd-server.service -f: This command allows you to view systemd logs. The -u flag filters the logs for the specified service, and the -f flag follows the log output in real-time.

Monitoring these logs is useful to identify issues during the startup process or to verify that the service has started successfully.

7. Reset Admin Password

If you need to reset the admin password for Rancher (the management interface for Kubernetes clusters), run the following command:

rancherd reset-admin

This command generates a new admin password for accessing the Rancher UI, typically via a web browser. Make sure to store the new password securely, as it will be required to manage your Kubernetes cluster.

8. Import Cluster into Rancher (Optional)

To import an existing Kubernetes cluster into Rancher, use the following command:

curl --insecure -sfL https://chrancher1p:8443/v3/import/784tws2d7p5bplhhzp8zjmgqh2hh26pcdvlwf4rdmzr4r67ccwdndr_c-9qgk7.yaml | kubectl apply -f -
  • curl --insecure -sfL https://chrancher1p:8443/v3/import/784tws2d7p5bplhhzp8zjmgqh2hh26pcdvlwf4rdmzr4r67ccwdndr_c-9qgk7.yaml: Fetches the Kubernetes YAML file needed to import the cluster. In this case, the URL points to the Rancher server running on https://chrancher1p on port 8443.

  • kubectl apply -f -: Pipes the YAML file directly into Kubernetes to apply the configuration, effectively registering the cluster with Rancher for management.

Conclusion

By following these steps, you will have a fully functional RKE2 installation on your Ubuntu server, integrated with Rancher for managing your Kubernetes clusters. Rancher’s capabilities will simplify cluster management, provide insights into cluster health, and streamline operations, making it an excellent choice for both home labs and production environments.

This page was last edited on 2024-11-06 18:46

Powered by Wiki|Docs

This page was last edited on 2024-11-06 18:46

Vivek Chandran
© 2025 Code Nomad. All rights reserved

Powered by Wiki|Docs