#!/bin/bash cat << "EOF" _ _ _ _ (_) (_) | | | | _ __ _ __ _ _ __ _ | |_ __| | ___ __ __ | | / _` | / _` | | '__| | | | __| / _` | / _ \ \ \ / / | | | (_| | | (_| | | | | | | |_ _ | (_| | | __/ \ V / | | \__,_| \__, | |_| |_| \__| (_) \__,_| \___| \_/ _/ | __/ | |__/ |___/ Kubernetes Setup Script for Master Node Script source: https://github.com/techiescamp EOF # If you need public access to API server using the servers Public IP adress, change PUBLIC_IP_ACCESS to true. PUBLIC_IP_ACCESS="true" NODENAME=$(hostname -s) POD_CIDR="192.168.0.0/16" # Pull required images sudo kubeadm config images pull # Initialize kubeadm based on PUBLIC_IP_ACCESS if [[ "$PUBLIC_IP_ACCESS" == "false" ]]; then MASTER_PRIVATE_IP=$(ip addr show eth0 | awk '/inet / {print $2}' | cut -d/ -f1) sudo kubeadm init --apiserver-advertise-address="$MASTER_PRIVATE_IP" --apiserver-cert-extra-sans="$MASTER_PRIVATE_IP" --pod-network-cidr="$POD_CIDR" --node-name "$NODENAME" --ignore-preflight-errors Swap elif [[ "$PUBLIC_IP_ACCESS" == "true" ]]; then MASTER_PUBLIC_IP=$(curl ifconfig.me && echo "") sudo kubeadm init --control-plane-endpoint="$MASTER_PUBLIC_IP" --apiserver-cert-extra-sans="$MASTER_PUBLIC_IP" --pod-network-cidr="$POD_CIDR" --node-name "$NODENAME" --ignore-preflight-errors Swap else echo "Error: MASTER_PUBLIC_IP has an invalid value: $PUBLIC_IP_ACCESS" exit 1 fi # Configure kubeconfig mkdir -p "$HOME"/.kube sudo cp -i /etc/kubernetes/admin.conf "$HOME"/.kube/config sudo chown "$(id -u)":"$(id -g)" "$HOME"/.kube/config # Install Claico Network Plugin Network kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml