Skip to content

Commit

Permalink
add coreos cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
vbanthia committed Nov 9, 2015
1 parent 81fc0e2 commit 3f4a833
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 1 deletion.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This repository contains setup examples of [openstf/stf](https://github.com/openstf/stf) on [various hosts](#supported-hosts) using [Vagrant](https://www.vagrantup.com/) with [VirtualBox](https://www.virtualbox.org/) provider.

## Supported Hosts
- [CoreOS](#run-stf-on-coreos-cluster)

## Requirements
- [VirtualBox](https://www.virtualbox.org/) >= 5.0.0
Expand All @@ -21,9 +22,50 @@ cd stf-setup-examples
cd ./db
vagrant up
```
Above command will
Above command will do
- Download **ubuntu/trusty64** image if image is not present (*this may take time depending on internet speed*)
- Launch Ubuntu VM and set its IP to `$rethinkdb_host_ip` configured in [Configuration File](config.rb) (**Default: 198.162.50.11**)
- Install and run rethinkdb server

You can confirm if rethinkdb is up by visiting rethinkdb admin console (https://198.162.50.11:8080 or https://RETHINKDB_HOST_IP:8080)

## Run STF on CoreOS Cluster

### Requirements
- Install [fleetctl client](https://coreos.com/fleet/docs/latest/launching-containers-fleet.html)
- On OS X, you can install it using `brew install fleetctl`.
- Make sure that rethinkdb is running by following [these instructions](#run-rethinkdb-cluster)

### Configuration
You can configure global variable present in [CoreOS Configuration File](coreos/coreos_config.rb) according to your Requirements.

### Run CoreOS Cluster

```sh
cd coreos
vagrant up
```
Above command will do
- Download **CoreOS** image if image is not present (*this may take time depending on internet speed*)
- Launch `$num_instances` configured in [CoreOS Configuration File](coreos/coreos_config.rb) instances of CoreOS VM
- You can check if all the instances are running using `vagrant global-status` command

### Configuring fleetctl
Next, we will be launching services inside CoreOS cluster using fleetctl. First we need to export a global variable
FLEETCTL_ENDPOINT. This endpoint will tell fleetctl running on host os (OS X in my case) to talk with fleet daemon running inside one of the guest OS.

```sh
export FLEETCTL_ENDPOINT=https://172.17.8.101:2379
```
Using core-01 guest OS.

Now, run `fleetctl list-machines` command, You will see something like below

```sh
MACHINE IP METADATA
6e3e7dc2... 172.17.8.101 -
9821f508... 172.17.8.102 -
ab5747a8... 172.17.8.103 -
```

Now, your CoreOS cluster is ready to deploy STF Components.
1 change: 1 addition & 0 deletions config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- mode: ruby -*-
# -*- coding: utf-8 -*-

## Ubuntun VM Private IP Address where rethinkdb will run
Expand Down
59 changes: 59 additions & 0 deletions coreos/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- mode: ruby -*-
# -*- coding: utf-8 -*-

require 'fileutils'

require './coreos_config.rb'

Vagrant.require_version '>= 1.6.0'

CLOUD_CONFIG_PATH = File.join(File.dirname(__FILE__), 'user-data')

Vagrant.configure('2') do |config|
# always use Vagrants insecure key
config.ssh.insert_key = false

config.vm.box = "coreos-%s" % $update_channel
if $image_version != 'current'
config.vm.box_version = $image_version
end
config.vm.box_url = "https://%s.release.core-os.net/amd64-usr/%s/coreos_production_vagrant.json" % [$update_channel, $image_version]

config.vm.provider :virtualbox do |v|
# On VirtualBox, we don't have guest additions or a functional vboxsf
# in CoreOS, so tell Vagrant that so it can be smarter.
v.check_guest_additions = false
v.functional_vboxsf = false
end

(1..$num_instances).each do |i|
config.vm.define vm_name = "%s-%02d" % [$instance_name_prefix, i] do |config|
config.vm.hostname = vm_name

if $enable_serial_logging
logdir = File.join(File.dirname(__FILE__), 'log')
FileUtils.mkdir_p(logdir)

serialFile = File.join(logdir, "%s-serial.txt" % vm_name)
FileUtils.touch(serialFile)
end

$forwarded_ports.each do |guest, host|
config.vm.network 'forwarded_port', guest: guest, host: host, auto_correct: true
end

config.vm.provider :virtualbox do |v|
v.name = vm_name
v.memory = $vm_memory
v.cpus = $vm_cpus
end

ip = "172.17.8.#{ i+100 }"
config.vm.network :private_network, ip: ip

# cloudconfig-init
config.vm.provision :file, :source => "#{ CLOUD_CONFIG_PATH }", :destination => '/tmp/vagrantfile-user-data'
config.vm.provision :shell, :inline => 'mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/', :privileged => true
end
end
end
40 changes: 40 additions & 0 deletions coreos/coreos_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- mode: ruby -*-
# -*- coding: utf-8 -*-

# Defaults for config options defined in CONFIG
$num_instances = 3
$instance_name_prefix = 'core'
$update_channel = 'alpha'
$image_version = 'current'
$vm_memory = 512
$vm_cpus = 1
$shared_folders = {}
$forwarded_ports = {}

# Used to fetch a new discovery token for a cluster of size $num_instances
$new_discovery_url="https://discovery.etcd.io/new?size=#{ $num_instances }"

# Automatically replace the discovery token on 'vagrant up'

if File.exists?('user-data') && (ARGV[0].eql?('up') || ARGV[0].eql?('reload'))
require 'open-uri'
require 'yaml'

token = open($new_discovery_url).read

data = YAML.load(IO.readlines('user-data')[1..-1].join)

if data.key? 'coreos' and data['coreos'].key? 'etcd2'
data['coreos']['etcd2']['discovery'] = token
end

# Fix for YAML.load() converting reboot-strategy from 'off' to `false`
if data.key? 'coreos' and data['coreos'].key? 'update' and data['coreos']['update'].key? 'reboot-strategy'
if data['coreos']['update']['reboot-strategy'] == false
data['coreos']['update']['reboot-strategy'] = 'off'
end
end

yaml = YAML.dump(data)
File.open('user-data', 'w') { |file| file.write("#cloud-config\n\n#{yaml}") }
end
40 changes: 40 additions & 0 deletions coreos/user-data
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#cloud-config

---
coreos:
etcd2:
advertise-client-urls: https://$public_ipv4:2379
initial-advertise-peer-urls: https://$private_ipv4:2380
listen-client-urls: https://0.0.0.0:2379
listen-peer-urls: https://$private_ipv4:2380
discovery: https://discovery.etcd.io/<token>
fleet:
public-ip: $public_ipv4
flannel:
interface: $public_ipv4
units:
- name: etcd2.service
command: start
- name: fleet.service
command: start
- name: flanneld.service
drop-ins:
- name: 50-network-config.conf
content: |
[Service]
ExecStartPre=/usr/bin/etcdctl set /coreos.com/network/config '{ "Network": "10.1.0.0/16" }'
command: start
- name: docker-tcp.socket
command: start
enable: true
content: |
[Unit]
Description=Docker Socket for the API

[Socket]
ListenStream=2375
Service=docker.service
BindIPv6Only=both

[Install]
WantedBy=sockets.target

0 comments on commit 3f4a833

Please sign in to comment.