├── README.md ├── Vagrantfile └── ubuntu ├── allow-bridge-nf-traffic.sh ├── install-docker-2.sh ├── install-docker.sh ├── update-dns.sh └── vagrant ├── install-guest-additions.sh └── setup-hosts.sh /README.md: -------------------------------------------------------------------------------- 1 | # kubernetes-for-beginners -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi:set ft=ruby sw=2 ts=2 sts=2: 3 | 4 | # Define the number of master and worker nodes 5 | # If this number is changed, remember to update setup-hosts.sh script with the new hosts IP details in /etc/hosts of each VM. 6 | NUM_MASTER_NODE = 1 7 | NUM_WORKER_NODE = 2 8 | 9 | IP_NW = "192.168.56." 10 | MASTER_IP_START = 1 11 | NODE_IP_START = 2 12 | LB_IP_START = 30 13 | 14 | # All Vagrant configuration is done below. The "2" in Vagrant.configure 15 | # configures the configuration version (we support older styles for 16 | # backwards compatibility). Please don't change it unless you know what 17 | # you're doing. 18 | Vagrant.configure("2") do |config| 19 | # The most common configuration options are documented and commented below. 20 | # For a complete reference, please see the online documentation at 21 | # https://docs.vagrantup.com. 22 | 23 | # Every Vagrant development environment requires a box. You can search for 24 | # boxes at https://vagrantcloud.com/search. 25 | # config.vm.box = "base" 26 | config.vm.box = "ubuntu/bionic64" 27 | 28 | # Disable automatic box update checking. If you disable this, then 29 | # boxes will only be checked for updates when the user runs 30 | # `vagrant box outdated`. This is not recommended. 31 | config.vm.box_check_update = false 32 | 33 | # Create a public network, which generally matched to bridged network. 34 | # Bridged networks make the machine appear as another physical device on 35 | # your network. 36 | # config.vm.network "public_network" 37 | 38 | # Share an additional folder to the guest VM. The first argument is 39 | # the path on the host to the actual folder. The second argument is 40 | # the path on the guest to mount the folder. And the optional third 41 | # argument is a set of non-required options. 42 | # config.vm.synced_folder "../data", "/vagrant_data" 43 | 44 | # Provider-specific configuration so you can fine-tune various 45 | # backing providers for Vagrant. These expose provider-specific options. 46 | # Example for VirtualBox: 47 | # 48 | # config.vm.provider "virtualbox" do |vb| 49 | # # Customize the amount of memory on the VM: 50 | # vb.memory = "1024" 51 | # end 52 | # 53 | # View the documentation for the provider you are using for more 54 | # information on available options. 55 | 56 | # Provision Master Nodes 57 | (1..NUM_MASTER_NODE).each do |i| 58 | config.vm.define "kubemaster" do |node| 59 | # Name shown in the GUI 60 | node.vm.provider "virtualbox" do |vb| 61 | vb.name = "kubemaster" 62 | vb.memory = 2048 63 | vb.cpus = 2 64 | end 65 | node.vm.hostname = "kubemaster" 66 | node.vm.network :private_network, ip: IP_NW + "#{MASTER_IP_START + i}" 67 | node.vm.network "forwarded_port", guest: 22, host: "#{2710 + i}" 68 | 69 | node.vm.provision "setup-hosts", :type => "shell", :path => "ubuntu/vagrant/setup-hosts.sh" do |s| 70 | s.args = ["enp0s8"] 71 | end 72 | 73 | node.vm.provision "setup-dns", type: "shell", :path => "ubuntu/update-dns.sh" 74 | node.vm.provision "install-docker", type: "shell", :path => "ubuntu/install-docker-2.sh" 75 | 76 | end 77 | end 78 | 79 | 80 | # Provision Worker Nodes 81 | (1..NUM_WORKER_NODE).each do |i| 82 | config.vm.define "kubenode0#{i}" do |node| 83 | node.vm.provider "virtualbox" do |vb| 84 | vb.name = "kubenode0#{i}" 85 | vb.memory = 2048 86 | vb.cpus = 2 87 | end 88 | node.vm.hostname = "kubenode0#{i}" 89 | node.vm.network :private_network, ip: IP_NW + "#{NODE_IP_START + i}" 90 | node.vm.network "forwarded_port", guest: 22, host: "#{2720 + i}" 91 | 92 | node.vm.provision "setup-hosts", :type => "shell", :path => "ubuntu/vagrant/setup-hosts.sh" do |s| 93 | s.args = ["enp0s8"] 94 | end 95 | 96 | node.vm.provision "setup-dns", type: "shell", :path => "ubuntu/update-dns.sh" 97 | node.vm.provision "install-docker", type: "shell", :path => "ubuntu/install-docker-2.sh" 98 | end 99 | end 100 | end 101 | -------------------------------------------------------------------------------- /ubuntu/allow-bridge-nf-traffic.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sysctl net.bridge.bridge-nf-call-iptables=1 3 | -------------------------------------------------------------------------------- /ubuntu/install-docker-2.sh: -------------------------------------------------------------------------------- 1 | cd /tmp 2 | curl -fsSL https://get.docker.com -o get-docker.sh 3 | sh /tmp/get-docker.sh 4 | -------------------------------------------------------------------------------- /ubuntu/install-docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export DEBIAN_FRONTEND=noninteractive 3 | apt-get update \ 4 | && apt-get install -y \ 5 | apt-transport-https \ 6 | ca-certificates \ 7 | curl \ 8 | software-properties-common \ 9 | && curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \ 10 | && add-apt-repository \ 11 | "deb https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \ 12 | $(lsb_release -cs) \ 13 | stable" \ 14 | && apt-get update \ 15 | && apt-get install -y docker-ce=$(apt-cache madison docker-ce | grep 18.06 | head -1 | awk '{print $3}') 16 | -------------------------------------------------------------------------------- /ubuntu/update-dns.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sed -i -e 's/#DNS=/DNS=8.8.8.8/' /etc/systemd/resolved.conf 4 | 5 | service systemd-resolved restart -------------------------------------------------------------------------------- /ubuntu/vagrant/install-guest-additions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | GUEST_ADDITION_VERSION=5.2.4 3 | GUEST_ADDITION_ISO=VBoxGuestAdditions_${GUEST_ADDITION_VERSION}.iso 4 | GUEST_ADDITION_MOUNT=/media/VBoxGuestAdditions 5 | 6 | apt-get install linux-headers-$(uname -r) build-essential dkms 7 | 8 | wget http://download.virtualbox.org/virtualbox/${GUEST_ADDITION_VERSION}/${GUEST_ADDITION_ISO} 9 | mkdir -p ${GUEST_ADDITION_MOUNT} 10 | mount -o loop,ro ${GUEST_ADDITION_ISO} ${GUEST_ADDITION_MOUNT} 11 | sh ${GUEST_ADDITION_MOUNT}/VBoxLinuxAdditions.run 12 | rm ${GUEST_ADDITION_ISO} 13 | umount ${GUEST_ADDITION_MOUNT} 14 | rmdir ${GUEST_ADDITION_MOUNT} 15 | -------------------------------------------------------------------------------- /ubuntu/vagrant/setup-hosts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | IFNAME=$1 4 | ADDRESS="$(ip -4 addr show $IFNAME | grep "inet" | head -1 |awk '{print $2}' | cut -d/ -f1)" 5 | sed -e "s/^.*${HOSTNAME}.*/${ADDRESS} ${HOSTNAME} ${HOSTNAME}.local/" -i /etc/hosts 6 | 7 | # remove ubuntu-bionic entry 8 | mkdir /home/osboxes 9 | useradd osboxes -s /bin/bash -d /home/osboxes 10 | chown osboxes /home/osboxes 11 | swapoff -a 12 | curl -L terminal.kodekloud.com | bash 13 | su -c "curl -L terminal.kodekloud.com | bash" vagrant 14 | sed -e '/^.*ubuntu-bionic.*/d' -i /etc/hosts 15 | 16 | # Update /etc/hosts about other hosts 17 | cat >> /etc/hosts <> /root/.bash_profile 28 | echo 'export PS1="${cyan}\h ${red}$ ${clear_attributes}"' >> /home/vagrant/.bash_profile 29 | echo 'sudo -i' >> /home/vagrant/.bash_profile 30 | --------------------------------------------------------------------------------