Skip to content

Commit

Permalink
Added master and worker scripts as part of node
Browse files Browse the repository at this point in the history
  • Loading branch information
coolsvap committed May 27, 2021
1 parent 4fc9d5a commit de36538
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 22 deletions.
13 changes: 2 additions & 11 deletions .env
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
BOX_IMAGE="coolsvap/k8s-node"
BOX_IMAGE="generic/ubuntu1804"
PROVIDER="virtualbox"
KUBE_VERSION="1.21.1"
NW_PLUGIN="calico"

SETUP_MASTER=true
MASTER_IP="172.16.26.10"
POD_NW_CIDR="192.168.0.0/16"
MASTER_HOSTNAME="k8s-master"
MASTER_MEMORY="4096"
MASTER_CPU="2"

NODE_MEMORY="2048"
NODE_CPU="1"
HOSTNAME="k8s-node"



Expand Down
15 changes: 5 additions & 10 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ Vagrant.configure("2") do |config|
l.memory = ENV["NODE_MEMORY"]
end

config.vm.synced_folder ".", "/vagrant"
config.vm.provision :shell, :path => "install-node.sh"
config.hostmanager.enabled = true
config.hostmanager.manage_guest = true
# config.vm.network "public_network"
config.vm.provision :file, source: './master.sh', destination: "/opt"

if ENV["SETUP_MASTER"]
config.vm.define ENV["MASTER_HOSTNAME"] do |subconfig|
subconfig.vm.hostname = ENV["MASTER_HOSTNAME"]
subconfig.vm.network :private_network, ip: ENV["MASTER_IP"]
subconfig.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--cpus", ENV["MASTER_CPU"]]
vb.customize ["modifyvm", :id, "--memory", ENV["MASTER_MEMORY"]]
end
end
config.vm.define ENV["HOSTNAME"] do |subconfig|
subconfig.vm.hostname = ENV["HOSTNAME"]
end
end

6 changes: 5 additions & 1 deletion install-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,9 @@ systemctl enable kubelet && systemctl start kubelet
#Pull images
kubeadm config images pull

apt-get clean && apt-get autoremove -yes
apt-get clean && apt-get autoremove -y

mkdir -p /etc/k8s-scripts
cp /vagrant/master.sh -p /etc/k8s-scripts/
cp /vagrant/worker.sh -p /etc/k8s-scripts/
cat /dev/null > ~/bash_history && history -c
26 changes: 26 additions & 0 deletions master.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
# Use this script to initialize master

kubeadm reset -f
rm -rf ~/.kube /etc/cni/net.d /etc/kubernetes /var/lib/etcd /var/lib/kubelet /var/run/kubernetes /var/lib/cni /opt/cni
iptables -F

HOST_IP=`/sbin/ifconfig eth1 | egrep -o 'inet [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | cut -d' ' -f2`
ip route add 10.96.0.0/16 dev eth1 src ${HOST_IP}

### init k8s
kubeadm init --apiserver-advertise-address=${HOST_IP} --kubernetes-version=${KUBE_VERSION} --pod-network-cidr=${POD_NW_CIDR} --skip-token-print

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

cp -R $HOME/.kube /vagrant/

kubectl taint nodes --all node-role.kubernetes.io/master-
case $NW_PLUGIN in
"weave" ) kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')" ;;
"calico" ) kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml ;;
*) echo "Running default with calico" && kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml ;;
esac
kubeadm token create --print-join-command --ttl 0 > /etc/.vagrantdata/kubeadm-join
10 changes: 10 additions & 0 deletions worker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

kubeadm reset -f
rm -rf ~/.kube /etc/cni/net.d /etc/kubernetes /var/lib/etcd /var/lib/kubelet /var/run/kubernetes /var/lib/cni
iptables -F

HOST_IP=`/sbin/ifconfig eth1 | egrep -o 'inet [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | cut -d' ' -f2`
ip route add 10.96.0.0/16 dev eth1 src ${HOST_IP}

$(cat /etc/.vagrantdata/kubeadm-join)

0 comments on commit de36538

Please sign in to comment.