Developers Notes
  • Welcome
  • Developer
    • Java
      • JUnit
        • Parameterized Test
        • Introduction to WireMock
      • Maven
        • Resource Reader and Writer
        • JUnit with Maven
        • Maven Run
        • A Quick Guide to Maven Wrapper
      • Spring
        • Autowired vs Resource
        • Spring OpenFeign 사용시 https 신뢰하는 방법
        • Aspect with Annotation
        • Spring JPA에서 Tibero를 사용하기 위한 설정
        • Spring module dependency
        • Mockito
          • Autowired @Value field in Spring with Mockito
        • SpringBoot Hybernate application.yml
        • ReflectionTestUtils
        • Spring Properties File Outside jar
        • Spring @RequestParam Annotation
        • Properties with Spring and Spring Boot
        • Passing JVM Options from Gradle bootRun
        • Securing Spring Boot API With API Key and Secret
        • Why Is Field Injection Not Recommended?
        • An Overview of Identifiers in Hibernate/JPA
      • Etcs
        • BigDecimal 사용시 주의 사항
        • static factory methods common naming conventions
        • List of Lists into a List (Stream)
        • Return null in stream
        • Logging with Lombok
        • JPA
        • Big-O Java Collections
    • MySQL
      • Active Connections on MySQL
      • MariaDB-Galera
      • FOUND_ROWS
      • MySQL Group Replication Requirements
      • Data Types Explicit Default Handling
    • C/C++
      • Autotool 사용법
      • Intruduction to GNU Autotools
      • mysql
        • C Api Flow
        • MySQL Connector/C++ 8.3 Developer Guide
      • Common vulnerabilities guide for C programmers
      • HTTP in C++
      • JSON in C++
      • How to get memory usage at runtime using C++?
      • How to get time in milliseconds using C++ on Linux?
      • Sleep Functions in C++
      • Calculate Cpu Usage on Linux as Top
    • CryptoGraphy
      • 인증 기관(CA;Certificate Authority) 구성하고 인증서 발급하기
      • KeyTool Import PrivateKey, Certificate
      • Java Keytool 사용법
      • PKCS, Public Key Cryptography Standard
      • CER/DER/CRT/CSR 형식 파일이란?
      • FIPS 140-2
      • SSL 인증서 발급
      • 사용법, tip 정리
      • OpenSSL
        • OpenSSL guide
        • Openssl RSA Private Key Encrypt
      • How to Read PEM File to Get Public and Private Keys
    • PKCS#11 API
      • PKCS#11 API-강좌1
      • PKCS#11 API-강좌2
      • PKCS#11 API-강좌3
      • PKCS#11 API-강좌4
      • PKCS#11 API-강좌5(C 언어로 된 Sample Code)
      • PKCS#11 API-강좌6(EC Key 생성 및 Signing)
    • Warehouse of PKI
    • GoLang
      • go-cshared-examples
      • Fun building shared libraries in Go
      • Golang time
      • Encoding Json
  • OpenSSL
    • OpenSSL Document
      • openssl-req
      • x509v3_config
      • Openssl Example
    • Creating a Self-Signed Certificate With OpenSSL
    • Openssl 3.x Provider
      • Writing OpenSSL Provider Skeleton
    • OpenSSL Certificate Command
  • DevOps
    • Docker
      • Environment Variables for MariaDB or MySQL Docker
      • Container Technology, Docker
      • Docker Trouble Shooting
      • Docker BuildKit
      • How to clear Docker cache and free up space on your system
    • Cloud
      • Serverless Architecture
      • AWS
        • AWS 주요 자습서 Link
        • Diagram-as-code for AWS architecture.
        • AWS Architecture icon
      • Install MariaDB Galera by Helm
      • Jenkinsfile VIM syntax highlighting
      • Cloud Development Kit for Kubernetes
    • VM
      • vagrant를 사용한 vm 설치 방법
    • Etcs
      • Logstash
        • Installing Logstash
        • Configuration Logstash Output
      • Rancher Install
      • Install ELK
      • Simpler Tool for Deploying Rancher
    • Ubuntu
      • Install SFTP Client
  • Etcs
    • Etcs
      • Useful Tools
      • Links
      • Entertainment
