Introduction
Rancher consists of rancher-server, rancher-agent, and one or more kubernetes clusters. Among these, rancher-agent runs on the managed kubernetes and communicates with the rancher-server, sending cluster information.
The rancher-server provides a WebUI and API for managing kubernetes. The rancher-server is accessible only via HTTPS.
Installation
Single Node
There are two ways to build a single-node setup:
- Run
rancher-serverdirectly withdocker - Use
rketo enable allroleson a single node
The rke method will be described later, so here we show the docker method.
On the node where you want to run rancher-server, enter the following command:
| |
This will start a single-node rancher-server. You can access it at http://<IP Address>.
Multi Node
Use rke to build an HA environment for rancher-server.
rke (rancher k8s engine) is a command-line tool for building kubernetes clusters. Once the environment is ready, you can build a cluster with a single command.
Prepare Machines
This time, we use multipass to prepare the machines. The following commands create six virtual machines:
| |
The cloud-init.yaml file referenced in the command performs post-setup tasks after the machine boots. In this case, the following tasks are performed:
- Install
docker - Register the host machine’s
sshkey - Add the
Ubuntuuser to thedockergroup - Load required kernel modules
- Disable swap
The details are as follows:
| |
In the end, you will have six machines as follows:
| |
Create Kubernetes Environment with rke
As described in rke, download the binary and add execute permission.
Set the information and roles for the above six nodes. Many other settings are possible, but they are omitted here.
| |
Run the rke command with this yaml file as a parameter to create the Kubernetes environment.
| |
After the cluster is successfully created, two new files will be generated in addition to the original yaml file.
| |
Among these, kube_config_rancher_cluster.yaml is the configuration file for accessing the cluster. Copy it to ~/kube/config so that it can be loaded by kubectl. Now you can access the cluster.
| |
Install Rancher on Kubernetes
Follow the Rancher documentation for installation. Here, only the installation steps are extracted; for detailed settings, refer to the documentation.
Install
helmRefer to the helm homepage to install
helm.1sudo snap install helm --classicAdd the
rancherrepository tohelmThis time, select
stable.1helm repo add rancher-stable https://releases.rancher.com/server-charts/stableAdd a
namespacefor installingrancherThe namespace name must be
cattle-system.1kubectl create namespace cattle-systemInstall
cert-managerThere are other ways to create certificates, but here we let
ranchergenerate them.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17# Install the CustomResourceDefinition resources separately kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v0.15.0/cert-manager.crds.yaml # Create the namespace for cert-manager kubectl create namespace cert-manager # Add the Jetstack Helm repository helm repo add jetstack https://charts.jetstack.io # Update your local Helm chart repository cache helm repo update # Install the cert-manager Helm chart helm install \ cert-manager jetstack/cert-manager \ --namespace cert-manager \ --version v0.15.0Check the status of
cert-manager:1 2 3 4 5$ kubectl get pods --namespace cert-manager NAME READY STATUS RESTARTS AGE cert-manager-766d5c494b-9cmcq 1/1 Running 0 15s cert-manager-cainjector-6649bbb695-cfmxq 1/1 Running 0 15s cert-manager-webhook-68d464c8b-5bmjt 1/1 Running 0 15sInstall
rancher-serverInstall
rancher-serverusing Rancher-generated certificates.1 2 3helm install rancher rancher-stable/rancher \ --namespace cattle-system \ --set hostname=rancher.my.orgCheck the status of
rancher-server:1 2 3 4 5$ kubectl get pod -n cattle-system -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES rancher-756b996499-fjnt9 1/1 Running 0 35m 10.42.0.4 10.131.158.247 <none> <none> rancher-756b996499-rkn8h 1/1 Running 0 35m 10.42.2.4 10.131.158.121 <none> <none> rancher-756b996499-wmczg 1/1 Running 0 35m 10.42.5.4 10.131.158.97 <none> <none>Pods on each node are in
Runningstate, indicating successful installation.