#!/bin/bash #author: tmade #version: 1.5 USER="kubernetes" HOME="/home/${USER}" CALICO="/home/kubernetes/calico" #filename such as "calico-v3.11.2.yaml" expected CALICOVERS="v3.11.2" KUBEHOME="${HOME}/.kube" #CIDR="10.0.0.5" DASBOARD="/home/kubernetes/dashboard" # filename such as "kubernetes-dashboard-v2.0.0-rc5.yaml" expected DASHVERS="v2.0.1" PODNETWORKADDON="192.168.0.0/16" echo "" echo "Setup -------------k8s--------------" echo "" su - kubernetes -c "kubectl version 2> /dev/null" echo "" su - kubernetes -c "read -s -n 1 -p \"Press any key to continue . . .\"" apt-get update apt-cache policy kubeadm | head -n 30 #apt-cache policy docker-ce echo "" read -p "Please enter k8s version you want to install (e. g. \"1.16.4-00\"): " VERSION echo "Version: \"$VERSION\" will be installed!" apt-mark unhold kubernetes-cni kubeadm kubelet kubectl docker-ce #apt-mark unhold kubernetes-cni kubeadm kubelet kubectl docker-ce apt-get install -y kubeadm=${VERSION} kubelet=${VERSION} kubectl=${VERSION} echo "" read -p "Please enter your CIDR management ip-adress for your master (e. g. \"10.6.33.10\"): " CIDR echo "" echo "ip set to: \"$CIDR\"" echo "" kubeadm init --apiserver-advertise-address=${CIDR} --pod-network-cidr=${PODNETWORKADDON} echo "" read -s -n 1 -p "Press any key to continue . . ." echo "" if [ -e ${KUBEHOME} ] then echo "\"${KUBEHOME}\" exists" read -p "Do you want to delete \"${KUBEHOME}\"? Please enter y (proceed) or n (stop): " PROCEED echo "You´ve entered: \"$PROCEED\"" echo "" if [ $PROCEED = y ] then rm -r ${KUBEHOME} echo "\"${KUBEHOME}\" deleted!" echo "" read -s -n 1 -p "Press any key to continue . . ." else exit 1 fi fi su - ${USER} -c "mkdir -p $HOME/.kube" su - ${USER} -c "sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config" chown -R ${USER}:${USER} $HOME/.kube echo "" echo "home \"$HOME/.kube\" copied!" echo "" read -s -n 1 -p "Press any key to continue . . ." #calico pod-network-addon #su - kubernetes -c "kubectl apply -f /home/kubernetes/calico/${CALICOVERS}/rbac-kdd.yaml" #su - kubernetes -c "kubectl apply -f /home/kubernetes/calico/${CALICOVERS}/calico.yaml" su - kubernetes -c "kubectl apply -f ${CALICO}/calico-${CALICOVERS}.yaml" echo "" echo "calico pod network add on has been deployed" echo "" read -s -n 1 -p "Press any key to continue . . ." #install dashboard su - kubernetes -c "kubectl apply -f ${DASBOARD}/kubernetes-dashboard-${DASHVERS}.yaml" echo "" echo "dashboard has been deployed" echo "" read -s -n 1 -p "Press any key to continue . . ." apt-mark hold kubernetes-cni kubeadm kubelet kubectl docker-ce echo "" while [ -z $SCHEDULE ] ; do read -p "Do you want to schedule pods on your master? Please enter \"y\" or \"n\": " SCHEDULE echo "Please enter \"y\" or \"n\"" done echo "" echo "You´ve entered: \"$SCHEDULE\"" echo "" if [ $SCHEDULE = y ] then kubectl taint nodes $(hostname) node-role.kubernetes.io/master- fi echo "" echo "Status - please press \"ctrl + c\" when all pods are running" echo "" watch kubectl get pods -A -o wide