Powered by GitBook
On this page
  • Prerequisites
  • Note
  • Configuration
  • Configuration Files
  • Build VMs
  • Repository in Host
  • Run Rancher
  • Rancher web
  • Create New Cluster
  • Create new Cluster
  • Add Nodes to Cluster
  • Provisioning Cluster
  • References
Edit on GitHub
  1. DevOps
  2. Etcs

Rancher Install

using VirtualBox, vagrant

PreviousConfiguration Logstash OutputNextInstall ELK

Last updated 2 years ago

Prerequisites

  • At least 4GB of free RAM

Note

  • Vagrant will require plugins to create VirtualBox VMs. Install them with the following commands:

vagrant plugin install vagrant-vboxmanage
vagrant plugin install vagrant-vbguest

Configuration

my local ip address 192.168.129.106.

Configuration Files

below code is bootstrap provision script for all VMs.

bootstrap.sh
#!/bin/bash

# Enable ssh password authentication
echo "[TASK 1] Enable ssh password authentication"
sed -i 's/^PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
systemctl reload sshd

# Set Root password
echo "[TASK 2] Set root password"
echo -e "kubeadmin\nkubeadmin" | passwd root >/dev/null 2>&1


# Set Rancher
apt-get update && apt-get install -y ca-certificates curl gnupg lsb-release
mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null

apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
apt-get install -y vim net-tools

cat <<EOF > /etc/docker/daemon.json
{
    "insecure-registries" : [ "192.168.129.106:5001" ]
}
EOF

systemctl daemon-reload && systemctl restart docker

below Vagrantfile is generate 5 VMs(1 VM is for rancher, 4 VM is for k8s).

Prepare at least 4GB of memory for Rancher.

VM network's range is 192.168.56.0/24.

Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

ENV['VAGRANT_NO_PARALLEL'] = 'yes'

Vagrant.configure("2") do |config|

  config.vm.provision "shell", path: "bootstrap.sh"
  
  config.vm.define "Rancher" do |rancher|
    rancher.vm.box = "ubuntu/focal64"
    rancher.vm.hostname = "rancher.example.com"
    rancher.vm.network "private_network", ip: "192.168.56.10"
    rancher.vm.provision "shell", inline: "docker run --privileged -d --restart=unless-stopped -p 80:80 -p 443:443 rancher/rancher"

    rancher.vm.provider "virtualbox" do |rv|
        rv.name = "rancher"
        rv.memory = 6114
        rv.cpus = 2
    end
  end
  
  NodeCount = 4

  # Kubernetes Nodes
  (1..NodeCount).each do |i|
    config.vm.define "node#{i}" do |node|

      node.vm.box = "ubuntu/focal64"
      node.vm.hostname = "node#{i}.example.com"
      node.vm.network "private_network", ip: "192.168.56.11#{i}"

      node.vm.provider "virtualbox" do |v|
        v.name = "node#{i}"
        v.memory = 2048
        v.cpus = 2
      end
    end
  end

end

VM Information

hostname
cpus
memory(GiB)
IP
Purpose

rancher

2

6

192.168.56.10

Rancher

node1

2

2

192.168.56.111

k8s Master

node2

2

2

192.168.56.112

k8s Master

node3

2

2

192.168.56.113

k8s Worker

node4

2

2

192.168.56.114

k8s Worker

Empty VM List

Build VMs

build VMs. this command is take a few minutes.

vagrant up

Generated VM List

Repository in Host

In host machine, run docker registry.

sudo docker run -d -p 5001:5000 --restart always --name registry registry:2

after run registry, see below command:

curl 192.168.129.106:5001/v2/_catalog

Run Rancher

Rancher web

connect to rancher web (http:192.168.56.10) via web browser

check container id and find password

