k8x/init.sh

158 lines
4 KiB
Bash
Raw Permalink Normal View History

2024-05-17 21:45:52 -04:00
#!/bin/bash
HOME=$( cd "$(dirname "$0")" && pwd )
source $HOME/config
export KUBECONFIG=$ADMIN_KUBECONFIG
# checks if we have the cryptopack file
if [ -f $HOME/cryptopack.b64 ]; then
echo "] cryptopack.b64 FOUND :)"
else
echo "] cryptopack.b64 is not found."
exit 0
fi
# checks if we have the necessary config files
if [ -f $HOME/config ]; then
echo "] config file FOUND :)"
else
echo "] config file is missing."
exit 0
fi
if [ -f $HOME/config-coreapps ]; then
echo "] config-coreapps file FOUND :)"
else
echo "] config-coreapps file is missing."
exit 1
fi
# checks if we have a system with nftables and revert it to iptables-legacy since docker doesnt deal with it yet.
OS_RELEASE=`lsb_release -cs`
if [ "$OS_RELEASE" = "buster" ]; then
if [ `readlink /etc/alternatives/iptables` == "/usr/sbin/iptables-nft" ]; then
update-alternatives --set iptables /usr/sbin/iptables-legacy
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
update-alternatives --set arptables /usr/sbin/arptables-legacy
update-alternatives --set ebtables /usr/sbin/ebtables-legacy
systemctl mask nftables.service
echo "] PLEASE REBOOT FOR THIS CHANGES TO TAKE EFFECT."
exit
else
echo "] iptables seems to point to iptables-legacy. :)"
fi
fi
#this one could be done better for sure...
case "${NODE_NAME_SHORT}" in
${MASTER_1_NAME})
NODETYPE='controller'
NODEIP=${MASTER_1_IP}
;;
${MASTER_2_NAME})
NODETYPE='controller'
NODEIP=${MASTER_2_IP}
;;
${MASTER_3_NAME})
NODETYPE='controller'
NODEIP=${MASTER_3_IP}
;;
${NODE_1_NAME})
NODETYPE='worker'
NODEIP=${NODE_1_IP}
;;
${NODE_2_NAME})
NODETYPE='worker'
NODEIP=${NODE_2_IP}
;;
${NODE_3_NAME})
NODETYPE='worker'
NODEIP=${NODE_3_IP}
;;
${NODE_4_NAME})
NODETYPE='worker'
NODEIP=${NODE_4_IP}
;;
${NODE_5_NAME})
NODETYPE='worker'
NODEIP=${NODE_5_IP}
;;
${NODE_6_NAME})
NODETYPE='worker'
NODEIP=${NODE_6_IP}
;;
${NODE_7_NAME})
NODETYPE='worker'
NODEIP=${NODE_7_IP}
;;
${NODE_8_NAME})
NODETYPE='worker'
NODEIP=${NODE_8_IP}
;;
${NODE_9_NAME})
NODETYPE='worker'
NODEIP=${NODE_9_IP}
;;
${NODE_10_NAME})
NODETYPE='worker'
NODEIP=${NODE_10_IP}
;;
${NODE_11_NAME})
NODETYPE='worker'
NODEIP=${NODE_11_IP}
;;
${NODE_12_NAME})
NODETYPE='worker'
NODEIP=${NODE_12_IP}
;;
${NODE_13_NAME})
NODETYPE='worker'
NODEIP=${NODE_13_IP}
;;
${NODE_14_NAME})
NODETYPE='worker'
NODEIP=${NODE_14_IP}
;;
${NODE_15_NAME})
NODETYPE='worker'
NODEIP=${NODE_15_IP}
;;
*)
echo '] Node hostname not defined.'
exit 0
;;
esac
echo "... ] SETTING UP ${NODETYPE} NODE ${NODE_NAME_SHORT} WITH ${NODEIP} [ ..."
echo "] Setting up base ..."
/bin/bash $FUNC_PATH/init_hostname.sh
/bin/bash $FUNC_PATH/init_metal.sh
/bin/bash $FUNC_PATH/install_docker.sh
/bin/bash $FUNC_PATH/install_chrony.sh
/bin/bash ssl/install_kube_crypto.sh
/bin/bash ssl/create_admin.sh
if [ "$NODETYPE" == "controller" ]; then
echo "] Setting up master ..."
/bin/bash ssl/create_master.sh
/bin/bash $FUNC_PATH/install_etcd.sh
/bin/bash $FUNC_PATH/install_kube_apiserver.sh
/bin/bash $FUNC_PATH/install_kube_scheduler.sh
/bin/bash $FUNC_PATH/install_kube_controller_manager.sh
#/bin/bash $FUNC_PATH/install_kube_keepalived.sh
/bin/bash $FUNC_PATH/install_k8x_api.sh
fi
echo "] Setting up kube-api localhost loadbalacing ..."
/bin/bash $FUNC_PATH/install_kube_haproxy.sh
echo "] Setting up worker ..."
/bin/bash ssl/create_worker.sh
/bin/bash $FUNC_PATH/install_kubelet.sh
/bin/bash $FUNC_PATH/install_kube_proxy.sh
#label node
kubectl label nodes ${NODE_NAME_SHORT} nodetype=${NODETYPE} --overwrite
echo "... ] DONE :) [ ..."