#!/bin/bash #author: tmade #version: 1.1 #kubernetes user name USER="kubernetes" HOME="/home/${USER}" KUBEHOME="${HOME}/.kube" #CIDR="10.0.0.5" PODNETWORKADDON="192.168.0.0/16" read -p "Do you want to create the user ${USER}? Please enter \"y\" or \"n\: " MYUSER echo "" if [ ${MYUSER,,} == "y" ] then useradd -s /bin/bash -m ${USER} fi sudo -lU ${USER} > /dev/null 2>&1 RESULT=$? if [ "${RESULT}" -ne "0" ] ; then echo "User "${USER}" does not exist in sudoers and will be added." echo "${USER} ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers else echo "User "${USER}" already exists in sudoers - won´t be added again!" fi echo "" echo "Setup -------------k8s--------------" echo "" su - ${USER} -c "kubectl version 2> /dev/null" echo "" su - ${USER} -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.23.3-00\"): " VERSION echo "Version: \"$VERSION\" will be installed!" 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 echo "Creating folder structure..." echo "" 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 . . ." echo "" echo "Creating calico pod network addon..." echo "" su - ${USER} -c "kubectl create -f https://projectcalico.docs.tigera.io/manifests/tigera-operator.yaml" su - ${USER} -c "kubectl create -f https://projectcalico.docs.tigera.io/manifests/custom-resources.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 - ${USER} -c "kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.0/aio/deploy/recommended.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