Skip to content

Instantly share code, notes, and snippets.

@v1k0d3n
Last active September 3, 2016 19:09
Show Gist options
  • Save v1k0d3n/d2500d9bccdaec275fa3f505fa13359c to your computer and use it in GitHub Desktop.
Save v1k0d3n/d2500d9bccdaec275fa3f505fa13359c to your computer and use it in GitHub Desktop.
# Kubernetes Details: Instances
$kube_version = "ubuntu/trusty64"
$kube_memory = 1024
$kube_vcpus = 1
$kube_count = 3
$git_commit = "6a7308d"
$subnet = "192.168.236"
$forwarded_ports = {}
# Ansible Declarations:
$number_etcd = "kube[1:2]"
$number_master = "kube[1:2]"
$number_worker = "kube[1:3]"
# Virtualbox leave / Openstack change to OS default username:
$ssh_user = "ubuntu"
$ssh_keypath = "~/.ssh/your_ssh_keypair"
$ssh_port = 22
# Ansible Details:
$ansible_limit = "all"
$ansible_playbook = "projects/kargo/vagrant-cluster.yml"
$ansible_inventory = ".vagrant/provisioners/ansible/inventory_override"
# Openstack Authentication Information:
$os_auth_url = "http://your.openstack.url:5000/v2.0"
$os_username = "user"
$os_password = "password"
$os_tenant = "tenant"
# Openstack Instance Information:
$os_flavor = "m1.small"
$os_image = "ubuntu-trusty-14.04"
$os_floatnet = "public"
$os_fixednet = ['vagrant-net']
$os_keypair = "your_ssh_keypair"
$os_secgroups = ["default"]
# -*- mode: ruby -*-
# vi: set ft=ruby :
# NOTE: Variable overrides are in ./config.rb
require "yaml"
require "vagrant-openstack-provider"
require "fileutils"
# Use a variable file for overrides:
CONFIG = File.expand_path("config.rb")
if File.exist?(CONFIG)
require CONFIG
end
# Force best practices for this environment:
if $kube_memory < 512
puts "WARNING: Your machine should have at least 512 MB of memory"
end
# Install any Required Plugins
missing_plugins_installed = false
required_plugins = %w(vagrant-env vagrant-git vagrant-openstack-provider)
required_plugins.each do |plugin|
if !Vagrant.has_plugin? plugin
system "vagrant plugin install #{plugin}"
missing_plugins_installed = true
end
end
# If any plugins were missing and have been installed, re-run vagrant
if missing_plugins_installed
exec "vagrant #{ARGV.join(" ")}"
end
# Vagrantfile API/sytax version. Don’t touch unless you know what you’re doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# UNCOMMENT FOLLOWING LINES FOR OPENSTACK PROVIDER:
config.ssh.username = $ssh_user
config.ssh.private_key_path = $ssh_keypath
# Guest Definitions:
# ------------------------
#
# START: Kube Definition(s)
(1..$kube_count).each do |kb|
ip = "#{$subnet}.#{kb}"
config.vm.define vm_name = "kube#{kb}" do |kube|
kube.vm.box = $kube_version
kube.vm.hostname = "kube#{kb}"
# NETWORK-SETTINGS: eth1 configured in using the $subnet variable:
kube.vm.network "private_network", ip: "#{$subnet}.#{kb}", auto_config: false
# kube.vm.network "public_network", ip: "#{$subnet}.#{kb}"
if $expose_docker_tcp
kube.vm.network "forwarded_port", guest: 2375, host: ($expose_docker_tcp + i - 1), auto_correct: true
end
$forwarded_ports.each do |guest, host|
kube.vm.network "forwarded_port", guest: guest, host: host, auto_correct: true
end
# Openstack Provider (Optional --provider=openstack):
kube.vm.provider "virtualbox" do |vb|
vb.name = "kube#{kb}"
vb.customize ["modifyvm", :id, "--memory", $kube_memory]
vb.customize ["modifyvm", :id, "--cpus", $kube_vcpus]
end
# Openstack Provider (Optional --provider=openstack):
kube.vm.provider "openstack" do |os|
# Openstack Authentication Information:
os.openstack_auth_url = $os_auth_url
os.username = $os_username
os.password = $os_password
os.tenant_name = $os_tenant
# Openstack Instance Information:
os.server_name = "kube#{kb}"
os.flavor = $os_flavor
os.image = $os_image
os.floating_ip_pool = $os_floatnet
os.networks = $os_fixednet
os.keypair_name = $os_keypair
os.security_groups = $os_secgroups
end
# We only want Ansible to run after after all servers are deployed:
if kb == $kube_count
kube.vm.provision :ansible do |ansible|
ansible.sudo = true
ansible.limit = $ansible_limit
ansible.playbook = $ansible_playbook
ansible.host_key_checking = false
ansible.groups = {
# The first three nodes should be etcd servers
"etcd" => [$number_etcd],
# The first two nodes should be masters
"kube-master" => [$number_master],
# all nodes should be kube nodes
"kube-node" => [$number_worker],
"k8s-cluster:children" => ["kube-master", "kube-node"],
}
# Additional Ansible tools for debugging:
#ansible.inventory_path = $ansible_inventory
#ansible.verbose = "-vvvv"
#ansible.raw_ssh_args = ANSIBLE_RAW_SSH_ARGS
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment