Skip to content

Commit

Permalink
Merge pull request #9 from coolsvap/1.21
Browse files Browse the repository at this point in the history
Update to 1.21 for Ubuntu
  • Loading branch information
Swapnil Kulkarni authored May 25, 2021
2 parents 0bb309b + acb2eec commit 44d408e
Show file tree
Hide file tree
Showing 11 changed files with 378 additions and 221 deletions.
81 changes: 0 additions & 81 deletions CentOS/Vagrantfile

This file was deleted.

22 changes: 0 additions & 22 deletions CentOS/install-centos.sh

This file was deleted.

56 changes: 56 additions & 0 deletions Master/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
BOX_IMAGE = "generic/ubuntu1804"
SETUP_MASTER = true
MASTER_IP = "192.168.26.10"
POD_NW_CIDR = "10.244.0.0/16"
KUBE_VERSION="1.21.1"

$kubemasterscript = <<SCRIPT
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`
### init k8s
kubeadm init --apiserver-advertise-address=${HOST_IP} --kubernetes-version=#{KUBE_VERSION} --pod-network-cidr=#{POD_NW_CIDR} --skip-token-print
ip route add 10.96.0.0/16 dev eth1 src ${HOST_IP}
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl taint nodes --all node-role.kubernetes.io/master-
kubectl create -f https://docs.projectcalico.org/manifests/tigera-operator.yaml
kubectl create -f https://docs.projectcalico.org/manifests/custom-resources.yaml
echo
echo "### COMMAND TO ADD A WORKER NODE ###"
kubeadm token create --print-join-command --ttl 0
SCRIPT

Vagrant.configure("2") do |config|
config.vm.box = BOX_IMAGE
config.vm.box_check_update = false

config.vm.provider "virtualbox" do |l|
l.cpus = 2
l.memory = "4096"
end

config.vm.provision :shell, :path => "install-master.sh"

config.hostmanager.enabled = true
config.hostmanager.manage_guest = true
# config.vm.network "public_network"

if SETUP_MASTER
config.vm.define "master" do |subconfig|
subconfig.vm.hostname = "master"
subconfig.vm.network :private_network, ip: MASTER_IP
subconfig.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--cpus", "2"]
vb.customize ["modifyvm", :id, "--memory", "4096"]
end
subconfig.vm.provision :shell, inline: $kubemasterscript
end
end
end
65 changes: 65 additions & 0 deletions Master/install-master.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/sh
# Use this script to setup any node in your Kuberntes cluster
# Either master or worker
# Source: http://kubernetes.io/docs/getting-started-guides/kubeadm/

### setup terminal
KUBE_VERSION=1.21.1
### Setting up background to operate Kubernetes
echo 'colorscheme ron' >> ~/.vimrc
echo 'set tabstop=2' >> ~/.vimrc
echo 'set shiftwidth=2' >> ~/.vimrc
echo 'set expandtab' >> ~/.vimrc
echo 'source <(kubectl completion bash)' >> ~/.bashrc
echo 'alias k=kubectl' >> ~/.bashrc
echo 'alias c=clear' >> ~/.bashrc
echo 'complete -F __start_kubectl k' >> ~/.bashrc
sed -i '1s/^/force_color_prompt=yes\n/' ~/.bashrc

#Turn off Swap
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
swapoff -a

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

apt-get update
apt-get install wget apt-transport-https gnupg lsb-release -y

curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF > /etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF

### install k8s and docker
apt-get remove -y docker.io kubelet kubeadm kubectl kubernetes-cni docker-ce
apt-get autoremove -y
systemctl daemon-reload

apt-get update -y
apt-get -y install linux-headers-$(uname -r)
apt-get install -y etcd-client vim build-essential bash-completion binutils apparmor-utils docker.io kubelet=${KUBE_VERSION}-00 kubeadm=${KUBE_VERSION}-00 kubectl=${KUBE_VERSION}-00 kubernetes-cni=0.8.7-00

cat > /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"storage-driver": "overlay2"
}
EOF
mkdir -p /etc/systemd/system/docker.service.d

# Restart docker.
systemctl daemon-reload
systemctl restart docker

# start docker on reboot
systemctl enable docker

docker info | grep -i "storage"
docker info | grep -i "cgroup"

systemctl enable kubelet && systemctl start kubelet

#Pull images
kubeadm config images pull
28 changes: 10 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# kubeadm-vagrant
Setup Kubernetes Cluster with Kubeadm and Vagrant
# Setup Kubernetes Cluster with Kubeadm and Vagrant

Introduction
## Introduction

With reference to steps listed at [Using kubeadm to Create a Cluster](https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/) for setting up the Kubernetes cluster with kubeadm. I have been working on an automation to setup the cluster. The result of it is [kubeadm-vagrant](https://github.com/coolsvap/kubeadm-vagrant), a github project with simple steps to setup your kubernetes cluster with more control on vagrant based virtual machines.

Installation
### Installation
- Download and install [Vagrant](https://www.vagrantup.com/) specific to your OS

- Clone the kubeadm-vagrant repo
- Clone the [kubeadm-vagrant](https://github.com/coolsvap/kubeadm-vagrant) repo

```git clone https://github.com/coolsvap/kubeadm-vagrant ```
``` git clone https://github.com/coolsvap/kubeadm-vagrant ```

- For setting up Master/Worker nodes move to specific directories.

- Choose your distribution of choice from CentOS/Ubuntu and move to the specific directory.
- Configure the cluster parameters in Vagrantfile. Refer below for details of configuration options.

``` vi Vagrantfile ```
Expand All @@ -23,24 +24,15 @@ Installation
- This will spin up new Kubernetes cluster. You can check the status of cluster with following command,

```
sudo su
vagrant ssh
kubectl get pods --all-namespaces
```
Cluster Configuration Options

1. You need to generate a KUBETOKEN of your choice to be used while creating the cluster. You will need to install kubeadm package on your host to create the token with following command

```
# kubeadm token generate
148a37.736fd53655b767b7
```
1. ``` BOX_IMAGE ``` is currently default with &quot;coolsvap/centos-k8s&quot; box which is custom box created which can be used for setting up the cluster with basic dependencies for kubernetes node.
1. ``` BOX_IMAGE ``` is currently default with &quot;generic/ubuntu1804&quot; box which is custom box created which can be used for setting up the cluster with basic dependencies for kubernetes node.
2. Set ``` SETUP_MASTER ``` to true if you want to setup the node. This is true by default for spawning a new cluster. You can skip it for adding new minions.
3. Set ``` SETUP_NODES ``` to true/false depending on whether you are setting up minions in the cluster.
4. Specify ``` NODE_COUNT ``` as the count of minions in the cluster
5. Specify the ``` MASTER_IP ``` as static IP which can be referenced for other cluster configurations
6. Specify ``` NODE_IP_NW ``` as the network IP which can be used for assigning dynamic IPs for cluster nodes from the same network as Master
7. Specify custom ``` POD_NW_CIDR ``` of your choice
8. Setting up kubernetes dashboard is still a WIP with ``` K8S_DASHBOARD ``` option.
69 changes: 0 additions & 69 deletions Ubuntu/Vagrantfile

This file was deleted.

31 changes: 0 additions & 31 deletions Ubuntu/install-ubuntu.sh

This file was deleted.

Loading

0 comments on commit 44d408e

Please sign in to comment.