Skip to content

Instantly share code, notes, and snippets.

@sr1890
Forked from danielepolencic/Vagrantfile
Created February 12, 2020 07:35
Show Gist options
  • Select an option

  • Save sr1890/e7df4f2cd76753f5997c00b05d80c257 to your computer and use it in GitHub Desktop.

Select an option

Save sr1890/e7df4f2cd76753f5997c00b05d80c257 to your computer and use it in GitHub Desktop.

Revisions

  1. @danielepolencic danielepolencic created this gist Aug 13, 2019.
    70 changes: 70 additions & 0 deletions Vagrantfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    BOX_IMAGE = "bento/ubuntu-18.04"
    KUBEADM_VERSION = "1.13.5-00"

    Vagrant.configure("2") do |config|
    config.vm.provider :virtualbox do |v|
    v.memory = 1024
    v.cpus = 1
    end

    config.vm.provision :shell, privileged: true, inline: $install_common_tools

    config.vm.define :master do |master|
    master.vm.box = BOX_IMAGE
    master.vm.hostname = "master"
    master.vm.network :private_network, ip: "10.0.0.10"
    master.vm.provider :virtualbox do |vb|
    vb.cpus = 2
    end
    end

    %w{worker1 worker2}.each_with_index do |name, i|
    config.vm.define name do |worker|
    worker.vm.box = BOX_IMAGE
    worker.vm.hostname = name
    worker.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id, "--memory", "512"]
    end
    worker.vm.network :private_network, ip: "10.0.0.#{i + 11}"
    worker.vm.provision :shell, privileged: false, inline: <<-SHELL
    sudo mkdir -p /etc/systemd/system/docker.service.d
    cat > /etc/systemd/system/docker.service.d/proxy.conf << "EOF"
    [Service]
    Environment="HTTP_PROXY=http://myproxy.hostname:8080"
    Environment="HTTPS_PROXY=https://myproxy.hostname:8080/"
    Environment="NO_PROXY="localhost,127.0.0.1,::1"
    EOF
    sudo systemctl daemon-reload
    sudo systemctl restart restart docker.service
    SHELL
    end
    end

    config.vm.provision "shell", inline: $install_multicast
    end


    $install_common_tools = <<-SCRIPT
    # disable swap
    swapoff -a
    sed -i '/swap/d' /etc/fstab
    # Install kubeadm, kubectl and kubelet
    export DEBIAN_FRONTEND=noninteractive
    apt-get -qq install ebtables ethtool
    apt-get -qq update
    apt-get -qq install -y docker.io apt-transport-https curl
    apt-key adv --fetch-keys https://packages.cloud.google.com/apt/doc/apt-key.gpg
    cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
    deb http://apt.kubernetes.io/ kubernetes-xenial main
    EOF
    apt-get -qq update
    apt-get -qq install -y \
    kubelet=#{KUBEADM_VERSION} \
    kubeadm=#{KUBEADM_VERSION} \
    kubectl=#{KUBEADM_VERSION}
    SCRIPT

    $install_multicast = <<-SHELL
    apt-get -qq install -y avahi-daemon libnss-mdns
    SHELL