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-server
directly withdocker
- Use
rke
to enable allroles
on 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
ssh
key - Add the
Ubuntu
user to thedocker
group - 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
helm
Refer to the helm homepage to install
helm
.1
sudo snap install helm --classic
Add the
rancher
repository tohelm
This time, select
stable
.1
helm repo add rancher-stable https://releases.rancher.com/server-charts/stable
Add a
namespace
for installingrancher
The namespace name must be
cattle-system
.1
kubectl create namespace cattle-system
Install
cert-manager
There are other ways to create certificates, but here we let
rancher
generate 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.0
Check 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 15s
Install
rancher-server
Install
rancher-server
using Rancher-generated certificates.1 2 3
helm install rancher rancher-stable/rancher \ --namespace cattle-system \ --set hostname=rancher.my.org
Check 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
Running
state, indicating successful installation.