Add Extra Flags to Kubelet to enable extra feature
[iec.git] / src / foundation / 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 #Add extra flags to Kubelet
14 sed '/Environment=\"KUBELET_CONFIG_ARGS/a\Environment=\"KUBELET_EXTRA_ARGS=--fail-swap-on=false --feature-gates HugePages=false\"' -i /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
15
16 if ! kubectl get nodes; then
17   sudo kubeadm config images pull
18   sudo kubeadm init \
19     --pod-network-cidr="${POD_NETWORK_CIDR}" \
20     --apiserver-advertise-address="${MGMT_IP}" \
21     --service-cidr="${SERVICE_CIDR}"
22
23   if [ "$(id -u)" = 0 ]; then
24     echo "export KUBECONFIG=/etc/kubernetes/admin.conf" | \
25       tee -a "${HOME}/.profile"
26     # shellcheck disable=SC1090
27     source "${HOME}/.profile"
28   else
29     mkdir -p "${HOME}/.kube"
30     sudo cp -i /etc/kubernetes/admin.conf "${HOME}/.kube/config"
31     sudo chown "$(id -u)":"$(id -g)" "${HOME}/.kube/config"
32   fi
33 fi