Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions rancher-server-deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Rancher Server Deployment Example

This example demonstrates how to run a Rancher Server in HA mode on two Vagrant nodes including load balancer and database setup.

To run the example make sure you have the following components installed on your machine:
* VirtualBox
* Vagrant
* Oracle Java 8 (JDK or JRE)
* Infrastructor

### Step 1: run virtual nodes
Run virtual node using vagrant CLI from the directory where the Vagrantfile is located:
```
vagrant up
```

### Step 2: run the provisioning script:
From the same directory execute provisioning script with infrastructor CLI:
```
infrastructor run -f provision.groovy
```
you will be asked for a MySQL password during execution.

### Step 3: check the result
Open a web browser and go to http://192.168.55.10. You should see a rancher server welcome page.

42 changes: 42 additions & 0 deletions rancher-server-deployment/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"

config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--uartmode1", "disconnected"]
end

config.vm.define "haproxy" do |node|
node.vm.network "private_network", ip: "192.168.55.10"
node.vm.provider :virtualbox do |vb|
vb.memory = 512
vb.cpus = 1
end
end

config.vm.define "rancher-1" do |node|
node.vm.network "private_network", ip: "192.168.55.11"
node.vm.provider :virtualbox do |vb|
vb.memory = 2048
vb.cpus = 2
end
end

config.vm.define "rancher-2" do |node|
node.vm.network "private_network", ip: "192.168.55.12"
node.vm.provider :virtualbox do |vb|
vb.memory = 2048
vb.cpus = 2
end
end

config.vm.define "mysql" do |node|
node.vm.network "private_network", ip: "192.168.55.13"
node.vm.provider :virtualbox do |vb|
vb.memory = 2048
vb.cpus = 2
end
end
end
75 changes: 75 additions & 0 deletions rancher-server-deployment/provision.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
inlineInventory {
node id: 'haproxy', host: '192.168.55.10', username: 'ubuntu', keyfile: keypath('haproxy'), tags: [role: 'haproxy']
node id: 'rancher-1', host: '192.168.55.11', username: 'ubuntu', keyfile: keypath('rancher-1'), tags: [role: 'rancher']
node id: 'rancher-2', host: '192.168.55.12', username: 'ubuntu', keyfile: keypath('rancher-2'), tags: [role: 'rancher']
node id: 'mysql', host: '192.168.55.13', username: 'ubuntu', keyfile: keypath('mysql'), tags: [role: 'mysql']
}.provision {

task name: 'install docker on all hosts', parallel: 4, actions: {
shell "sudo apt update"
shell "sudo curl -Ssl https://get.docker.com | sh"
shell "sudo usermod -aG docker ubuntu"
}

def MYSQL_PASSWORD = input message: "Enter MySQL password for rancher user: ", secret: true

task name: 'run a mysql server', filter: {'role:mysql'}, actions: {
info "launching a mysql instance"
shell "docker rm -f rancher-storage || true"
shell ("docker run -p 3306:3306 " + \
"-d -e MYSQL_RANDOM_ROOT_PASSWORD=yes " + \
"-e MYSQL_PASSWORD=$MYSQL_PASSWORD " + \
"-e MYSQL_USER=rancher " + \
"-e MYSQL_DATABASE=rancher " + \
"--name rancher-storage mysql:5.6.37")

info "wating for mysql instance is up and running"
retry count: 10, delay: 2000, actions: {
assert canConnectTo {
port = 3306
host = node.host
}
}
}

task name: 'run a couple of rancher servers', parallel: 2, filter: {'role:rancher'}, actions: {
shell "docker rm -f rancher-server || true"
shell ("docker run -d -p 80:8080 " + \
"-p 9345:9345 --restart=always " + \
"--name=rancher-server rancher/server:v1.6.4 " + \
"--advertise-address ${node.host} " + \
"--advertise-http-port 80 " + \
"--db-host 192.168.55.13 " + \
"--db-port 3306 " + \
"--db-pass $MYSQL_PASSWORD " + \
"--db-user rancher " + \
"--db-name rancher")
}

task name: 'run an haproxy load balancer', filter: {'role:haproxy'}, actions: {
info "uploading haproxy configuration"
directory sudo: true, target: '/etc/haproxy', mode: 600
template(mode: 600, sudo: true) {
source = 'templates/haproxy.cfg'
target = '/etc/haproxy/haproxy.cfg'
bindings = [
port: 80,
servers: [
[name: 'rancher1', host: '192.168.55.11', port: 80],
[name: 'rancher2', host: '192.168.55.12', port: 80]
]
]
}

info "launching haproxy instance"
shell "docker run -d -v /etc/haproxy:/usr/local/etc/haproxy:ro -p 80:80 --name haproxy haproxy:1.7"

info "waiting for haproxy is up and running"
retry count: 10, delay: 5000, actions: {
def response = httpGet url: "http://$node.host/ping"
assert response.code == 200
}
}
}

def keypath(def machine) { ".vagrant/machines/$machine/virtualbox/private_key" }
13 changes: 13 additions & 0 deletions rancher-server-deployment/templates/haproxy.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
global
daemon
maxconn 256

defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms

listen http-in
bind *:$port
<% servers.each { out.println " server $it.name $it.host:$it.port maxconn 32" } %>