├── docs ├── INFORMATION.md └── kubeadm │ ├── k8s-kubeadm-base.md │ ├── k8s-kubeadm-pre-cni.md │ └── k8s-kubeadm-calico-full-cluster-bootstrap.md ├── .gitignore ├── .DS_Store ├── logos ├── kuberverse-logo-h-4096x2304.png ├── kuberverse-logo-v-4096x4096.png ├── kuberverse-logo-h-4096x2304-transp.png ├── kuberverse-logo-v-1920x1920-transp.png ├── kuberverse-logo-v-4096x4096-transp.png ├── kuberverse-logo-4096x4096-square-full.png ├── kuberverse-logo-4096x4096-square-middle.png ├── kuberverse-logo-4096x4096-square-full-transp.png └── kuberverse-logo-4096x4096-square-middle-transp.png ├── Vagrantfile ├── labs ├── kv-k8s-cluster │ ├── worker.sh │ ├── README.md │ ├── master.sh │ ├── common.sh │ └── Vagrantfile ├── kv-k8s-cluster-ha │ ├── worker.sh │ ├── README.md │ ├── scaler.sh │ ├── master.sh │ ├── scaler-docker.sh │ ├── lib │ │ └── kvlab.rb │ ├── common.sh │ └── Vagrantfile ├── k8s-kubeadm-base │ └── Vagrantfile ├── k8s-kubeadm-pre-cni │ └── Vagrantfile └── k8s-kubeadm-calico-full-cluster-bootstrap │ └── Vagrantfile ├── lib ├── sh │ ├── worker.sh │ ├── scaler.sh │ ├── master.sh │ ├── scaler-docker.sh │ └── common.sh └── rb │ ├── kvshell.rb │ ├── kvtools.rb │ └── kvlab.rb ├── LEIAME.md ├── kvlab.conf.rb ├── README.md └── LICENSE /docs/INFORMATION.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant/ 2 | -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arturscheiner/kuberverse/HEAD/.DS_Store -------------------------------------------------------------------------------- /logos/kuberverse-logo-h-4096x2304.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arturscheiner/kuberverse/HEAD/logos/kuberverse-logo-h-4096x2304.png -------------------------------------------------------------------------------- /logos/kuberverse-logo-v-4096x4096.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arturscheiner/kuberverse/HEAD/logos/kuberverse-logo-v-4096x4096.png -------------------------------------------------------------------------------- /logos/kuberverse-logo-h-4096x2304-transp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arturscheiner/kuberverse/HEAD/logos/kuberverse-logo-h-4096x2304-transp.png -------------------------------------------------------------------------------- /logos/kuberverse-logo-v-1920x1920-transp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arturscheiner/kuberverse/HEAD/logos/kuberverse-logo-v-1920x1920-transp.png -------------------------------------------------------------------------------- /logos/kuberverse-logo-v-4096x4096-transp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arturscheiner/kuberverse/HEAD/logos/kuberverse-logo-v-4096x4096-transp.png -------------------------------------------------------------------------------- /logos/kuberverse-logo-4096x4096-square-full.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arturscheiner/kuberverse/HEAD/logos/kuberverse-logo-4096x4096-square-full.png -------------------------------------------------------------------------------- /logos/kuberverse-logo-4096x4096-square-middle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arturscheiner/kuberverse/HEAD/logos/kuberverse-logo-4096x4096-square-middle.png -------------------------------------------------------------------------------- /logos/kuberverse-logo-4096x4096-square-full-transp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arturscheiner/kuberverse/HEAD/logos/kuberverse-logo-4096x4096-square-full-transp.png -------------------------------------------------------------------------------- /logos/kuberverse-logo-4096x4096-square-middle-transp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arturscheiner/kuberverse/HEAD/logos/kuberverse-logo-4096x4096-square-middle-transp.png -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # kuberverse kubernetes cluster lab 2 | # version: 0.5.0 3 | # description: this Vagrantfile creates a cluster with masters and workers 4 | # created by Artur Scheiner - artur.scheiner@gmail.com 5 | 6 | require_relative 'kvlab.conf.rb' 7 | require_relative 'lib/rb/kvlab.rb' 8 | 9 | Vagrant.configure("2") do |config| 10 | 11 | kvlab = KvLab.new() 12 | 13 | if MASTER_COUNT >= 2 14 | kvlab.createScaler(config) 15 | end 16 | 17 | kvlab.createMaster(config) 18 | kvlab.createWorker(config) 19 | 20 | config.vm.provision "shell", 21 | run: "always", 22 | inline: "swapoff -a" 23 | end 24 | -------------------------------------------------------------------------------- /labs/kv-k8s-cluster/worker.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # kuberverse k8s lab provisioner 3 | # type: kubeadm-calico-full-cluster-bootstrap 4 | # created by Artur Scheiner - artur.scheiner@gmail.com 5 | 6 | KVMSG=$1 7 | NODE=$2 8 | NODE_HOST_IP=20+$NODE 9 | POD_CIDR=$3 10 | API_ADV_ADDRESS=$4 11 | 12 | echo "********** $KVMSG" 13 | echo "********** $KVMSG" 14 | echo "********** $KVMSG ->> Joining Kubernetes Cluster" 15 | echo "********** $KVMSG ->> Worker Node $NODE" 16 | echo "********** $KVMSG ->> kv-worker-$NODE" 17 | 18 | # Extract and execute the kubeadm join command from the exported file 19 | $(cat /vagrant/kubeadm-init.out | grep -A 2 "kubeadm join" | sed -e 's/^[ \t]*//' | tr '\n' ' ' | sed -e 's/ \\ / /g') 20 | echo KUBELET_EXTRA_ARGS=--node-ip=10.8.8.$NODE_HOST_IP > /etc/default/kubelet -------------------------------------------------------------------------------- /labs/kv-k8s-cluster-ha/worker.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # kuberverse kubernetes cluster lab 3 | # version: 0.1.0-alpha 4 | # description: this is the workers script file 5 | # type: kubeadm-calico-full-cluster-bootstrap 6 | # created by Artur Scheiner - artur.scheiner@gmail.com 7 | 8 | KVMSG=$1 9 | NODE=$2 10 | WORKER_IP=$3 11 | MASTER_TYPE=$4 12 | 13 | if [ $MASTER_TYPE = "single" ]; then 14 | $(cat /vagrant/kubeadm-init.out | grep -A 2 "kubeadm join" | sed -e 's/^[ \t]*//' | tr '\n' ' ' | sed -e 's/ \\ / /g') 15 | else 16 | $(cat /vagrant/workers-join.out | sed -e 's/^[ \t]*//' | tr '\n' ' ' | sed -e 's/ \\ / /g') 17 | fi 18 | 19 | if grep -E "KUBELET_EXTRA_ARGS=" /etc/default/kubelet ; then 20 | sed -i "s+KUBELET_EXTRA_ARGS=\"+KUBELET_EXTRA_ARGS=\"--node-ip=$WORKER_IP +g" /etc/default/kubelet 21 | else 22 | echo KUBELET_EXTRA_ARGS=--node-ip=$WORKER_IP >> /etc/default/kubelet 23 | fi 24 | 25 | systemctl restart kubelet 26 | -------------------------------------------------------------------------------- /lib/sh/worker.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # kuberverse kubernetes cluster lab 3 | # version: 0.5.0 4 | # description: this is the workers script file 5 | # created by Artur Scheiner - artur.scheiner@gmail.com 6 | 7 | #if [ $KV_MASTER_TYPE = "single" ]; then 8 | # $(cat /vagrant/kubeadm-init.out | grep -A 2 "kubeadm join" | sed -e 's/^[ \t]*//' | tr '\n' ' ' | sed -e 's/ \\ / /g') 9 | #else 10 | $(cat /vagrant/.kv/workers-join | sed -e 's/^[ \t]*//' | tr '\n' ' ' | sed -e 's/ \\ / /g') 11 | #fi 12 | 13 | if grep -E "KUBELET_EXTRA_ARGS=" /etc/default/kubelet ; then 14 | sed -i "s+KUBELET_EXTRA_ARGS=\"+KUBELET_EXTRA_ARGS=\"--node-ip=$KV_THIS_IP +g" /etc/default/kubelet 15 | else 16 | echo KUBELET_EXTRA_ARGS=--node-ip=$KV_THIS_IP >> /etc/default/kubelet 17 | fi 18 | 19 | mkdir -p /home/vagrant/.kube /root/.kube 20 | cp -i /vagrant/.kv/kube-config /home/vagrant/.kube/config 21 | cp -i /vagrant/.kv/kube-config /root/.kube/config 22 | chown vagrant:vagrant /home/vagrant/.kube/config 23 | 24 | systemctl restart kubelet 25 | -------------------------------------------------------------------------------- /labs/kv-k8s-cluster-ha/README.md: -------------------------------------------------------------------------------- 1 | #### Kuberverse HA Cluster 2 | 3 | This is the **full lab** created for those who wants to install a k8s cluster using the kubeadm method but wish to optimize even more the time. This template installs and bootstraps automatically a full cluster with the **calico** networking interface. This is the full cluster build that I have created to optimize your study time. 4 | 5 | ### Latest Changes ### 6 | 7 | 28/10/2021 - This lab was updated to run the latest version of Kubernetes 1.22.3. The cluster runs over Ubuntu 18.04.6 and the container runtime Docker 18.9.1. All links and references where updated to reflect the actual changes. 8 | 9 | ##### Use it if: ##### 10 | 11 | - you want a very, very, very easy way to bring a cluster up and running in a couple of minutes; 12 | - you have studied a lot, the steps involved in the k8s cluster configuration using the kubeadm method; 13 | - you´re curious and wish to put your hands on a cluster without being involved in the configuration steps but wants to play with _kubectl_; 14 | - you´re tired to install and configure all the components necessary to bring a cluster up; 15 | - you wish to get a coffe while the hard work is done automatically for you; 16 | 17 | ### How to Use ### 18 | -------------------------------------------------------------------------------- /labs/kv-k8s-cluster/README.md: -------------------------------------------------------------------------------- 1 | #### k8s-kubeadm-calico-full-cluster-bootstrap - The kubeadm Full Lab with Calico Flavor 2 | 3 | This is the **full lab** created for those who wants to install a k8s cluster using the kubeadm method but wish to optimize even more the time. This template installs and bootstraps automatically a full cluster with the **calico** networking interface. This is the full cluster build that I have created to optimize your study time. 4 | 5 | ### Latest Changes ### 6 | 7 | This lab was recently updated to run the latest version of Kubernetes 1.16. The cluster runs over Ubuntu 16.04 and the container runtime chosen was Docker 18.09. All links and references where updated to reflect the actual changes. The overall experience was maintained from the previous version, but the script was divided into 4 different pieces: 8 | 9 | - New Vagrantfile 10 | - New common.sh 11 | - New master.sh 12 | - New worker.sh 13 | 14 | ##### Use it if: ##### 15 | 16 | - you want a very, very, very easy way to bring a cluster up and running in a couple of minutes; 17 | - you have studied a lot, the steps involved in the k8s cluster configuration using the kubeadm method; 18 | - you´re curious and wish to put your hands on a cluster without being involved in the configuration steps but wants to play with _kubectl_; 19 | - you´re tired to install and configure all the components necessary to bring a cluster up; 20 | - you wish to get a coffe while the hard work is done automatically for you; 21 | -------------------------------------------------------------------------------- /labs/k8s-kubeadm-base/Vagrantfile: -------------------------------------------------------------------------------- 1 | # kuberverse k8s lab provisioner 2 | # type: kubeadm-base 3 | # created by Artur Scheiner - artur.scheiner@gmail.com 4 | 5 | BOX_IMAGE = "bento/ubuntu-16.04" 6 | MASTER_COUNT = 1 7 | WORKER_COUNT = 2 8 | 9 | Vagrant.configure("2") do |config| 10 | 11 | (0..MASTER_COUNT-1).each do |i| 12 | config.vm.define "kv-master-#{i}" do |subconfig| 13 | subconfig.vm.box = BOX_IMAGE 14 | subconfig.vm.hostname = "kv-master-#{i}" 15 | subconfig.vm.network :private_network, ip: "10.8.8.#{i + 10}" 16 | subconfig.vm.provider :virtualbox do |vb| 17 | vb.customize ["modifyvm", :id, "--cpus", 2] 18 | vb.memory = 2048 19 | end 20 | end 21 | end 22 | 23 | (0..WORKER_COUNT-1).each do |i| 24 | config.vm.define "kv-worker-#{i}" do |subconfig| 25 | subconfig.vm.box = BOX_IMAGE 26 | subconfig.vm.hostname = "kv-worker-#{i}" 27 | subconfig.vm.network :private_network, ip: "10.8.8.#{i + 20}" 28 | subconfig.vm.provider :virtualbox do |vb| 29 | vb.customize ["modifyvm", :id, "--cpus", 2] 30 | vb.memory = 1024 31 | end 32 | end 33 | end 34 | 35 | # Install avahi on all machines 36 | config.vm.provision "shell", inline: <<-SHELL 37 | apt-get update 38 | apt-get upgrade -y 39 | apt-get install -y avahi-daemon libnss-mdns traceroute htop httpie 40 | SHELL 41 | 42 | config.vm.provision "shell", 43 | run: "always", 44 | inline: "swapoff -a" 45 | 46 | end 47 | -------------------------------------------------------------------------------- /LEIAME.md: -------------------------------------------------------------------------------- 1 | # kuberverse 2 | This is the kuberverse youtube channel repos 3 | 4 | Here you will find the files used in our labs. Please, be free to try it out! 5 | 6 | At this moment we have 3 labs available for you to test out: 7 | 8 | - k8s-kubeadm-base 9 | this is the base lab from those who wants to install a cluster using the kubeadm method, from the base OS image (ubuntu 16.04) 10 | Follow the directory to get directions about how to use this template 11 | Use it if you're new to kubernetes and wish to start your first cluster running all the commands needed to create your environment. 12 | 13 | - k8s-kubeadm-pre-cni 14 | this is the pre-cni lab from those who wants to install a cluster using the kubeadm method, but wish optimize time because this template 15 | installs automatically docker, kubernetes and the their dependencies. No kubernetes configuration is done here. 16 | Use it if you're creating a second cluster or have used "vagrant destroy -f" on the directory of your previous lab. This templates goes 17 | up to the point where you need to rum "kubeadm init" on the master and after "kubeadm join" on the workers. 18 | 19 | - k8s-kubeadm-calico-full-cluster-bootstrap 20 | this is the full cluster build that I have created to optimize your study time. Use this if you with to bootstrap a new cluster from zero 21 | but do not to run all the commands to bring the cluster up. The end result here is a full-cluster up and running so that you can continue 22 | your studies. Useful for those that have decided to "vagrant destroy -f" the previous cluster. 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /labs/k8s-kubeadm-pre-cni/Vagrantfile: -------------------------------------------------------------------------------- 1 | # kuberverse k8s lab provisioner 2 | # type: kubeadm-pre-cni 3 | # created by Artur Scheiner - artur.scheiner@gmail.com 4 | 5 | BOX_IMAGE = "bento/ubuntu-16.04" 6 | MASTER_COUNT = 1 7 | WORKER_COUNT = 2 8 | 9 | Vagrant.configure("2") do |config| 10 | 11 | (0..MASTER_COUNT-1).each do |i| 12 | config.vm.define "kv-master-#{i}" do |subconfig| 13 | subconfig.vm.box = BOX_IMAGE 14 | subconfig.vm.hostname = "kv-master-#{i}" 15 | subconfig.vm.network :private_network, ip: "10.8.8.#{i + 10}" 16 | subconfig.vm.provider :virtualbox do |vb| 17 | vb.customize ["modifyvm", :id, "--cpus", 2] 18 | vb.memory = 2048 19 | end 20 | end 21 | end 22 | 23 | (0..WORKER_COUNT-1).each do |i| 24 | config.vm.define "kv-worker-#{i}" do |subconfig| 25 | subconfig.vm.box = BOX_IMAGE 26 | subconfig.vm.hostname = "kv-worker-#{i}" 27 | subconfig.vm.network :private_network, ip: "10.8.8.#{i + 20}" 28 | subconfig.vm.provider :virtualbox do |vb| 29 | vb.customize ["modifyvm", :id, "--cpus", 2] 30 | vb.memory = 1024 31 | end 32 | end 33 | end 34 | 35 | # Install avahi on all machines 36 | config.vm.provision "shell", inline: <<-SHELL 37 | echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list 38 | curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 39 | apt-get update 40 | apt-get upgrade -y 41 | apt-get install -y avahi-daemon libnss-mdns traceroute htop httpie docker.io kubeadm kubelet kubectl 42 | SHELL 43 | 44 | config.vm.provision "shell", 45 | run: "always", 46 | inline: "swapoff -a" 47 | 48 | end 49 | -------------------------------------------------------------------------------- /kvlab.conf.rb: -------------------------------------------------------------------------------- 1 | # kuberverse kubernetes cluster lab 2 | # version: 0.5.0 3 | # description: this Vagrantfile creates a cluster with masters and workers 4 | # created by Artur Scheiner - artur.scheiner@gmail.com 5 | 6 | # Is not recommended, but you can change the base box. 7 | # This means that all the VMs will use the same image. 8 | # For vmware_desktop provider use 9 | # BOX_IMAGE = "bento/ubuntu-18.04" 10 | # For virtualbox provider you can choose to use 11 | # bento or kuberverse images. The difference is 12 | # that kuberverse images are pre-loaded with 13 | # the packages needed to create the cluster 14 | # that means less time to build the cluster. 15 | BOX_IMAGE = "kuberverse/ubuntu-18.04" 16 | 17 | # Define the k8s version to be used on this lab. 18 | KUBE_VERSION = "1.22.3" 19 | 20 | # Define the container runtime that will be used on 21 | # your lab. From k8s v1.22 the default runtime is containerd. 22 | # You can choose between containerd|docker 23 | CONTAINER_RUNTIME = "containerd" 24 | 25 | # Define CNI Provider 26 | # Choose between calico|weave|flannel 27 | CNI_PROVIDER = "weave" 28 | 29 | # Change these values if you wish to play with the 30 | # cluster size. Do this before starting your cluster 31 | # provisioning. 32 | MASTER_COUNT = 2 33 | WORKER_COUNT = 2 34 | 35 | # Change these values if you wish to play with the 36 | # VMs memory resources. 37 | # Kubernetes pre-flight for the MASTER_NODES now requires 1700+ of memory. 38 | SCALER_MEMORY = 512 39 | MASTER_MEMORY = 2048 40 | WORKER_MEMORY = 1024 41 | 42 | # Change these values if you wish to play with the 43 | # networking settings of your cluster 44 | KV_LAB_NETWORK = "10.8.8.0" 45 | 46 | # This value changes the intra-pod network 47 | POD_CIDR = "172.18.0.0/16" 48 | 49 | 50 | KVMSG = "Kuberverse Kubernetes Cluster Lab" -------------------------------------------------------------------------------- /labs/kv-k8s-cluster/master.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # kuberverse k8s lab provisioner 3 | # type: kubeadm-calico-full-cluster-bootstrap 4 | # created by Artur Scheiner - artur.scheiner@gmail.com 5 | 6 | KVMSG=$1 7 | NODE=$2 8 | POD_CIDR=$3 9 | API_ADV_ADDRESS=$4 10 | 11 | echo "********** $KVMSG" 12 | echo "********** $KVMSG" 13 | echo "********** $KVMSG ->> Initializing Kubernetes Cluster" 14 | echo "********** $KVMSG ->> Master Node $NODE" 15 | echo "********** $KVMSG ->> kv-master-$NODE" 16 | kubeadm init --pod-network-cidr $POD_CIDR --apiserver-advertise-address $API_ADV_ADDRESS | tee /vagrant/kubeadm-init.out 17 | 18 | echo "********** $KVMSG" 19 | echo "********** $KVMSG" 20 | echo "********** $KVMSG ->> Configuring Kubernetes Cluster Environment" 21 | echo "********** $KVMSG" 22 | echo "********** $KVMSG" 23 | mkdir -p /home/vagrant/.kube 24 | cp -i /etc/kubernetes/admin.conf /home/vagrant/.kube/config 25 | chown vagrant:vagrant /home/vagrant/.kube/config 26 | mkdir -p /root/.kube 27 | cp -i /etc/kubernetes/admin.conf /root/.kube/config 28 | 29 | #Configure the Calico Network Plugin 30 | echo "********** $KVMSG" 31 | echo "********** $KVMSG" 32 | echo "********** $KVMSG ->> Configuring Kubernetes Cluster Calico Networking" 33 | echo "********** $KVMSG ->> Downloading Calico YAML File" 34 | echo "********** $KVMSG" 35 | echo "********** $KVMSG" 36 | wget -q https://docs.projectcalico.org/v3.10/manifests/calico.yaml -O /tmp/calico-default.yaml 37 | #wget -q https://bit.ly/kv-lab-k8s-calico-yaml -O /tmp/calico-default.yaml 38 | sed "s+192.168.0.0/16+$POD_CIDR+g" /tmp/calico-default.yaml > /tmp/calico-defined.yaml 39 | 40 | echo "********** $KVMSG ->> Applying Calico YAML File" 41 | echo "********** $KVMSG" 42 | echo "********** $KVMSG" 43 | kubectl apply -f /tmp/calico-defined.yaml 44 | rm /tmp/calico-default.yaml /tmp/calico-defined.yaml 45 | echo KUBELET_EXTRA_ARGS=--node-ip=10.8.8.1$NODE > /etc/default/kubelet -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kuberverse 2 | 3 | ![kuberverse logo](https://raw.githubusercontent.com/arturscheiner/kuberverse/master/logos/kuberverse-logo-h-4096x2304.png) 4 | Hello kubers, welcome to kuberverse repo! This is the place where we publish the files used on our Youtube recording labs! 5 | 6 | ## Getting Started 7 | 8 | Here, you will find instructions on how to get ready with our labs. The labs where written with easy in mind, to help you build and play **kubernetes clusters**. Please, fell free to try them out!! 9 | 10 | ## System Requirements 11 | 12 | ### Software 13 | 14 | To run the labs you will need to have pre-installed on your computer the latest version of the following softwares: 15 | 16 | - [Vagrant](www.vagrantup.com) by Hashicorp 17 | - [Virtualbox](virtualbox.org) by Oracle 18 | 19 | ### Hardware 20 | 21 | The gold rule here is **more is better**. As we will create clusters using virtual machines running on your desk computer or notebook, resources will be needed in the proportion of your use. To be used for study, and using my computer (an old macbook pro late 2012 retina, with a Intel Core i5 processor with 8Gb of memory) as the basis for this labs, I can assure you can run a k8s cluster with 1 master with 2Gb of memory and 2 workers with 1Gb each. This configuration fits almost all of the 6 scenarios of the CKA and the 4 scenarios of CKAD certification exams. 22 | 23 | ### How to use 24 | First you need to clone this repository: 25 | 26 | - Find the directory where you want to start you labs.. 27 | - From inside this folder run: **git clone https://github.com/arturscheiner/kuberverse.git** 28 | - It will create the folder ./kuberverse (when clonning you can add the desired folder name at the end of the git clone command) 29 | - Inside the ./kuberverse folder, edit the file **kvlab.conf.rb** follow the instructions inside of it 30 | - From this folder, run the command **vagrant up** and wait a couple of minutes after that you will be able to access your cluster and play with it -------------------------------------------------------------------------------- /lib/rb/kvshell.rb: -------------------------------------------------------------------------------- 1 | # kuberverse kubernetes cluster lab 2 | # version: 0.5.0 3 | # description: this Vagrantfile creates a cluster with masters and workers 4 | # created by Artur Scheiner - artur.scheiner@gmail.com 5 | 6 | class KvShell 7 | def env(node,ip,hostname,sIPs,mIPs,wIPs) 8 | <<-SCRIPT 9 | export KV_KVMSG='#{KVMSG}' 10 | export KV_BOX_IMAGE=#{BOX_IMAGE} 11 | export KV_KUBE_VERSION=#{KUBE_VERSION} 12 | export KV_CONTAINER_RUNTIME=#{CONTAINER_RUNTIME} 13 | export KV_CNI_PROVIDER=#{CNI_PROVIDER} 14 | export kV_MASTER_COUNT=#{MASTER_COUNT} 15 | export KV_WORKER_COUNT=#{WORKER_COUNT} 16 | export KV_POD_CIDR=#{POD_CIDR} 17 | export KV_MASTER_TYPE=#{MASTER_COUNT == 1 ? "single" : "multi"} 18 | export KV_THIS_IP=#{ip} 19 | export KV_THIS_NODE=#{node} 20 | export KV_THIS_HOSTNAME=#{hostname} 21 | export KV_SCALER_IPS_ARRAY="#{sIPs}" 22 | export KV_MASTER_IPS_ARRAY="#{mIPs}" 23 | export KV_WORKER_IPS_ARRAY="#{wIPs}" 24 | SCRIPT 25 | end 26 | 27 | def scaler() 28 | <<-SCRIPT 29 | printenv | grep -E '^KV_' | sed 's/^/export /' >> ~/.bash_profile 30 | mkdir -p /home/vagrant/.kv 31 | 32 | /bin/bash -c '/vagrant/lib/sh/scaler.sh' 33 | SCRIPT 34 | end 35 | 36 | def worker() 37 | <<-SCRIPT 38 | printenv | grep -E '^KV_' | sed 's/^/export /' >> ~/.bash_profile 39 | mkdir -p /home/vagrant/.kv 40 | 41 | /bin/bash -c '/vagrant/lib/sh/common.sh' 42 | /bin/bash -c '/vagrant/lib/sh/worker.sh' 43 | SCRIPT 44 | end 45 | 46 | def master() 47 | <<-SCRIPT 48 | printenv | grep -E '^KV_' | sed 's/^/export /' >> ~/.bash_profile 49 | 50 | mkdir -p /home/vagrant/.kv 51 | 52 | /bin/bash -c '/vagrant/lib/sh/common.sh' 53 | /bin/bash -c '/vagrant/lib/sh/master.sh' 54 | SCRIPT 55 | end 56 | 57 | end -------------------------------------------------------------------------------- /docs/kubeadm/k8s-kubeadm-base.md: -------------------------------------------------------------------------------- 1 | # The kubeadm Empty Lab 2 | 3 | This is the **empty lab** created for those who wants to install a k8s cluster using the kubeadm method but wish to do almost all the work manually, running the commands necessary to bring the cluster up on a step-by-step way. This template will create the boxes MASTER and WORKERS, with the base recomended OS image (ubuntu 16.04). 4 | 5 | ## Use Considerations ## 6 | 7 | ### Use it if: ### 8 | 9 | - you're new to kubernetes and wish to start your first cluster running all the commands needed to create your study cluster environment; 10 | - you like to do stuffs manually ir order to have a deeper understanting of what is happening; 11 | 12 | ## Getting Started ## 13 | 14 | To run the labs you will need to have pre-installed on your computer the latest version of the following softwares: 15 | 16 | - [Vagrant](www.vagrantup.com) by Hashicorp 17 | - [Virtualbox](virtualbox.org) by Oracle 18 | 19 | ### Tiny URL ### 20 | 21 | http://bit.ly/kv-lab-k8s-kab-vf 22 | 23 | ### Steps To Run ### 24 | 25 | 1. Create a directory 26 | ```bash 27 | make -p kuberverse/kv-empty 28 | ``` 29 | 30 | 2. Import the Vagrantfile file to this directory 31 | 32 | ```bash 33 | cd kuberverse/kv-empty 34 | wget http://bit.ly/kv-lab-k8s-kab-vf -O Vagrantfile 35 | ``` 36 | 37 | 3. Execute the vagrant command to startup the multi-machine environment 38 | 39 | ```bash 40 | vagrant up 41 | ```` 42 | 43 | 4. Your lab environment will be automatically provisioned and you would be able to get the list of the machines using the command 44 | 45 | ```bash 46 | vagrant status 47 | ```` 48 | 49 | 5. Your lab environment will be automatically provisioned and you would be able to access the shell of any of the machines using the command 50 | 51 | ```bash 52 | vagrant ssh **_machine-name_** 53 | ``` 54 | 55 | ex: _vagrant ssh kv-master-0_ 56 | 57 | ## Next Steps ## 58 | 59 | After provisioning this environment you will need to follow the steps describe on _kuberverse youtube_ or _kubeverse blog_ -------------------------------------------------------------------------------- /labs/kv-k8s-cluster/common.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # kuberverse k8s lab provisioner 3 | # type: kubeadm-calico-full-cluster-bootstrap 4 | # created by Artur Scheiner - artur.scheiner@gmail.com 5 | 6 | #variable definitions 7 | KVMSG=$1 8 | 9 | echo "********** $KVMSG" 10 | echo "********** $KVMSG" 11 | echo "********** $KVMSG ->> Adding Kubernetes and Docker-CE Repo" 12 | echo "********** $KVMSG" 13 | echo "********** $KVMSG" 14 | ### Install packages to allow apt to use a repository over HTTPS 15 | apt-get update && apt-get install apt-transport-https ca-certificates curl software-properties-common 16 | 17 | ### Add Kubernetes GPG key 18 | curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 19 | 20 | ### Kubernetes Repo 21 | echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list 22 | 23 | ### Add Docker’s official GPG key 24 | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - 25 | 26 | ### Add Docker apt repository. 27 | add-apt-repository \ 28 | "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ 29 | $(lsb_release -cs) \ 30 | stable" 31 | 32 | echo "********** $KVMSG" 33 | echo "********** $KVMSG" 34 | echo "********** $KVMSG ->> Updating Repositories" 35 | echo "********** $KVMSG" 36 | echo "********** $KVMSG" 37 | apt-get update 38 | 39 | echo "********** $KVMSG" 40 | echo "********** $KVMSG" 41 | echo "********** $KVMSG ->> Installing Required & Recommended Packages" 42 | echo "********** $KVMSG" 43 | echo "********** $KVMSG" 44 | apt-get install -y avahi-daemon libnss-mdns traceroute htop httpie bash-completion docker-ce=5:18.09.1~3-0~ubuntu-xenial kubeadm kubelet kubectl 45 | 46 | # Setup Docker daemon. 47 | cat > /etc/docker/daemon.json <> /etc/apt/apt.conf.d/99progress 19 | 20 | ### Install packages to allow apt to use a repository over HTTPS 21 | apt update && apt install apt-transport-https ca-certificates curl software-properties-common haproxy 22 | 23 | ### Add Docker’s official GPG key 24 | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - 25 | 26 | ### Add Docker apt repository. 27 | add-apt-repository \ 28 | "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ 29 | $(lsb_release -cs) \ 30 | stable" 31 | 32 | add-apt-repository ppa:vbernat/haproxy-2.0 -y 33 | 34 | apt update 35 | 36 | apt install -y avahi-daemon libnss-mdns traceroute htop httpie bash-completion haproxy ruby docker-ce 37 | fi 38 | 39 | systemctl stop haproxy 40 | 41 | tee /etc/haproxy/haproxy.cfg <> /etc/haproxy/haproxy.cfg 81 | ((i++)) 82 | done 83 | 84 | cat /vagrant/.kv/hosts >> /etc/hosts 85 | 86 | systemctl restart haproxy -------------------------------------------------------------------------------- /lib/rb/kvtools.rb: -------------------------------------------------------------------------------- 1 | # kuberverse kubernetes cluster lab 2 | # version: 0.5.0 3 | # description: this Vagrantfile creates a cluster with masters and workers 4 | # created by Artur Scheiner - artur.scheiner@gmail.com 5 | 6 | class KvTools 7 | def defineIp(type,i,kvln) 8 | case type 9 | when "master" 10 | return kvln.split('.')[0..-2].join('.') + ".#{i + 10}" 11 | when "worker" 12 | return kvln.split('.')[0..-2].join('.') + ".#{i + 20}" 13 | when "scaler" 14 | return kvln.split('.')[0..-2].join('.') + ".#{i + 50}" 15 | end 16 | end 17 | 18 | def addToHosts(ip,hostname) 19 | hosts=".kv/hosts" 20 | Dir.mkdir('.kv') unless File.exists?('.kv') 21 | File.new(hosts, "w") unless File.exists?(hosts) 22 | 23 | line_exist=File.readlines(hosts).grep(/#{ip}/).size 24 | 25 | if line_exist > 0 26 | puts "this #{ip} and #{hostname} is already in .kv/hosts file" 27 | else 28 | puts "updatind .kv/hosts file with #{ip} and #{hostname}" 29 | File.open(hosts, "a") do |line| 30 | line.puts "#{ip} #{hostname} #{hostname}.lab.local #{hostname}.local" 31 | end 32 | end 33 | end 34 | 35 | def cleanKvDir() 36 | kv_dir=".kv" 37 | FileUtils.remove_dir(kv_dir) if File.directory?(kv_dir) 38 | end 39 | 40 | def iPSa(type,count) 41 | iPS = Array[] 42 | (0..count-1).each do |node| 43 | iPS.push(self.defineIp(type,node,KV_LAB_NETWORK)) 44 | end 45 | return iPS 46 | end 47 | 48 | def colorize(text, color_code) 49 | "\e[#{color_code}m#{text}\e[0m" 50 | end 51 | 52 | def red(text); colorize(text, 31); end 53 | def green(text); colorize(text, 32); end 54 | def yellow(text); colorize(text, 33); end 55 | def blue(text); colorize(text, 34); end 56 | 57 | end 58 | 59 | class String 60 | def black; "\e[30m#{self}\e[0m" end 61 | def red; "\e[31m#{self}\e[0m" end 62 | def green; "\e[32m#{self}\e[0m" end 63 | def brown; "\e[33m#{self}\e[0m" end 64 | def blue; "\e[34m#{self}\e[0m" end 65 | def magenta; "\e[35m#{self}\e[0m" end 66 | def cyan; "\e[36m#{self}\e[0m" end 67 | def gray; "\e[37m#{self}\e[0m" end 68 | def yellow; "\e[33m#{self}\e[0m" end 69 | 70 | def bg_black; "\e[40m#{self}\e[0m" end 71 | def bg_red; "\e[41m#{self}\e[0m" end 72 | def bg_green; "\e[42m#{self}\e[0m" end 73 | def bg_brown; "\e[43m#{self}\e[0m" end 74 | def bg_blue; "\e[44m#{self}\e[0m" end 75 | def bg_magenta; "\e[45m#{self}\e[0m" end 76 | def bg_cyan; "\e[46m#{self}\e[0m" end 77 | def bg_gray; "\e[47m#{self}\e[0m" end 78 | 79 | def bold; "\e[1m#{self}\e[22m" end 80 | def italic; "\e[3m#{self}\e[23m" end 81 | def underline; "\e[4m#{self}\e[24m" end 82 | def blink; "\e[5m#{self}\e[25m" end 83 | def reverse_color; "\e[7m#{self}\e[27m" end 84 | end -------------------------------------------------------------------------------- /labs/kv-k8s-cluster-ha/scaler.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # kuberverse kubernetes cluster lab 3 | # version: 0.1.0-alpha 4 | # description: this is the scaler (load balancer) script file 5 | # created by Artur Scheiner - artur.scheiner@gmail.com 6 | 7 | KVMSG=$1 8 | SCALER_IP=$2 9 | BOX_IMAGE=$3 10 | MASTER_IPS=$(echo $4 | sed -e 's/,//g' -e 's/\]//g' -e 's/\[//g') 11 | 12 | 13 | 14 | 15 | 16 | if [[ ! $BOX_IMAGE =~ "kuberverse" ]] 17 | then 18 | 19 | export DEBIAN_FRONTEND=noninteractive 20 | 21 | echo -e 'Dpkg::Progress-Fancy "1";\nAPT::Color "1";' >> /etc/apt/apt.conf.d/99progress 22 | 23 | ### Install packages to allow apt to use a repository over HTTPS 24 | apt update && apt install apt-transport-https ca-certificates curl software-properties-common haproxy 25 | 26 | ### Add Docker’s official GPG key 27 | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - 28 | 29 | ### Add Docker apt repository. 30 | add-apt-repository \ 31 | "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ 32 | $(lsb_release -cs) \ 33 | stable" 34 | 35 | add-apt-repository ppa:vbernat/haproxy-2.0 -y 36 | 37 | apt update 38 | 39 | apt install -y avahi-daemon libnss-mdns traceroute htop httpie bash-completion haproxy ruby docker-ce 40 | fi 41 | 42 | systemctl stop haproxy 43 | 44 | tee /etc/haproxy/haproxy.cfg <> /etc/haproxy/haproxy.cfg 84 | ((i++)) 85 | done 86 | 87 | # echo "#Added by Kuberverse" > /vagrant/hosts.out 88 | # echo "$SCALER_IP kv-scaler.lab.local kv-scaler.local kv-scaler" >> /vagrant/hosts.out 89 | 90 | #cat > /vagrant/hosts.out<> /etc/hosts 96 | 97 | systemctl restart haproxy -------------------------------------------------------------------------------- /lib/sh/master.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # kuberverse kubernetes cluster lab 3 | # version: 0.5.0 4 | # description: this is the masters script file 5 | # created by Artur Scheiner - artur.scheiner@gmail.com 6 | 7 | if [ $KV_MASTER_TYPE = "single" ]; then 8 | 9 | kubeadm init --pod-network-cidr $KV_POD_CIDR \ 10 | --apiserver-advertise-address $KV_THIS_IP \ 11 | --apiserver-cert-extra-sans kv-master-0.lab.local | tee /vagrant/.kv/kubeadm-init.log 12 | 13 | k=$(grep -n "kubeadm join $KV_THIS_IP" /vagrant/.kv/kubeadm-init.log | cut -f1 -d:) 14 | x=$(echo $k | awk '{print $1}') 15 | awk -v ln=$x 'NR>=ln && NR<=ln+1' /vagrant/.kv/kubeadm-init.log | tee /vagrant/.kv/workers-join 16 | 17 | else 18 | 19 | if [ $KV_THIS_NODE = "0" ] ; then 20 | 21 | kubeadm init --control-plane-endpoint "kv-scaler-0.lab.local:6443" \ 22 | --apiserver-advertise-address $KV_THIS_IP \ 23 | --upload-certs --pod-network-cidr $KV_POD_CIDR \ 24 | --apiserver-cert-extra-sans kv-scaler-0.lab.local | tee /vagrant/.kv/kubeadm-init.log 25 | 26 | k=$(grep -n "kubeadm join kv-scaler-0.lab.local" /vagrant/.kv/kubeadm-init.log | cut -f1 -d:) 27 | x=$(echo $k | awk '{print $1}') 28 | awk -v ln=$x 'NR>=ln && NR<=ln+2' /vagrant/.kv/kubeadm-init.log | tee /vagrant/.kv/masters-join-default 29 | awk -v ln=$x 'NR>=ln && NR<=ln+1' /vagrant/.kv/kubeadm-init.log | tee /vagrant/.kv/workers-join 30 | else 31 | sed "s+lab.local:6443+lab.local:6443 --apiserver-advertise-address $KV_THIS_IP+g" /vagrant/.kv/masters-join-default > /vagrant/.kv/masters-join-$KV_THIS_NODE 32 | $(cat /vagrant/.kv/masters-join-$KV_THIS_NODE | sed -e 's/^[ \t]*//' | tr '\n' ' ' | sed -e 's/ \\ / /g') 33 | fi 34 | fi 35 | 36 | mkdir -p /home/vagrant/.kube 37 | cp -i /etc/kubernetes/admin.conf /home/vagrant/.kube/config 38 | chown vagrant:vagrant /home/vagrant/.kube/config 39 | 40 | mkdir -p /root/.kube 41 | cp -i /etc/kubernetes/admin.conf /root/.kube/config 42 | 43 | mkdir -p /vagrant/.kv 44 | cp -i /etc/kubernetes/admin.conf /vagrant/.kv/kube-config 45 | 46 | if (( $KV_THIS_NODE == 0 )) ; then 47 | case $KV_CNI_PROVIDER in 48 | calico) 49 | wget -q https://docs.projectcalico.org/manifests/calico.yaml -O /tmp/calico-default.yaml 50 | sed "s+192.168.0.0/16+$KV_POD_CIDR+g" /tmp/calico-default.yaml > /tmp/calico-defined.yaml 51 | kubectl apply -f /tmp/calico-defined.yaml 52 | ;; 53 | weave) 54 | wget -q "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')&env.IPALLOC_RANGE=$KV_POD_CIDR" -O /tmp/weave-defined.yaml 55 | kubectl apply -f /tmp/weave-defined.yaml 56 | ;; 57 | 58 | flannel) 59 | #not supported yet 60 | ;; 61 | *) 62 | #no default defined 63 | ;; 64 | esac 65 | fi 66 | 67 | if grep -E "KUBELET_EXTRA_ARGS=" /etc/default/kubelet ; then 68 | sed -i "s+KUBELET_EXTRA_ARGS=\"+KUBELET_EXTRA_ARGS=\"--node-ip=$KV_THIS_IP +g" /etc/default/kubelet 69 | else 70 | echo KUBELET_EXTRA_ARGS=--node-ip=$KV_THIS_IP >> /etc/default/kubelet 71 | fi 72 | 73 | systemctl restart networking 74 | systemctl restart kubelet 75 | -------------------------------------------------------------------------------- /labs/kv-k8s-cluster/Vagrantfile: -------------------------------------------------------------------------------- 1 | # kuberverse k8s lab provisioner 2 | # type: kubeadm-calico-full-cluster-bootstrap 3 | # created by Artur Scheiner - artur.scheiner@gmail.com 4 | # dependencies: https://raw.githubusercontent.com/arturscheiner/kuberverse/master/labs/kv-k8s-cluster/common.sh 5 | # https://raw.githubusercontent.com/arturscheiner/kuberverse/master/labs/kv-k8s-cluster/master.sh 6 | # https://raw.githubusercontent.com/arturscheiner/kuberverse/master/labs/kv-k8s-cluster/worker.sh 7 | 8 | BOX_IMAGE = "bento/ubuntu-16.04" 9 | MASTER_COUNT = 1 10 | WORKER_COUNT = 2 11 | POD_CIDR = "172.18.0.0/16" 12 | API_ADV_ADDRESS = "10.8.8.10" 13 | KVMSG = "Kuberverse" 14 | COMMON_SCRIPT_URL = "https://raw.githubusercontent.com/arturscheiner/kuberverse/master/labs/kv-k8s-cluster/common.sh" 15 | MASTER_SCRIPT_URL = "https://raw.githubusercontent.com/arturscheiner/kuberverse/master/labs/kv-k8s-cluster/master.sh" 16 | WORKER_SCRIPT_URL = "https://raw.githubusercontent.com/arturscheiner/kuberverse/master/labs/kv-k8s-cluster/worker.sh" 17 | 18 | Vagrant.configure("2") do |config| 19 | 20 | # Installing the necessary packages for this provisioner 21 | config.vm.provision "shell" do |s| 22 | s.inline = <<-SCRIPT 23 | mkdir -p /home/vagrant/.kv 24 | wget -q #{COMMON_SCRIPT_URL} -O /home/vagrant/.kv/common.sh 25 | chmod +x /home/vagrant/.kv/common.sh 26 | /home/vagrant/.kv/common.sh #{KVMSG} 27 | SCRIPT 28 | end 29 | 30 | (0..MASTER_COUNT-1).each do |i| 31 | config.vm.define "kv-master-#{i}" do |subconfig| 32 | subconfig.vm.box = BOX_IMAGE 33 | subconfig.vm.hostname = "kv-master-#{i}" 34 | subconfig.vm.network :private_network, ip: "10.8.8.#{i + 10}" 35 | subconfig.vm.provider :virtualbox do |vb| 36 | vb.customize ["modifyvm", :id, "--cpus", 2] 37 | vb.memory = 2048 38 | end 39 | 40 | # This if is here just to remember me to create a multi-master cluster 41 | # the behavior and overal configuration is different and this will require a HAProxy installation 42 | if i == 0 43 | 44 | subconfig.vm.provision "shell" do |s| 45 | s.inline = <<-SCRIPT 46 | mkdir -p /home/vagrant/.kv 47 | wget -q #{MASTER_SCRIPT_URL} -O /home/vagrant/.kv/master.sh 48 | chmod +x /home/vagrant/.kv/master.sh 49 | /home/vagrant/.kv/master.sh #{KVMSG} #{i} #{POD_CIDR} #{API_ADV_ADDRESS} 50 | SCRIPT 51 | end 52 | 53 | end 54 | 55 | end 56 | end 57 | 58 | (0..WORKER_COUNT-1).each do |i| 59 | config.vm.define "kv-worker-#{i}" do |subconfig| 60 | subconfig.vm.box = BOX_IMAGE 61 | subconfig.vm.hostname = "kv-worker-#{i}" 62 | subconfig.vm.network :private_network, ip: "10.8.8.#{i + 20}" 63 | subconfig.vm.provider :virtualbox do |vb| 64 | vb.customize ["modifyvm", :id, "--cpus", 2] 65 | vb.memory = 1024 66 | end 67 | 68 | subconfig.vm.provision "shell" do |s| 69 | s.inline = <<-SCRIPT 70 | mkdir -p /home/vagrant/.kv 71 | wget -q #{WORKER_SCRIPT_URL} -O /home/vagrant/.kv/worker.sh 72 | chmod +x /home/vagrant/.kv/worker.sh 73 | /home/vagrant/.kv/worker.sh #{KVMSG} #{i} #{POD_CIDR} #{API_ADV_ADDRESS} 74 | SCRIPT 75 | end 76 | 77 | end 78 | end 79 | 80 | config.vm.provision "shell", 81 | run: "always", 82 | inline: "swapoff -a" 83 | 84 | end 85 | -------------------------------------------------------------------------------- /labs/kv-k8s-cluster-ha/master.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # kuberverse kubernetes cluster lab 3 | # version: 0.2.0 4 | # description: this is the masters script file 5 | # created by Artur Scheiner - artur.scheiner@gmail.com 6 | 7 | KVMSG=$1 8 | NODE=$2 9 | POD_CIDR=$3 10 | MASTER_IP=$4 11 | CNI_PROVIDER=$5 12 | MASTER_TYPE=$6 13 | 14 | if [ $MASTER_TYPE = "single" ]; then 15 | 16 | #echo "# Added by Kuberverse" > /vagrant/hosts.out 17 | #echo "$MASTER_IP kv-master.lab.local kv-master.local kv-master" >> /vagrant/hosts.out 18 | 19 | kubeadm init --pod-network-cidr $POD_CIDR --apiserver-advertise-address $MASTER_IP --apiserver-cert-extra-sans kv-master.lab.local --apiserver-cert-extra-sans kv-scaler.lab.local | tee /vagrant/kubeadm-init.out 20 | 21 | k=$(grep -n "kubeadm join $MASTER_IP" /vagrant/kubeadm-init.out | cut -f1 -d:) 22 | x=$(echo $k | awk '{print $1}') 23 | awk -v ln=$x 'NR>=ln && NR<=ln+1' /vagrant/kubeadm-init.out | tee /vagrant/workers-join.out 24 | 25 | else 26 | 27 | if (( $NODE == 0 )) ; then 28 | 29 | kubeadm init --control-plane-endpoint "kv-scaler.lab.local:6443" --apiserver-advertise-address $MASTER_IP --upload-certs --pod-network-cidr $POD_CIDR --apiserver-cert-extra-sans kv-master.lab.local --apiserver-cert-extra-sans kv-scaler.lab.local | tee /vagrant/kubeadm-init.out 30 | 31 | k=$(grep -n "kubeadm join kv-scaler.lab.local" /vagrant/kubeadm-init.out | cut -f1 -d:) 32 | x=$(echo $k | awk '{print $1}') 33 | awk -v ln=$x 'NR>=ln && NR<=ln+2' /vagrant/kubeadm-init.out | tee /vagrant/masters-join-default.out 34 | awk -v ln=$x 'NR>=ln && NR<=ln+1' /vagrant/kubeadm-init.out | tee /vagrant/workers-join.out 35 | else 36 | sed "s+kubeadm join kv-scaler.lab.local:6443+kubeadm join kv-scaler.lab.local:6443 --apiserver-advertise-address $MASTER_IP+g" /vagrant/masters-join-default.out > /vagrant/masters-join-$NODE.out 37 | $(cat /vagrant/masters-join-$NODE.out | sed -e 's/^[ \t]*//' | tr '\n' ' ' | sed -e 's/ \\ / /g') 38 | fi 39 | 40 | fi 41 | 42 | mkdir -p /home/vagrant/.kube 43 | cp -i /etc/kubernetes/admin.conf /home/vagrant/.kube/config 44 | chown vagrant:vagrant /home/vagrant/.kube/config 45 | 46 | mkdir -p /root/.kube 47 | cp -i /etc/kubernetes/admin.conf /root/.kube/config 48 | 49 | mkdir -p /vagrant/.kube 50 | cp -i /etc/kubernetes/admin.conf /vagrant/.kube/config 51 | 52 | if (( $NODE == 0 )) ; then 53 | case $CNI_PROVIDER in 54 | calico) 55 | wget -q https://docs.projectcalico.org/manifests/calico.yaml -O /tmp/calico-default.yaml 56 | sed "s+192.168.0.0/16+$POD_CIDR+g" /tmp/calico-default.yaml > /tmp/calico-defined.yaml 57 | kubectl apply -f /tmp/calico-defined.yaml 58 | ;; 59 | weave) 60 | wget -q "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')&env.IPALLOC_RANGE=$POD_CIDR" -O /tmp/weave-defined.yaml 61 | kubectl apply -f /tmp/weave-defined.yaml 62 | ;; 63 | 64 | flannel) 65 | #not supported yet 66 | ;; 67 | *) 68 | #no default defined 69 | ;; 70 | esac 71 | fi 72 | 73 | if grep -E "KUBELET_EXTRA_ARGS=" /etc/default/kubelet ; then 74 | sed -i "s+KUBELET_EXTRA_ARGS=\"+KUBELET_EXTRA_ARGS=\"--node-ip=$MASTER_IP +g" /etc/default/kubelet 75 | else 76 | echo KUBELET_EXTRA_ARGS=--node-ip=$MASTER_IP >> /etc/default/kubelet 77 | fi 78 | 79 | systemctl restart networking 80 | systemctl restart kubelet 81 | -------------------------------------------------------------------------------- /labs/k8s-kubeadm-calico-full-cluster-bootstrap/Vagrantfile: -------------------------------------------------------------------------------- 1 | # kuberverse k8s lab provisioner 2 | # type: kubeadm-calico-full-cluster-bootstrap 3 | # created by Artur Scheiner - artur.scheiner@gmail.com 4 | 5 | BOX_IMAGE = "bento/ubuntu-16.04" 6 | MASTER_COUNT = 1 7 | WORKER_COUNT = 2 8 | POD_CIDR = "172.18.0.0/16" 9 | 10 | Vagrant.configure("2") do |config| 11 | 12 | (0..MASTER_COUNT-1).each do |i| 13 | config.vm.define "kv-master-#{i}" do |subconfig| 14 | subconfig.vm.box = BOX_IMAGE 15 | subconfig.vm.hostname = "kv-master-#{i}" 16 | subconfig.vm.network :private_network, ip: "10.8.8.#{i + 10}" 17 | subconfig.vm.provider :virtualbox do |vb| 18 | vb.customize ["modifyvm", :id, "--cpus", 2] 19 | vb.memory = 2048 20 | end 21 | 22 | # Installing the necessary packages for this provisioner 23 | subconfig.vm.provision "shell", inline: <<-SHELL 24 | echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list 25 | curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 26 | apt-get update 27 | apt-get upgrade -y 28 | apt-get install -y avahi-daemon libnss-mdns traceroute htop httpie bash-completion docker.io kubeadm kubelet kubectl 29 | SHELL 30 | 31 | if i == 0 32 | # Starting the creation of the k8s cluster and adjusting configurations 33 | subconfig.vm.provision "shell", inline: <<-SHELL 34 | kubeadm init --pod-network-cidr #{POD_CIDR} --apiserver-advertise-address 10.8.8.10 | tee /vagrant/kubeadm-init.out 35 | mkdir -p /home/vagrant/.kube 36 | cp -i /etc/kubernetes/admin.conf /home/vagrant/.kube/config 37 | chown vagrant:vagrant /home/vagrant/.kube/config 38 | 39 | mkdir -p /root/.kube 40 | cp -i /etc/kubernetes/admin.conf /root/.kube/config 41 | 42 | #Configure the Calico Network Plugin 43 | wget https://bit.ly/kv-lab-k8s-calico-yaml -O /tmp/calico-default.yaml 44 | sed "s+192.168.0.0/16+#{POD_CIDR}+g" /tmp/calico-default.yaml > /tmp/calico-defined.yaml 45 | kubectl apply -f /tmp/calico-defined.yaml 46 | rm /tmp/calico-default.yaml /tmp/calico-defined.yaml 47 | echo KUBELET_EXTRA_ARGS=--node-ip=10.8.8.10 > /etc/default/kubelet 48 | SHELL 49 | end 50 | 51 | end 52 | end 53 | 54 | (0..WORKER_COUNT-1).each do |i| 55 | config.vm.define "kv-worker-#{i}" do |subconfig| 56 | subconfig.vm.box = BOX_IMAGE 57 | subconfig.vm.hostname = "kv-worker-#{i}" 58 | subconfig.vm.network :private_network, ip: "10.8.8.#{i + 20}" 59 | subconfig.vm.provider :virtualbox do |vb| 60 | vb.customize ["modifyvm", :id, "--cpus", 2] 61 | vb.memory = 1024 62 | end 63 | 64 | # Installing the necessary packages for this provisioner 65 | subconfig.vm.provision "shell", inline: <<-SHELL 66 | echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list 67 | curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 68 | apt-get update 69 | apt-get upgrade -y 70 | apt-get install -y avahi-daemon libnss-mdns traceroute htop httpie bash-completion docker.io kubeadm kubelet kubectl 71 | 72 | # Extract and execute the kubeadm join command from the exported file 73 | $(cat /vagrant/kubeadm-init.out | grep -A 2 "kubeadm join" | sed -e 's/^[ \t]*//' | tr '\n' ' ' | sed -e 's/ \\ / /g') 74 | echo KUBELET_EXTRA_ARGS=--node-ip=10.8.8.#{i + 20} > /etc/default/kubelet 75 | SHELL 76 | end 77 | end 78 | 79 | config.vm.provision "shell", 80 | run: "always", 81 | inline: "swapoff -a" 82 | 83 | end 84 | -------------------------------------------------------------------------------- /lib/sh/scaler-docker.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # kuberverse kubernetes cluster lab 3 | # version: 0.1.0-alpha 4 | # description: this is the scaler (load balancer) script file 5 | # created by Artur Scheiner - artur.scheiner@gmail.com 6 | 7 | KVMSG=$1 8 | SCALER_IP=$2 9 | MASTER_IPS=$(echo $3 | sed -e 's/,//g' -e 's/\]//g' -e 's/\[//g') 10 | 11 | ### Install packages to allow apt to use a repository over HTTPS 12 | apt-get update && apt-get install apt-transport-https ca-certificates curl software-properties-common haproxy 13 | 14 | ### Add Docker’s official GPG key 15 | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - 16 | 17 | ### Add Docker apt repository. 18 | add-apt-repository \ 19 | "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ 20 | $(lsb_release -cs) \ 21 | stable" 22 | 23 | add-apt-repository ppa:vbernat/haproxy-2.0 -y 24 | 25 | apt-get update 26 | 27 | apt-get install -y avahi-daemon libnss-mdns traceroute htop httpie bash-completion haproxy ruby docker-ce 28 | 29 | cat >> /etc/haproxy/haproxy.cfg <> /etc/haproxy/haproxy.cfg 54 | ((i++)) 55 | done 56 | 57 | # echo "#Added by Kuberverse" > /vagrant/hosts.out 58 | # echo "$SCALER_IP kv-scaler.lab.local kv-scaler.local kv-scaler" >> /vagrant/hosts.out 59 | 60 | cat > /vagrant/hosts.out<> /etc/hosts 66 | 67 | systemctl restart haproxy 68 | 69 | mkdir -p /etc/kuberverse/kv-scaler 70 | 71 | cat > /etc/kuberverse/kv-scaler/haproxy.cfg <> /etc/kuberverse/kv-scaler/haproxy.cfg 105 | ((i++)) 106 | done 107 | 108 | cat > /etc/kuberverse/kv-scaler/Dockerfile< /etc/systemd/system/kv-scaler-docker.service<> /etc/haproxy/haproxy.cfg <> /etc/haproxy/haproxy.cfg 54 | ((i++)) 55 | done 56 | 57 | # echo "#Added by Kuberverse" > /vagrant/hosts.out 58 | # echo "$SCALER_IP kv-scaler.lab.local kv-scaler.local kv-scaler" >> /vagrant/hosts.out 59 | 60 | cat > /vagrant/hosts.out<> /etc/hosts 66 | 67 | systemctl restart haproxy 68 | 69 | mkdir -p /etc/kuberverse/kv-scaler 70 | 71 | cat > /etc/kuberverse/kv-scaler/haproxy.cfg <> /etc/kuberverse/kv-scaler/haproxy.cfg 105 | ((i++)) 106 | done 107 | 108 | cat > /etc/kuberverse/kv-scaler/Dockerfile< /etc/systemd/system/kv-scaler-docker.service<> /etc/apt/apt.conf.d/00aptproxy 48 | echo -e 'Dpkg::Progress-Fancy "1";\nAPT::Color "1";' >> /etc/apt/apt.conf.d/99progress 49 | fi 50 | 51 | cat /vagrant/.kv/hosts >> /etc/hosts 52 | 53 | case $KV_CONTAINER_RUNTIME in 54 | containerd) 55 | 56 | ### containerd 57 | 58 | cat < /etc/containerd/config.toml < /etc/docker/daemon.json <> /etc/apt/apt.conf.d/00aptproxy 55 | echo -e 'Dpkg::Progress-Fancy "1";\nAPT::Color "1";' >> /etc/apt/apt.conf.d/99progress 56 | fi 57 | 58 | cat /vagrant/hosts.out >> /etc/hosts 59 | 60 | case $CONTAINER_RUNTIME in 61 | containerd) 62 | 63 | ### containerd 64 | 65 | cat < /etc/containerd/config.toml < /etc/docker/daemon.json <= 2 17 | $sIPs = @kvtools.iPSa("scaler",1) 18 | else 19 | $sIPs = [] 20 | end 21 | 22 | $mIPs = @kvtools.iPSa("master",MASTER_COUNT) 23 | $wIPs = @kvtools.iPSa("worker",WORKER_COUNT) 24 | 25 | puts "********** #{KVMSG.green}**********" 26 | 27 | checkmark = "\u2713" 28 | puts checkmark.force_encoding('utf-8').green.bold.blink 29 | 30 | puts "---- Provisioned with k8s #{KUBE_VERSION.yellow}".blue 31 | puts "---- Container runtime is: #{CONTAINER_RUNTIME.yellow}" 32 | puts "---- CNI Provider is: #{CNI_PROVIDER.yellow}" 33 | puts "---- #{MASTER_COUNT} Masters Nodes" 34 | puts "---- #{WORKER_COUNT} Worker(s) Node(s)" unless MASTER_COUNT == 5 35 | end 36 | 37 | def createScaler(config) 38 | 39 | node = 0 40 | ip = @kvtools.defineIp("scaler",node,KV_LAB_NETWORK) 41 | 42 | if MASTER_COUNT != 1 43 | puts "---- 1 Scaler Node" 44 | puts "The Scaler #{node} Ip is #{ip}" 45 | end 46 | 47 | config.vm.define "kv-scaler-#{node}" do |scaler| 48 | scaler.vm.box = BOX_IMAGE 49 | scaler.vm.hostname = "kv-scaler-#{node}" 50 | scaler.vm.network :private_network, ip: ip, nic_type: "virtio" 51 | scaler.vm.network "forwarded_port", guest: 6443, host: 6443 52 | 53 | scaler.vm.provider :virtualbox do |vb| 54 | vb.customize ["modifyvm", :id, "--cpus", 2, "--nictype1", "virtio"] 55 | vb.memory = SCALER_MEMORY 56 | end 57 | 58 | if !BOX_IMAGE.include? "kuberverse" 59 | scaler.vm.provider "vmware_desktop" do |v| 60 | v.vmx["memsize"] = SCALER_MEMORY 61 | v.vmx["numvcpus"] = "2" 62 | end 63 | end 64 | if ARGV[0] == "destroy" 65 | puts "Deleting .kv directory" 66 | @kvtools.cleanKvDir() 67 | else 68 | @kvtools.addToHosts(ip,scaler.vm.hostname) 69 | end 70 | $s_script = @kvshell.env(node,ip,scaler.vm.hostname,$sIPs,$mIPs,$wIPs) + @kvshell.scaler() 71 | scaler.vm.provision "shell", inline: $s_script, keep_color: true 72 | end 73 | end 74 | 75 | def createMaster(config) 76 | 77 | (0..MASTER_COUNT-1).each do |node| 78 | ip = @kvtools.defineIp("master",node,KV_LAB_NETWORK) 79 | 80 | puts "The Master #{node} Ip is #{ip}" 81 | config.vm.define "kv-master-#{node}" do |master| 82 | master.vm.box = BOX_IMAGE 83 | master.vm.hostname = "kv-master-#{node}" 84 | master.vm.network :private_network, ip: ip, nic_type: "virtio" 85 | 86 | 87 | if MASTER_COUNT == 1 88 | master.vm.network "forwarded_port", guest: 6443, host: 6443 89 | end 90 | 91 | master.vm.provider :virtualbox do |vb| 92 | vb.customize ["modifyvm", :id, "--cpus", 2, "--nictype1", "virtio"] 93 | vb.memory = MASTER_MEMORY 94 | end 95 | 96 | if !BOX_IMAGE.include? "kuberverse" 97 | master.vm.provider "vmware_desktop" do |v| 98 | v.vmx["memsize"] = MASTER_MEMORY 99 | v.vmx["numvcpus"] = "2" 100 | end 101 | end 102 | if ARGV[0] == "destroy" 103 | puts "Deleting .kv directory" 104 | @kvtools.cleanKvDir() 105 | else 106 | @kvtools.addToHosts(ip,master.vm.hostname) 107 | end 108 | $m_script = @kvshell.env(node,ip,master.vm.hostname,$sIPs,$mIPs,$wIPs) + @kvshell.master() 109 | 110 | master.vm.provision "shell", inline: $m_script, keep_color: true 111 | end 112 | end 113 | end 114 | 115 | def createWorker(config) 116 | (0..WORKER_COUNT-1).each do |node| 117 | ip = @kvtools.defineIp("worker",node,KV_LAB_NETWORK) 118 | 119 | puts "The Worker #{node} Ip is #{ip}" 120 | config.vm.define "kv-worker-#{node}" do |worker| 121 | worker.vm.box = BOX_IMAGE 122 | worker.vm.hostname = "kv-worker-#{node}" 123 | worker.vm.network :private_network, ip: ip, nic_type: "virtio" 124 | worker.vm.provider :virtualbox do |vb| 125 | vb.customize ["modifyvm", :id, "--cpus", 2, "--nictype1", "virtio"] 126 | vb.memory = WORKER_MEMORY 127 | end 128 | 129 | if !BOX_IMAGE.include? "kuberverse" 130 | worker.vm.provider "vmware_desktop" do |v| 131 | v.vmx["memsize"] = WORKER_MEMORY 132 | v.vmx["numvcpus"] = "2" 133 | end 134 | end 135 | if ARGV[0] == "destroy" 136 | puts "Deleting .kv directory" 137 | @kvtools.cleanKvDir() 138 | else 139 | @kvtools.addToHosts(ip,worker.vm.hostname) 140 | end 141 | $w_script = @kvshell.env(node,ip,worker.vm.hostname,$sIPs,$mIPs,$wIPs) + @kvshell.worker() 142 | worker.vm.provision "shell", inline: $w_script, keep_color: true 143 | end 144 | end 145 | end 146 | 147 | end -------------------------------------------------------------------------------- /labs/kv-k8s-cluster-ha/Vagrantfile: -------------------------------------------------------------------------------- 1 | # kuberverse kubernetes cluster lab 2 | # version: 0.2.0 3 | # description: this Vagrantfile creates a cluster with masters and workers 4 | # created by Artur Scheiner - artur.scheiner@gmail.com 5 | # dependencies: https://raw.githubusercontent.com/arturscheiner/kuberverse/master/labs/kv-k8s-cluster-ha/common.sh 6 | # https://raw.githubusercontent.com/arturscheiner/kuberverse/master/labs/kv-k8s-cluster-ha/scaler.sh 7 | # https://raw.githubusercontent.com/arturscheiner/kuberverse/master/labs/kv-k8s-cluster-ha/master.sh 8 | # https://raw.githubusercontent.com/arturscheiner/kuberverse/master/labs/kv-k8s-cluster-ha/worker.sh 9 | 10 | # Is not recommended, but you can change the base box. 11 | # This means that all the VMs will use the same image. 12 | # For vmware_desktop provider use 13 | #BOX_IMAGE = "bento/ubuntu-18.04" 14 | # For virtualbox provider you can choose to use 15 | # bento or kuberverse images. The difference is 16 | # that kuberverse images are pre-loaded with 17 | # the packages needed to create the cluster 18 | # that means less time to build the cluster. 19 | BOX_IMAGE = "kuberverse/ubuntu-18.04" 20 | 21 | # Define the k8s version to be used on this lab. 22 | KUBE_VERSION = "1.22.3" 23 | 24 | # Define the container runtime that will be used on 25 | # your lab. From k8s v1.22 the default runtime is containerd. 26 | # You can choose between containerd|docker 27 | CONTAINER_RUNTIME = "containerd" 28 | 29 | # Define CNI Provider 30 | # Choose between calico|weave|flannel 31 | CNI_PROVIDER = "weave" 32 | 33 | # Change these values if you wish to play with the 34 | # cluster size. Do this before starting your cluster 35 | # provisioning. 36 | MASTER_COUNT = 1 37 | WORKER_COUNT = 1 38 | 39 | # Change these values if you wish to play with the 40 | # VMs memory resources. 41 | # Kubernetes pre-flight for the MASTER_NODES now requires 1700+ of memory. 42 | SCALER_MEMORY = 512 43 | MASTER_MEMORY = 2048 44 | WORKER_MEMORY = 1024 45 | 46 | # Change these values if you wish to play with the 47 | # networking settings of your cluster 48 | KV_LAB_NETWORK = "10.8.8.0" 49 | 50 | # This value changes the intra-pod network 51 | POD_CIDR = "172.18.0.0/16" 52 | 53 | 54 | KVMSG = "Kuberverse Kubernetes Cluster Lab" 55 | 56 | COMMON_SCRIPT_URL = "https://raw.githubusercontent.com/arturscheiner/kuberverse/master/labs/kv-k8s-cluster-ha/common.sh" 57 | SCALER_SCRIPT_URL = "https://raw.githubusercontent.com/arturscheiner/kuberverse/master/labs/kv-k8s-cluster-ha/scaler.sh" 58 | MASTER_SCRIPT_URL = "https://raw.githubusercontent.com/arturscheiner/kuberverse/master/labs/kv-k8s-cluster-ha/master.sh" 59 | WORKER_SCRIPT_URL = "https://raw.githubusercontent.com/arturscheiner/kuberverse/master/labs/kv-k8s-cluster-ha/worker.sh" 60 | 61 | def colorize(text, color_code) 62 | "\e[#{color_code}m#{text}\e[0m" 63 | end 64 | 65 | def red(text); colorize(text, 31); end 66 | def green(text); colorize(text, 32); end 67 | def yellow(text); colorize(text, 33); end 68 | def blue(text); colorize(text, 34); end 69 | 70 | class String 71 | def black; "\e[30m#{self}\e[0m" end 72 | def red; "\e[31m#{self}\e[0m" end 73 | def green; "\e[32m#{self}\e[0m" end 74 | def brown; "\e[33m#{self}\e[0m" end 75 | def blue; "\e[34m#{self}\e[0m" end 76 | def magenta; "\e[35m#{self}\e[0m" end 77 | def cyan; "\e[36m#{self}\e[0m" end 78 | def gray; "\e[37m#{self}\e[0m" end 79 | 80 | def bg_black; "\e[40m#{self}\e[0m" end 81 | def bg_red; "\e[41m#{self}\e[0m" end 82 | def bg_green; "\e[42m#{self}\e[0m" end 83 | def bg_brown; "\e[43m#{self}\e[0m" end 84 | def bg_blue; "\e[44m#{self}\e[0m" end 85 | def bg_magenta; "\e[45m#{self}\e[0m" end 86 | def bg_cyan; "\e[46m#{self}\e[0m" end 87 | def bg_gray; "\e[47m#{self}\e[0m" end 88 | 89 | def bold; "\e[1m#{self}\e[22m" end 90 | def italic; "\e[3m#{self}\e[23m" end 91 | def underline; "\e[4m#{self}\e[24m" end 92 | def blink; "\e[5m#{self}\e[25m" end 93 | def reverse_color; "\e[7m#{self}\e[27m" end 94 | end 95 | 96 | class KvLab 97 | 98 | def initialize 99 | puts "********** #{green(KVMSG)} **********" 100 | 101 | checkmark = "\u2713" 102 | puts checkmark.force_encoding('utf-8').green.bold.blink 103 | 104 | puts "---- Provisioned with k8s #{yellow(KUBE_VERSION)}".blue 105 | puts "---- Container runtime is: #{yellow(CONTAINER_RUNTIME)}" 106 | puts "---- CNI Provider is: #{yellow(CNI_PROVIDER)}" 107 | puts "---- #{MASTER_COUNT} Masters Nodes" 108 | puts "---- #{WORKER_COUNT} Worker(s) Node(s)" unless MASTER_COUNT == 5 109 | end 110 | 111 | def defineIp(type,i,kvln) 112 | case type 113 | when "master" 114 | return kvln.split('.')[0..-2].join('.') + ".#{i + 10}" 115 | when "worker" 116 | return kvln.split('.')[0..-2].join('.') + ".#{i + 20}" 117 | when "scaler" 118 | return kvln.split('.')[0..-2].join('.') + ".#{i + 50}" 119 | end 120 | end 121 | 122 | def createScaler(config) 123 | 124 | i = 0 125 | scalerIp = self.defineIp("scaler",i,KV_LAB_NETWORK) 126 | 127 | # if MASTER_COUNT == 1 128 | # p "This is a Single Master Cluster with:" 129 | # p "---- #{MASTER_COUNT} Master Node" 130 | # p "---- #{WORKER_COUNT} Worker(s) Node(s)" 131 | # p "---- Provisioned with Kubernetes v#{KUBE_VERSION}" 132 | # return 133 | # end 134 | 135 | if MASTER_COUNT != 1 136 | puts "---- 1 Scaler Node" 137 | puts "The Scaler #{i} Ip is #{scalerIp}" 138 | end 139 | 140 | masterIps = Array[] 141 | 142 | (0..MASTER_COUNT-1).each do |m| 143 | masterIps.push(self.defineIp("master",m,KV_LAB_NETWORK)) 144 | end 145 | 146 | # p masterIps.length 147 | # masterIps.each {|s| p s} 148 | 149 | config.vm.define "kv-scaler-#{i}" do |scaler| 150 | scaler.vm.box = BOX_IMAGE 151 | scaler.vm.hostname = "kv-scaler-#{i}" 152 | scaler.vm.network :private_network, ip: scalerIp, nic_type: "virtio" 153 | scaler.vm.network "forwarded_port", guest: 6443, host: 6443 154 | 155 | scaler.vm.provider :virtualbox do |vb| 156 | vb.customize ["modifyvm", :id, "--cpus", 2, "--nictype1", "virtio"] 157 | vb.memory = SCALER_MEMORY 158 | end 159 | 160 | if !BOX_IMAGE.include? "kuberverse" 161 | scaler.vm.provider "vmware_desktop" do |v| 162 | v.vmx["memsize"] = SCALER_MEMORY 163 | v.vmx["numvcpus"] = "2" 164 | end 165 | end 166 | 167 | $script = <<-SCRIPT 168 | 169 | echo "# Added by Kuberverse" > /vagrant/hosts.out 170 | echo "#{scalerIp} kv-scaler.lab.local kv-scaler.local kv-master" >> /vagrant/hosts.out 171 | 172 | mkdir -p /home/vagrant/.kv 173 | wget -q #{SCALER_SCRIPT_URL} -O /home/vagrant/.kv/scaler.sh 174 | chmod +x /home/vagrant/.kv/scaler.sh 175 | /home/vagrant/.kv/scaler.sh "#{KVMSG}" #{scalerIp} #{BOX_IMAGE} "#{masterIps}" 176 | SCRIPT 177 | scaler.vm.provision "shell", inline: $script, keep_color: true 178 | end 179 | end 180 | 181 | def createMaster(config) 182 | 183 | (0..MASTER_COUNT-1).each do |i| 184 | masterIp = self.defineIp("master",i,KV_LAB_NETWORK) 185 | 186 | puts "The Master #{i} Ip is #{masterIp}" 187 | config.vm.define "kv-master-#{i}" do |master| 188 | master.vm.box = BOX_IMAGE 189 | master.vm.hostname = "kv-master-#{i}" 190 | master.vm.network :private_network, ip: masterIp, nic_type: "virtio" 191 | 192 | $script = "" 193 | 194 | if MASTER_COUNT == 1 195 | master.vm.network "forwarded_port", guest: 6443, host: 6443 196 | $script = <<-SCRIPT 197 | echo "# Added by Kuberverse" > /vagrant/hosts.out 198 | echo "#{masterIp} kv-master.lab.local kv-master.local kv-master kv-scaler.lab.local" >> /vagrant/hosts.out 199 | SCRIPT 200 | end 201 | 202 | master.vm.provider :virtualbox do |vb| 203 | vb.customize ["modifyvm", :id, "--cpus", 2, "--nictype1", "virtio"] 204 | vb.memory = MASTER_MEMORY 205 | end 206 | 207 | if !BOX_IMAGE.include? "kuberverse" 208 | master.vm.provider "vmware_desktop" do |v| 209 | v.vmx["memsize"] = MASTER_MEMORY 210 | v.vmx["numvcpus"] = "2" 211 | end 212 | end 213 | 214 | $script = $script + <<-SCRIPT 215 | 216 | mkdir -p /home/vagrant/.kv 217 | 218 | wget -q #{COMMON_SCRIPT_URL} -O /home/vagrant/.kv/common.sh 219 | chmod +x /home/vagrant/.kv/common.sh 220 | /home/vagrant/.kv/common.sh "#{KVMSG}" #{BOX_IMAGE} #{KUBE_VERSION} #{CONTAINER_RUNTIME} 221 | 222 | wget -q #{MASTER_SCRIPT_URL} -O /home/vagrant/.kv/master.sh 223 | chmod +x /home/vagrant/.kv/master.sh 224 | /home/vagrant/.kv/master.sh "#{KVMSG}" #{i} #{POD_CIDR} #{masterIp} #{CNI_PROVIDER} #{MASTER_COUNT == 1 ? "single" : "multi"} 225 | SCRIPT 226 | master.vm.provision "shell", inline: $script, keep_color: true 227 | end 228 | end 229 | end 230 | 231 | def createWorker(config) 232 | (0..WORKER_COUNT-1).each do |i| 233 | workerIp = self.defineIp("worker",i,KV_LAB_NETWORK) 234 | 235 | puts "The Worker #{i} Ip is #{workerIp}" 236 | config.vm.define "kv-worker-#{i}" do |worker| 237 | worker.vm.box = BOX_IMAGE 238 | worker.vm.hostname = "kv-worker-#{i}" 239 | worker.vm.network :private_network, ip: workerIp, nic_type: "virtio" 240 | worker.vm.provider :virtualbox do |vb| 241 | vb.customize ["modifyvm", :id, "--cpus", 2, "--nictype1", "virtio"] 242 | vb.memory = WORKER_MEMORY 243 | end 244 | 245 | if !BOX_IMAGE.include? "kuberverse" 246 | worker.vm.provider "vmware_desktop" do |v| 247 | v.vmx["memsize"] = WORKER_MEMORY 248 | v.vmx["numvcpus"] = "2" 249 | end 250 | end 251 | 252 | $script = <<-SCRIPT 253 | 254 | mkdir -p /home/vagrant/.kv 255 | 256 | wget -q #{COMMON_SCRIPT_URL} -O /home/vagrant/.kv/common.sh 257 | chmod +x /home/vagrant/.kv/common.sh 258 | /home/vagrant/.kv/common.sh "#{KVMSG}" #{BOX_IMAGE} #{KUBE_VERSION} #{CONTAINER_RUNTIME} 259 | 260 | wget -q #{WORKER_SCRIPT_URL} -O /home/vagrant/.kv/worker.sh 261 | chmod +x /home/vagrant/.kv/worker.sh 262 | /home/vagrant/.kv/worker.sh "#{KVMSG}" #{i} #{workerIp} #{MASTER_COUNT == 1 ? "single" : "multi"} 263 | SCRIPT 264 | worker.vm.provision "shell", inline: $script, keep_color: true 265 | end 266 | end 267 | end 268 | end 269 | 270 | Vagrant.configure("2") do |config| 271 | 272 | kvlab = KvLab.new() 273 | 274 | if ARGV[0] == "up" or ARGV[0] == "status" or ARGV[0] == "destroy" or ARGV[0] == "ssh" 275 | 276 | if MASTER_COUNT >= 2 277 | kvlab.createScaler(config) 278 | end 279 | 280 | kvlab.createMaster(config) 281 | kvlab.createWorker(config) 282 | 283 | 284 | config.vm.provision "shell", 285 | run: "always", 286 | inline: "swapoff -a" 287 | end 288 | 289 | end 290 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------