root@rancher:~# docker ps
docker CONTAINER ID   IMAGE             COMMAND           CREATED          STATUS          PORTS                                                                      NAMES
c5deb26bb7a1   rancher/rancher   "entrypoint.sh"   16 minutes ago   Up 16 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp   thirsty_shtern
root@rancher:~# 
root@rancher:~# 
root@rancher:~# 
root@rancher:~# docker logs c5de | grep Password
I0303 03:22:09.031183      32 leaderelection.go:248] attempting to acquire leader lease kube-system/cattle-controllers...
I0303 03:22:09.048776      32 leaderelection.go:258] successfully acquired lease kube-system/cattle-controllers
2023/03/03 03:22:09 [INFO] Bootstrap Password: sjq4vhgr79vdr9x6lksrhmctlrdg6wtk27z4vvkmgxhdl9rmb9pt2p
E0303 03:22:12.688027      32 gvks.go:69] failed to sync schemas: failed to sync cache for cluster.x-k8s.io/v1alpha3, Kind=Cluster
E0303 03:22:21.864510      32 request.go:977] Unexpected error when reading response body: context canceled
E0303 03:22:21.864732      32 gvks.go:69] failed to sync schemas: failed to sync cache for rke-machine.cattle.io/v1, Kind=LinodeMachineTemplate
E0303 03:22:22.405636      32 gvks.go:69] failed to sync schemas: failed to sync cache for rke-machine.cattle.io/v1, Kind=AzureMachineTemplate
E0303 03:22:23.015232      32 gvks.go:69] failed to sync schemas: failed to sync cache for rke-machine.cattle.io/v1, Kind=DigitaloceanMachine
root@rancher:~#

Set new password and continue

Rancher main page

Create New Cluster

Create new Cluster

click create new cluster and select Custom.

Custom: use existing nodes and create a cluster using RKE

set Cluster Name and scroll down.

Cloud provider is External (Out-of-tree) and Next.

Add Nodes to Cluster

Add Cluster - Custom

Click Show advanced options

Show advanced options

node role

  • node1(192.168.56.111), node2(192.168.56.112) is master(etcd, control plane).

  • node3(192.168.56.113), node4(192.168.56.114) is worker(worker)

in node1 (select only etcd, control plane and copy command)

sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run  rancher/rancher-agent:v2.7.1 --server https://192.168.56.10 --token v6wqbtdr8btnfdtvdnwcjqb6mf659nvmntnssjvg2g25fbcfxbg6s8 --ca-checksum 9120c03ac56d2be15ef71e68ce585ef06737c1457f55c8430fe5287bd3f3636a --address 192.168.56.111 --etcd --controlplane

in node2 (select only etcd, control plane and copy command)

sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run  rancher/rancher-agent:v2.7.1 --server https://192.168.56.10 --token v6wqbtdr8btnfdtvdnwcjqb6mf659nvmntnssjvg2g25fbcfxbg6s8 --ca-checksum 9120c03ac56d2be15ef71e68ce585ef06737c1457f55c8430fe5287bd3f3636a --address 192.168.56.112 --etcd --controlplane

in node3 (de-select etcd, control plane and select only worker and copy command)

sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run  rancher/rancher-agent:v2.7.1 --server https://192.168.56.10 --token v6wqbtdr8btnfdtvdnwcjqb6mf659nvmntnssjvg2g25fbcfxbg6s8 --ca-checksum 9120c03ac56d2be15ef71e68ce585ef06737c1457f55c8430fe5287bd3f3636a --address 192.168.56.113 --worker

in node4 (de-select etcd, control plane and select only worker and copy command)

sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run  rancher/rancher-agent:v2.7.1 --server https://192.168.56.10 --token v6wqbtdr8btnfdtvdnwcjqb6mf659nvmntnssjvg2g25fbcfxbg6s8 --ca-checksum 9120c03ac56d2be15ef71e68ce585ef06737c1457f55c8430fe5287bd3f3636a --address 192.168.56.114 --worker

Provisioning Cluster

provisioning cluster

about 15 minutes later. create cluster is finished.

nodes in cluster

References

VirtualBox
Vagrant
Quick StartRancher Labs
Vagrant Quick Start | Rancher Manager
Networking - VirtualBox Provider | Vagrant | HashiCorp DeveloperNetworking - VirtualBox Provider | Vagrant | HashiCorp Developer
Logo
Rancher Agent Options | Rancher Manager
Empty VM List
Generated VM List
Set new password
welcome to rancher
create cluster
set cluster name
provisioning cluster
connected machine in cluster management
provisioning cluster
Logo
Logo
Logo