How to create and add cluster in Rancher

bayu nugraha
4 min readOct 6, 2020

I’ts for developer clusters purpose

Go to global tab, click add cluster,

step 1

Add cluster in global rancher

1. cluster name ex:legacy-app-dev, hostname in vm must be similar with cluster name, each at lvm choice no 4 for disks,

2.CNI, project network isolation disable

3.cloud provider none

4.nginx ingress=enable

5.pod secur=disable

6.docker version on nodes=require=/var/lib/docker

7.etcd snapshot=local

8.recurring etcd snapshot=no

9.authorized endpoint=disable

Step 2.

sudo su

apt update && sudo apt upgrade && reboot run this command in all nodes,

For node storage, it’s must add storage first di xen/vsphere, please refer to this step below

Requirement

curl, findmnt, grep, awk, blkid, open-iscsi and iscsid daemon running

Setup Node Storage

· Node using 2 Disk, Disk 1 storage for image and Disk 2 storage for K8s Persistent Volume

· Example Disk 2 in /dev/sdb

· Create Partition Disk 2:

fdisk /dev/sdb

Command (m for help): n

Partition type

p primary (0 primary, 0 extended, 4 free)

e extended (container for logical partitions)

Select (default p): p

Using default response p.

Partition number (1–4, default 1): 1

First sector (2048–2147483647, default 2048):

Last sector, +sectors or +size{K,M,G,T,P} (2048–2147483647, default 2147483647):

Created a new partition 1 of type ‘Linux’ and of size 1024 GiB.

Command (m for help): t

Selected partition 1

Hex code (type L to list all codes): 8e

Changed type of partition ‘Linux’ to ‘Linux LVM’.

Command (m for help): p

Disk /dev/sdb: 1 TiB, 1099511627776 bytes, 2147483648 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: dos

Disk identifier: 0x0800e1c1

Device Boot Start End Sectors Size Id Type

/dev/sdb1 2048 2147483647 2147481600 1024G 8e Linux LVM

Command (m for help): w

The partition table has been altered.

Calling ioctl() to re-read partition table.

Syncing disks.

· Format that prtition, create directory /var/kpv and mount to that directory :

mkdir /var/kpv \

&& pvcreate /dev/sdb1 \

&& vgcreate kpv-vg /dev/sdb1 \

&& lvcreate -l 100%FREE -n kpv-lv kpv-vg \

&& mkfs.ext4 /dev/kpv-vg/kpv-lv \

&& mount /dev/kpv-vg/kpv-lv /var/kpv

Physical volume “/dev/sdb1” successfully created.

Volume group “kpv-vg” successfully created

Logical volume “kpv-lv” created.

mke2fs 1.44.1 (24-Mar-2018)

Creating filesystem with 268434432 4k blocks and 67108864 inodes

Filesystem UUID: 13f21cd6–34a6–4ad1–94c7-c69bac422268

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,

102400000, 214990848

Allocating group tables: done

Writing inode tables: done

Creating journal (262144 blocks): done

Writing superblocks and filesystem accounting information: done

· Activate iscsid daemon:

systemctl enable iscsid && systemctl start iscsid

Run this command in all nodes,

apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common nfs-common open-iscsi \

&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add — \

&& add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable” \

&& apt update \

&& apt install -y docker-ce docker-ce-cli containerd.io \

&& systemctl enable iscsid && systemctl start iscsid \

&& systemctl enable rpcbind && systemctl start rpcbind

Step 3.

Edit cluster register, in the bottom column, adjust as needed,

For etcd, tick etcd and controlplane,

For worker and storage, tick worker,

Copy and run this command adjust as needed

For storage node, before we run this command, please click Show advanced options and click Add Taint, please refer to image below

Fill in this Key and Effect :

· Key = node-storage

· Effect = NoSchedule

Edit Node Label di Rancher after Node Storage has been register, click Add Label

· Key = node.longhorn.io/create-default-disk

· Value = true

Install Longhorn, go to Cluster > Default > Apps

Configuration:

· Name: longhorn

· Longhorn CSI Attacher replica count: 1 (default 3)

· Longhorn CSI Provisioner replica count: 1 (default 3)

· Default Storage Class Replica Count: 1 (default 3)

· Storage Over Provisioning Percentage: 125 (default 500)

· Default Replica Count: 1 (default 3)

· Create Default Disk on Labeled Nodes: true

· Default Data Path: /var/kpv/

· Kubernetes Taint Toleration: node-storage:NoSchedule

· Longhorn UI Service: NodePort

If disk not yet mounted, please run this command mount /dev/kpv-vg/kpv-lv /var/kpv

Go to Dashboard Longhorn > node > edit storage, delete and save, look at picture below

It would be automatically mounted,

Run this command to create bash script to automatically mount disk.

printf ‘%s\n’ ‘#!/bin/bash’ ‘exit 0’ | sudo tee -a /etc/rc.local \

&& chmod +x /etc/rc.local

sudo vi /etc/rc.local

#!/bin/bash

mount /dev/kpv-vg/kpv-lv /var/kpv

exit 0

--

--

bayu nugraha

Linux Administrator, Network Administrator, Cloud Engineer, DevOps Enthusiast, Docker, Jenkins, Git, Gitlab, Kubernetes, Ansible.