CoreOS is a new Linux distribution that has been rearchitected to provide features needed to run modern infrastructure stacks. The strategies and architectures that influence CoreOS allow companies like Google, Facebook and Twitter to run their services at scale with high resilience.
Just this week I tried out Vagrant Openstack plugin to spin up CoreOS instances on Elastx ops:IaaS.
Findings & issues
- Don’t destroy your Vagrant created Openstack images via Openstack. If you do, all your vagrant command will say ”Instance could not be found” and there seems to be no sane remedy. (Cleaning your ~/.vagrant.d/ files works.) The same thing has happened a few times when I do vagrant destroy where the instance is removed according to Openstack but lingers in Vagrant’s metadata.
- Be thorough with your preparations, especially ssh configurations. If you skip key name, public and private keys they’ll be generated in Openstack that then can’t be exported.
- Vagrant Openstack plugin (at least the one used in this post) is not ”official” according to Openstack foundation. More info here. Thanks Philip!
When up and running you do:
$ vagrant up --provider=openstack
$ vagrant up
after that everything is as usual. In addition you have plugin specific command line additions:
$ vagrant openstack --help Usage: vagrant openstack command Available subcommands: image-list List available images flavor-list List available flavors network-list List private networks in project floatingip-list List floating IP and floating IP pools volume-list List existing volumes
Installing the plugin
There are a few different Vagrant Openstack plugin choices like vagrant-openstack and vagrant-openstack-plugin all available to be installed. The one to use are however vagrant-openstack-provider.
$ vagrant plugin install vagrant-openstack-provider
To only run the plugin command line additions you only need a Vargantfile with Openstack connection configuration like the one below:
require 'vagrant-openstack-provider' Vagrant.configure('2') do |config| config.vm.box = 'openstack' config.vm.provider :openstack do |os| os.openstack_auth_url = 'https://ops.elastx.net:5000/v2.0/tokens' os.username = '<your username>' os.password = '<your password>' os.tenant_name = '<your tenant>' end end
In order to provision a real coreos node we need more preparations and a more complete Vagrantfile. We need:
- to generate key pair to import to Openstack for use with vagrant ssh
- username for login to image
- figure out floating IP pool to be able to connect at all to the provisioned instance
Let’s go to work:
Generate key pairs.
$ ssh-keygen -t rsa -f test.key $ ssh-keygen -y -f test.key > test.key.pub
Put your private and public key files next to your Vagrantfile.
- Import public key into Openstack. Login to Openstack and import public key under Access & Security, Key Pairs.
Figuring out IP pool might actually be easier via vagrant than through the Openstack GUI.
$ vagrant openstack floatingip-list +-------------------+ | Floating IP pools | +-------------------+ | test-net-01 | +-------------------+
So let’s look at a full sample Vagrantfile:
# \-_\- mode: ruby -_- # \# vi: set ft=ruby : require 'vagrant-openstack-provider' Vagrant.require_version ">= 1.6.0" Vagrant.configure("2") do |config| config.vm.box = "doesnt_really_matter_but_is_required" config.vm.box_version = ">= 308.0.1" config.ssh.username = '' config.ssh.private_key_path = '<path to your public ssh key>/test.key.pub' config.vm.provider :openstack do |os| os.openstack_auth_url = 'https://ops.elastx.net:5000/v2.0/tokens' os.username = '<your username>' os.password = '<your password>' os.tenant_name = '<your tenant>' os.flavor = 'm1.small' os.image = 'coreos-444.4.0' os.floating_ip_pool = 'test-net-01>' os.keypair_name = 'test' os.public_key_path = '<path to your private ssh key>/test.key' end config.vm.define vm_name = "coreos-vagrant-01" do |config| config.vm.hostname = vm_name config.vm.network :private_network, ip: "172.17.8.101" end end
You’re now good to go.
$ vagrant up --provider=openstack Bringing machine 'coreos-vagrant-01' up with 'openstack' provider... ==> coreos-vagrant-01: Finding flavor for server... ==> coreos-vagrant-01: Finding image for server... ==> coreos-vagrant-01: Launching a server with the following settings... ==> coreos-vagrant-01: -- Tenant : elastx.se ==> coreos-vagrant-01: -- Name : coreos-vagrant-01 ==> coreos-vagrant-01: -- Flavor : m1.small ==> coreos-vagrant-01: -- FlavorRef : bff4c362-1a64-4895-bcbe-89b437815934 ==> coreos-vagrant-01: -- Image : coreos-444.4.0 ==> coreos-vagrant-01: -- ImageRef : be5c10e9-80c5-4646-80bf-c0123243a4ef ==> coreos-vagrant-01: -- KeyPair : test ==> coreos-vagrant-01: Waiting for the server to be built... ==> coreos-vagrant-01: Using floating IP 126.96.36.199 ==> coreos-vagrant-01: Waiting for SSH to become available... /Users/gungus/.vagrant.d/gems/gems/vagrant-openstack-provider-0.4.1/lib/vagrant-openstack-provider/action/create_server.rb:340:in `initialize': Network is unreachable - connect(2) (Errno::ENETUNREACH)
… I ignore the error, ssh seems to work fine.
$ vagrant ssh coreos-vagrant-01 CoreOS (beta) core@coreos-vagrant-01 ~ $
That’s all for now. Feel free to send us an email at email@example.com if you have any questions. If you are interested in trying our ops:IaaS please contact support. Good luck with spinning up your coreos instances.