read  -p "Voy a quitar swap. Pulsa ENTER para seguir:" mainmenuinput

# disable swap

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

read  -p "Cargar kernel modules. Pulsa ENTER para seguir:" mainmenuinput

# Load the following kernel modules on all the nodes

sudo tee /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF

sudo modprobe overlay
sudo modprobe br_netfilter

read  -p "Parametros del kernel. Pulsa ENTER para seguir:" mainmenuinput

# Set the following Kernel parameters for Kubernetes

sudo tee /etc/sysctl.d/kubernetes.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF

# Reload the above changes

sudo sysctl --system

read  -p "Instalar dependencias de containerd. Pulsa ENTER para seguir:" mainmenuinput

# Install containerd run time
# dependencies

sudo apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates

read  -p "Enable docker repository. Pulsa ENTER para seguir:" mainmenuinput

# Enable docker repository

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/docker.gpg

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"


read  -p "Instalar containerd. Pulsa ENTER para seguir:" mainmenuinput

# install containerd

sudo apt update
sudo apt install -y containerd.io

read  -p "Configurar containerd. Pulsa ENTER para seguir:" mainmenuinput

# Configure containerd so that it starts using systemd as cgroup.

containerd config default | sudo tee /etc/containerd/config.toml >/dev/null 2>&1
sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml

read  -p "Enable containerd. Pulsa ENTER para seguir:" mainmenuinput

# Restart and enable containerd service

sudo systemctl restart containerd
sudo systemctl enable containerd

read  -p "Añade repository de Kubernetes. Pulsa ENTER para seguir:" mainmenuinput

# Add apt repository for Kubernetes

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"

# Install Kubernetes components Kubectl, kubeadm & kubelet
read  -p "Instalar componentes de kubernetes. Pulsa ENTER para seguir:" mainmenuinput


sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
