2 # shellcheck source=/dev/null
4 # For host setup as Kubernetes master
5 # Use the src of the default route as the default local IP
6 DEF_SRC_IP=$(ip route get 8.8.8.8 | awk '{ for (nn=1;nn<=NF;nn++) if ($nn~"src") print $(nn+1) }')
7 MGMT_IP=${1:-${DEF_SRC_IP}}
8 MGMT_HOST=$(nslookup $MGMT_IP | grep "in-addr.arpa" | cut -d " " -f 3 | awk '{ print substr( $0, 1, length($0)-1 ) }') || true
9 #MGMT_HOST=$(nslookup $MGMT_IP | grep "in-addr.arpa" | cut -d " " -f 3 | sed 's/.$//') || true
12 POD_NETWORK_CIDR=${2:-192.168.0.0/16}
13 SERVICE_CIDR=${3:-172.16.1.0/24}
15 if [ -z "${MGMT_IP}" ]; then
16 echo "Please specify a management IP!"
20 if [ -z "${MGMT_HOST}" ]; then
21 echo "MGMT HOST is not set, using MGMT_IP instead."
25 if ! kubectl get nodes --request-timeout=3s; then
26 sudo kubeadm config images pull
28 --pod-network-cidr="${POD_NETWORK_CIDR}" \
29 --apiserver-advertise-address="${MGMT_IP}" \
30 --service-cidr="${SERVICE_CIDR}"
32 # --pod-network-cidr="${POD_NETWORK_CIDR}" \
33 # --apiserver-advertise-address="${MGMT_HOST}" \
34 # --service-cidr="${SERVICE_CIDR}"
36 if [ "$(id -u)" = 0 ]; then
37 echo "export KUBECONFIG=/etc/kubernetes/admin.conf" | \
38 tee -a "${HOME}/.bashrc"
39 # shellcheck disable=SC1090
40 source "${HOME}/.bashrc"
43 mkdir -p "${HOME}/.kube"
44 # shellcheck disable=SC2216
45 yes | sudo cp -rf /etc/kubernetes/admin.conf "${HOME}/.kube/config"
46 sudo chown "$(id -u)":"$(id -g)" "${HOME}/.kube/config"