forked from loxilb-io/loxilb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'loxilb-io:main' into main
- Loading branch information
Showing
26 changed files
with
947 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# -*- mode: ruby -*- | ||
# vi: set ft=ruby : | ||
|
||
require "yaml" | ||
settings = YAML.load_file "yaml/settings.yaml" | ||
|
||
workers = settings["nodes"]["workers"]["count"] | ||
loxilbs = (ENV['LOXILBS'] || "2").to_i | ||
|
||
Vagrant.configure("2") do |config| | ||
|
||
if Vagrant.has_plugin?("vagrant-vbguest") | ||
config.vbguest.auto_update = false | ||
end | ||
|
||
(1..loxilbs).each do |node_number| | ||
config.vm.define "llb#{node_number}" do |loxilb| | ||
loxilb.vm.box = settings["software"]["loxilb"]["box"]["name"] | ||
loxilb.vm.box_version = settings["software"]["loxilb"]["box"]["version"] | ||
loxilb.vm.hostname = "llb#{node_number}" | ||
ip = node_number + 251 | ||
loxilb.vm.network :private_network, ip: "192.168.80.#{ip}", :netmask => "255.255.255.0" | ||
loxilb.vm.provision :shell, :path => "node_scripts/loxilb.sh" | ||
loxilb.vm.provider :virtualbox do |vbox| | ||
vbox.customize ["modifyvm", :id, "--memory", 6000] | ||
vbox.customize ["modifyvm", :id, "--cpus", 4] | ||
vbox.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"] | ||
end | ||
end | ||
end | ||
|
||
config.vm.define "master" do |master| | ||
master.vm.box = settings["software"]["cluster"]["box"] | ||
master.vm.hostname = 'master' | ||
master.vm.network :private_network, ip: settings["network"]["control_ip"], :netmask => "255.255.255.0" | ||
master.vm.provision "shell", | ||
env: { | ||
"DNS_SERVERS" => settings["network"]["dns_servers"].join(" "), | ||
"ENVIRONMENT" => settings["environment"], | ||
"KUBERNETES_VERSION" => settings["software"]["kubernetes"], | ||
"OS" => settings["software"]["os"] | ||
}, | ||
path: "node_scripts/common.sh" | ||
master.vm.provision "shell", | ||
env: { | ||
"CALICO_VERSION" => settings["software"]["calico"], | ||
"CONTROL_IP" => settings["network"]["control_ip"], | ||
"POD_CIDR" => settings["network"]["pod_cidr"], | ||
"SERVICE_CIDR" => settings["network"]["service_cidr"] | ||
}, | ||
path: "node_scripts/master.sh" | ||
|
||
master.vm.provider :virtualbox do |vbox| | ||
vbox.customize ["modifyvm", :id, "--memory", 4096] | ||
vbox.customize ["modifyvm", :id, "--cpus", 2] | ||
vbox.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"] | ||
end | ||
end | ||
|
||
(1..workers).each do |node_number| | ||
config.vm.define "worker#{node_number}" do |worker| | ||
worker.vm.box = settings["software"]["cluster"]["box"] | ||
worker.vm.hostname = "worker#{node_number}" | ||
ip = node_number + 200 | ||
worker.vm.network :private_network, ip: "192.168.80.#{ip}", :netmask => "255.255.255.0" | ||
worker.vm.provision "shell", | ||
env: { | ||
"DNS_SERVERS" => settings["network"]["dns_servers"].join(" "), | ||
"ENVIRONMENT" => settings["environment"], | ||
"KUBERNETES_VERSION" => settings["software"]["kubernetes"], | ||
"OS" => settings["software"]["os"] | ||
}, | ||
path: "node_scripts/common.sh" | ||
worker.vm.provision "shell", path: "node_scripts/worker.sh" | ||
|
||
worker.vm.provider :virtualbox do |vbox| | ||
vbox.customize ["modifyvm", :id, "--memory", 4096] | ||
vbox.customize ["modifyvm", :id, "--cpus", 2] | ||
vbox.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
VMs=$(vagrant global-status | grep -i virtualbox) | ||
while IFS= read -a VMs; do | ||
read -a vm <<< "$VMs" | ||
cd ${vm[4]} 2>&1>/dev/null | ||
echo "Destroying ${vm[1]}" | ||
vagrant destroy -f ${vm[1]} | ||
cd - 2>&1>/dev/null | ||
done <<< "$VMs" | ||
|
||
vagrant up | ||
|
||
for((i=1; i<=60; i++)) | ||
do | ||
fin=1 | ||
pods=$(vagrant ssh master -c 'kubectl get pods -A' 2> /dev/null | grep -v "NAMESPACE") | ||
|
||
while IFS= read -a pods; do | ||
read -a pod <<< "$pods" | ||
if [[ ${pod[3]} != *"Running"* ]]; then | ||
echo "${pod[1]} is not UP yet" | ||
fin=0 | ||
fi | ||
done <<< "$pods" | ||
if [ $fin == 1 ]; | ||
then | ||
break; | ||
fi | ||
echo "Will try after 10s" | ||
sleep 10 | ||
done | ||
|
||
sudo sysctl net.ipv4.conf.vboxnet1.arp_accept=1 | ||
|
||
#Create fullnat Service | ||
vagrant ssh master -c 'kubectl apply -f /vagrant/yaml/tcp_fullnat.yml' 2> /dev/null | ||
vagrant ssh master -c 'kubectl apply -f /vagrant/yaml/udp_fullnat.yml' 2> /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/bin/bash | ||
# | ||
# Common setup for all servers (Control Plane and Nodes) | ||
|
||
set -euxo pipefail | ||
|
||
# Variable Declaration | ||
|
||
# DNS Setting | ||
if [ ! -d /etc/systemd/resolved.conf.d ]; then | ||
sudo mkdir /etc/systemd/resolved.conf.d/ | ||
fi | ||
cat <<EOF | sudo tee /etc/systemd/resolved.conf.d/dns_servers.conf | ||
[Resolve] | ||
DNS=${DNS_SERVERS} | ||
EOF | ||
|
||
sudo systemctl restart systemd-resolved | ||
|
||
# disable swap | ||
sudo swapoff -a | ||
|
||
# keeps the swap off during reboot | ||
(crontab -l 2>/dev/null; echo "@reboot /sbin/swapoff -a") | crontab - || true | ||
sudo apt-get update -y | ||
# Install CRI-O Runtime | ||
|
||
VERSION="$(echo ${KUBERNETES_VERSION} | grep -oE '[0-9]+\.[0-9]+')" | ||
|
||
# Create the .conf file to load the modules at bootup | ||
cat <<EOF | sudo tee /etc/modules-load.d/crio.conf | ||
overlay | ||
br_netfilter | ||
EOF | ||
|
||
sudo modprobe overlay | ||
sudo modprobe br_netfilter | ||
|
||
# Install ipvs related modules | ||
sudo modprobe ip_vs | ||
sudo modprobe ip_vs_rr | ||
sudo modprobe ip_vs_wrr | ||
sudo modprobe ip_vs_sh | ||
#sudo modprobe nf_conntrack_ipv4 | ||
|
||
sudo sysctl net.ipv4.vs.sloppy_sctp=1 | ||
|
||
# Set up required sysctl params, these persist across reboots. | ||
cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf | ||
net.bridge.bridge-nf-call-iptables = 1 | ||
net.ipv4.ip_forward = 1 | ||
net.bridge.bridge-nf-call-ip6tables = 1 | ||
EOF | ||
|
||
sudo sysctl --system | ||
|
||
cat <<EOF | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list | ||
deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/ / | ||
EOF | ||
cat <<EOF | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$VERSION.list | ||
deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$VERSION/$OS/ / | ||
EOF | ||
|
||
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$VERSION/$OS/Release.key | sudo apt-key --keyring /etc/apt/trusted.gpg.d/libcontainers.gpg add - | ||
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/Release.key | sudo apt-key --keyring /etc/apt/trusted.gpg.d/libcontainers.gpg add - | ||
|
||
sudo apt-get update | ||
sudo apt-get install cri-o cri-o-runc -y | ||
|
||
cat >> /etc/default/crio << EOF | ||
${ENVIRONMENT} | ||
EOF | ||
sudo systemctl daemon-reload | ||
sudo systemctl enable crio --now | ||
|
||
echo "CRI runtime installed successfully" | ||
|
||
sudo apt-get update | ||
sudo apt-get install -y apt-transport-https ca-certificates curl | ||
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-archive-keyring.gpg | ||
|
||
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list | ||
sudo apt-get update -y | ||
sudo apt-get install -y kubelet="$KUBERNETES_VERSION" kubectl="$KUBERNETES_VERSION" kubeadm="$KUBERNETES_VERSION" | ||
sudo apt-get update -y | ||
sudo apt-get install -y jq | ||
sudo apt-get install -y ipvsadm | ||
|
||
local_ip="$(ip --json a s | jq -r '.[] | if .ifname == "eth1" then .addr_info[] | if .family == "inet" then .local else empty end else empty end')" | ||
cat > /etc/default/kubelet << EOF | ||
KUBELET_EXTRA_ARGS=--node-ip=$local_ip | ||
${ENVIRONMENT} | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export LOXILB_IP=$(ip a |grep global | grep -v '10.0.2.15' | grep -v '192.168.80' | awk '{print $2}' | cut -f1 -d '/') | ||
|
||
apt-get update | ||
apt-get install -y software-properties-common | ||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | ||
add-apt-repository -y "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | ||
apt-get update | ||
apt-get install -y docker-ce | ||
docker run -u root --cap-add SYS_ADMIN --restart unless-stopped --privileged -dit -v /dev/log:/dev/log --net=host --name loxilb ghcr.io/loxilb-io/loxilb:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/bash | ||
# | ||
# Setup for Control Plane (Master) servers | ||
|
||
set -euxo pipefail | ||
|
||
NODENAME=$(hostname -s) | ||
|
||
sudo kubeadm config images pull | ||
|
||
echo "Preflight Check Passed: Downloaded All Required Images" | ||
|
||
#sudo kubeadm init --apiserver-advertise-address=$CONTROL_IP --apiserver-cert-extra-sans=$CONTROL_IP --pod-network-cidr=$POD_CIDR --service-cidr=$SERVICE_CIDR --node-name "$NODENAME" --ignore-preflight-errors Swap | ||
sudo kubeadm init --ignore-preflight-errors Swap --config /vagrant/yaml/kubeadm-config.yaml | ||
|
||
mkdir -p "$HOME"/.kube | ||
sudo cp -i /etc/kubernetes/admin.conf "$HOME"/.kube/config | ||
sudo chown "$(id -u)":"$(id -g)" "$HOME"/.kube/config | ||
|
||
# Save Configs to shared /Vagrant location | ||
|
||
# For Vagrant re-runs, check if there is existing configs in the location and delete it for saving new configuration. | ||
|
||
config_path="/vagrant/configs" | ||
|
||
if [ -d $config_path ]; then | ||
rm -f $config_path/* | ||
else | ||
mkdir -p $config_path | ||
fi | ||
|
||
cp -i /etc/kubernetes/admin.conf $config_path/config | ||
touch $config_path/join.sh | ||
chmod +x $config_path/join.sh | ||
|
||
kubeadm token create --print-join-command > $config_path/join.sh | ||
|
||
# Install Calico Network Plugin | ||
|
||
curl https://raw.githubusercontent.com/projectcalico/calico/v${CALICO_VERSION}/manifests/calico.yaml -O | ||
|
||
kubectl apply -f calico.yaml | ||
|
||
sudo -i -u vagrant bash << EOF | ||
whoami | ||
mkdir -p /home/vagrant/.kube | ||
sudo cp -i $config_path/config /home/vagrant/.kube/ | ||
sudo chown 1000:1000 /home/vagrant/.kube/config | ||
EOF | ||
|
||
# Install Metrics Server | ||
|
||
kubectl apply -f https://raw.githubusercontent.com/techiescamp/kubeadm-scripts/main/manifests/metrics-server.yaml | ||
|
||
# Install loxilb | ||
kubectl apply -f /vagrant/yaml/kube-loxilb.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
# | ||
# Setup for Node servers | ||
|
||
set -euxo pipefail | ||
|
||
config_path="/vagrant/configs" | ||
|
||
/bin/bash $config_path/join.sh -v | ||
|
||
sudo -i -u vagrant bash << EOF | ||
whoami | ||
mkdir -p /home/vagrant/.kube | ||
sudo cp -i $config_path/config /home/vagrant/.kube/ | ||
sudo chown 1000:1000 /home/vagrant/.kube/config | ||
NODENAME=$(hostname -s) | ||
kubectl label node $(hostname -s) node-role.kubernetes.io/worker=worker | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
vagrant destroy -f worker2 | ||
vagrant destroy -f worker1 | ||
vagrant destroy -f master | ||
vagrant destroy -f llb1 | ||
vagrant destroy -f llb2 |
Oops, something went wrong.