Merge "Add LICENSE, .gitignore file"
[iec.git] / scripts / k8s_master.sh
1 #!/bin/bash -ex
2
3 # For host setup as Kubernetes master
4 MGMT_IP=$1
5 POD_NETWORK_CIDR=${2:-192.168.0.0/16}
6 SERVICE_CIDR=${3:-172.16.1.0/24}
7
8 if [ -z "${MGMT_IP}" ]; then
9   echo "Please specify a management IP!"
10   exit 1
11 fi
12
13 if ! kubectl get nodes; then
14   sudo kubeadm config images pull
15   sudo kubeadm init \
16     --pod-network-cidr="${POD_NETWORK_CIDR}" \
17     --apiserver-advertise-address="${MGMT_IP}" \
18     --service-cidr="${SERVICE_CIDR}"
19
20   if [ "$(id -u)" = 0 ]; then
21     echo "export KUBECONFIG=/etc/kubernetes/admin.conf" | \
22       tee -a "${HOME}/.profile"
23     # shellcheck disable=SC1090
24     source "${HOME}/.profile"
25   else
26     mkdir -p "${HOME}/.kube"
27     sudo cp -i /etc/kubernetes/admin.conf "${HOME}/.kube/config"
28     sudo chown "$(id -u)":"$(id -g)" "${HOME}/.kube/config"
29   fi
30 fi