github.com/enmand/kubernetes@v1.2.0-alpha.0/Vagrantfile (about)

     1  # -*- mode: ruby -*-
     2  # vi: set ft=ruby :
     3  
     4  # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
     5  VAGRANTFILE_API_VERSION = "2"
     6  
     7  # Require a recent version of vagrant otherwise some have reported errors setting host names on boxes
     8  Vagrant.require_version ">= 1.6.2"
     9  
    10  if ARGV.first == "up" && ENV['USING_KUBE_SCRIPTS'] != 'true'
    11    raise Vagrant::Errors::VagrantError.new, <<END
    12  Calling 'vagrant up' directly is not supported.  Instead, please run the following:
    13  
    14    export KUBERNETES_PROVIDER=vagrant
    15    export VAGRANT_DEFAULT_PROVIDER=providername
    16    ./cluster/kube-up.sh
    17  END
    18  end
    19  
    20  # The number of minions to provision
    21  $num_minion = (ENV['NUM_MINIONS'] || 1).to_i
    22  
    23  # ip configuration
    24  $master_ip = ENV['MASTER_IP']
    25  $minion_ip_base = ENV['MINION_IP_BASE'] || ""
    26  $minion_ips = $num_minion.times.collect { |n| $minion_ip_base + "#{n+3}" }
    27  
    28  # Determine the OS platform to use
    29  $kube_os = ENV['KUBERNETES_OS'] || "fedora"
    30  
    31  # Determine whether vagrant should use nfs to sync folders
    32  $use_nfs = ENV['KUBERNETES_VAGRANT_USE_NFS'] == 'true'
    33  
    34  # To override the vagrant provider, use (e.g.):
    35  #   KUBERNETES_PROVIDER=vagrant VAGRANT_DEFAULT_PROVIDER=... .../cluster/kube-up.sh
    36  # To override the box, use (e.g.):
    37  #   KUBERNETES_PROVIDER=vagrant KUBERNETES_BOX_NAME=... .../cluster/kube-up.sh
    38  # You can specify a box version:
    39  #   KUBERNETES_PROVIDER=vagrant KUBERNETES_BOX_NAME=... KUBERNETES_BOX_VERSION=... .../cluster/kube-up.sh
    40  # You can specify a box location:
    41  #   KUBERNETES_PROVIDER=vagrant KUBERNETES_BOX_NAME=... KUBERNETES_BOX_URL=... .../cluster/kube-up.sh
    42  # KUBERNETES_BOX_URL and KUBERNETES_BOX_VERSION will be ignored unless
    43  # KUBERNETES_BOX_NAME is set
    44  
    45  # Default OS platform to provider/box information
    46  $kube_provider_boxes = {
    47    :parallels => {
    48      'fedora' => {
    49        # :box_url and :box_version are optional (and mutually exclusive);
    50        # if :box_url is omitted the box will be retrieved by :box_name (and
    51        # :box_version if provided) from
    52        # http://atlas.hashicorp.com/boxes/search (formerly
    53        # http://vagrantcloud.com/); this allows you override :box_name with
    54        # your own value so long as you provide :box_url; for example, the
    55        # "official" name of this box is "rickard-von-essen/
    56        # opscode_fedora-20", but by providing the URL and our own name, we
    57        # make it appear as yet another provider under the "kube-fedora20"
    58        # box
    59        :box_name => 'kube-fedora20',
    60        :box_url => 'https://atlas.hashicorp.com/rickard-von-essen/boxes/opscode_fedora-20/versions/0.4.0/providers/parallels.box'
    61      }
    62    },
    63    :virtualbox => {
    64      'fedora' => {
    65        :box_name => 'kube-fedora21',
    66        :box_url => 'http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_fedora-21_chef-provisionerless.box'
    67      }
    68    },
    69    :libvirt => {
    70      'fedora' => {
    71        :box_name => 'kube-fedora20',
    72        :box_url => 'http://citozin.com/opscode_fedora-20_chef-provisionerless_libvirt.box'
    73      }
    74    },
    75    :vmware_desktop => {
    76      'fedora' => {
    77        :box_name => 'kube-fedora21',
    78        :box_url => 'http://opscode-vm-bento.s3.amazonaws.com/vagrant/vmware/opscode_fedora-21_chef-provisionerless.box'
    79      }
    80    }
    81  }
    82  
    83  # Give access to all physical cpu cores
    84  # Previously cargo-culted from here:
    85  # http://www.stefanwrobel.com/how-to-make-vagrant-performance-not-suck
    86  # Rewritten to actually determine the number of hardware cores instead of assuming
    87  # that the host has hyperthreading enabled.
    88  host = RbConfig::CONFIG['host_os']
    89  if host =~ /darwin/
    90    $vm_cpus = `sysctl -n hw.physicalcpu`.to_i
    91  elsif host =~ /linux/
    92    #This should work on most processors, however it will fail on ones without the core id field.
    93    #So far i have only seen this on a raspberry pi. which you probably don't want to run vagrant on anyhow...
    94    #But just in case we'll default to the result of nproc if we get 0 just to be safe.
    95    $vm_cpus = `cat /proc/cpuinfo | grep 'core id' | sort -u | wc -l`.to_i
    96    if $vm_cpus < 1
    97        $vm_cpus = `nproc`.to_i
    98    end
    99  else # sorry Windows folks, I can't help you
   100    $vm_cpus = 2
   101  end
   102  
   103  # Give VM 1024MB of RAM by default
   104  # In Fedora VM, tmpfs device is mapped to /tmp.  tmpfs is given 50% of RAM allocation.
   105  # When doing Salt provisioning, we copy approximately 200MB of content in /tmp before anything else happens.
   106  # This causes problems if anything else was in /tmp or the other directories that are bound to tmpfs device (i.e /run, etc.)
   107  $vm_master_mem = (ENV['KUBERNETES_MASTER_MEMORY'] || ENV['KUBERNETES_MEMORY'] || 1024).to_i
   108  $vm_minion_mem = (ENV['KUBERNETES_MINION_MEMORY'] || ENV['KUBERNETES_MEMORY'] || 1024).to_i
   109  
   110  Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
   111    def setvmboxandurl(config, provider)
   112      if ENV['KUBERNETES_BOX_NAME'] then
   113        config.vm.box = ENV['KUBERNETES_BOX_NAME']
   114  
   115        if ENV['KUBERNETES_BOX_URL'] then
   116          config.vm.box_url = ENV['KUBERNETES_BOX_URL']
   117        end
   118  
   119        if ENV['KUBERNETES_BOX_VERSION'] then
   120          config.vm.box_version = ENV['KUBERNETES_BOX_VERSION']
   121        end
   122      else
   123        config.vm.box = $kube_provider_boxes[provider][$kube_os][:box_name]
   124  
   125        if $kube_provider_boxes[provider][$kube_os][:box_url] then
   126          config.vm.box_url = $kube_provider_boxes[provider][$kube_os][:box_url]
   127        end
   128  
   129        if $kube_provider_boxes[provider][$kube_os][:box_version] then
   130          config.vm.box_version = $kube_provider_boxes[provider][$kube_os][:box_version]
   131        end
   132      end
   133    end
   134  
   135    def customize_vm(config, vm_mem)
   136  
   137      if $use_nfs then
   138        config.vm.synced_folder ".", "/vagrant", nfs: true
   139      end
   140  
   141      # Try VMWare Fusion first (see
   142      # https://docs.vagrantup.com/v2/providers/basic_usage.html)
   143      config.vm.provider :vmware_fusion do |v, override|
   144        setvmboxandurl(override, :vmware_desktop)
   145        v.vmx['memsize'] = vm_mem
   146        v.vmx['numvcpus'] = $vm_cpus
   147      end
   148  
   149      # configure libvirt provider
   150      config.vm.provider :libvirt do |v, override|
   151        setvmboxandurl(override, :libvirt)
   152        v.memory = vm_mem
   153        v.cpus = $vm_cpus
   154        v.nested = true
   155        v.volume_cache = 'none'
   156      end
   157  
   158      # Then try VMWare Workstation
   159      config.vm.provider :vmware_workstation do |v, override|
   160        setvmboxandurl(override, :vmware_desktop)
   161        v.vmx['memsize'] = vm_mem
   162        v.vmx['numvcpus'] = $vm_cpus
   163      end
   164  
   165      # Then try Parallels
   166      config.vm.provider :parallels do |v, override|
   167        setvmboxandurl(override, :parallels)
   168        v.memory = vm_mem # v.customize ['set', :id, '--memsize', vm_mem]
   169        v.cpus = $vm_cpus # v.customize ['set', :id, '--cpus', $vm_cpus]
   170  
   171        # Don't attempt to update the Parallels tools on the image (this can
   172        # be done manually if necessary)
   173        v.update_guest_tools = false # v.customize ['set', :id, '--tools-autoupdate', 'off']
   174  
   175        # Set up Parallels folder sharing to behave like VirtualBox (i.e.,
   176        # mount the current directory as /vagrant and that's it)
   177        v.customize ['set', :id, '--shf-guest', 'off']
   178        v.customize ['set', :id, '--shf-guest-automount', 'off']
   179        v.customize ['set', :id, '--shf-host', 'on']
   180  
   181        # Remove all auto-mounted "shared folders"; the result seems to
   182        # persist between runs (i.e., vagrant halt && vagrant up)
   183        override.vm.provision :shell, :inline => (%q{
   184          set -ex
   185          if [ -d /media/psf ]; then
   186            for i in /media/psf/*; do
   187              if [ -d "${i}" ]; then
   188                umount "${i}" || true
   189                rmdir -v "${i}"
   190              fi
   191            done
   192            rmdir -v /media/psf
   193          fi
   194          exit
   195        }).strip
   196      end
   197  
   198      # Don't attempt to update Virtualbox Guest Additions (requires gcc)
   199      if Vagrant.has_plugin?("vagrant-vbguest") then
   200        config.vbguest.auto_update = false
   201      end
   202      # Finally, fall back to VirtualBox
   203      config.vm.provider :virtualbox do |v, override|
   204        setvmboxandurl(override, :virtualbox)
   205        v.memory = vm_mem # v.customize ["modifyvm", :id, "--memory", vm_mem]
   206        v.cpus = $vm_cpus # v.customize ["modifyvm", :id, "--cpus", $vm_cpus]
   207  
   208        # Use faster paravirtualized networking
   209        v.customize ["modifyvm", :id, "--nictype1", "virtio"]
   210        v.customize ["modifyvm", :id, "--nictype2", "virtio"]
   211      end
   212    end
   213  
   214    # Kubernetes master
   215    config.vm.define "master" do |c|
   216      customize_vm c, $vm_master_mem
   217      if ENV['KUBE_TEMP'] then
   218        script = "#{ENV['KUBE_TEMP']}/master-start.sh"
   219        c.vm.provision "shell", run: "always", path: script
   220      end
   221      c.vm.network "private_network", ip: "#{$master_ip}"
   222    end
   223  
   224    # Kubernetes minion
   225    $num_minion.times do |n|
   226      minion_vm_name = "minion-#{n+1}"
   227      minion_prefix = ENV['INSTANCE_PREFIX'] || 'kubernetes' # must mirror default in cluster/vagrant/config-default.sh
   228      minion_hostname = "#{minion_prefix}-#{minion_vm_name}"
   229  
   230      config.vm.define minion_vm_name do |minion|
   231        customize_vm minion, $vm_minion_mem
   232  
   233        minion_ip = $minion_ips[n]
   234        if ENV['KUBE_TEMP'] then
   235          script = "#{ENV['KUBE_TEMP']}/minion-start-#{n}.sh"
   236          minion.vm.provision "shell", run: "always", path: script
   237        end
   238        minion.vm.network "private_network", ip: "#{minion_ip}"
   239      end
   240    end
   241  end