Update kubernetes_install.sh
This commit is contained in:
parent
f4d971f3e2
commit
d0b7ad46cd
@ -1,11 +1,24 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
DOCKER_VERSION=$1
|
# Setting all parameters
|
||||||
KUBERNETES_VERSION=$2
|
NODE_TYPE=$1
|
||||||
CLIENT=$3
|
INTERNAL=!$2
|
||||||
IP=$4
|
MASTER_IP=$3
|
||||||
TOKEN=$5
|
|
||||||
HASH=$6
|
## Parameters for master node installation
|
||||||
|
if [ "$NODE_TYPE" == "master" ]
|
||||||
|
then
|
||||||
|
if [ "$#" -lt 4 ]; then
|
||||||
|
POD_NETWORK_ARG=""
|
||||||
|
else
|
||||||
|
POD_NETWORK_ARG="--pod-network-cidr=$4"
|
||||||
|
fi
|
||||||
|
# Parameters for worker node installation
|
||||||
|
elif [ "$NODE_TYPE" == "worker" ]
|
||||||
|
then
|
||||||
|
TOKEN=$4
|
||||||
|
HASH=$5
|
||||||
|
fi
|
||||||
|
|
||||||
#Installing Docker
|
#Installing Docker
|
||||||
DOCKER_INSTALLED=$(which docker)
|
DOCKER_INSTALLED=$(which docker)
|
||||||
@ -17,7 +30,7 @@ then
|
|||||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
|
||||||
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
||||||
apt-get update
|
apt-get update
|
||||||
apt-get install -y docker-ce=$DOCKER_VERSION
|
apt-get install -y docker-ce
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@ -30,26 +43,51 @@ then
|
|||||||
chmod 666 /etc/apt/sources.list.d/kubernetes.list
|
chmod 666 /etc/apt/sources.list.d/kubernetes.list
|
||||||
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
|
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
|
||||||
apt-get update
|
apt-get update
|
||||||
apt-get install -y kubelet=$KUBERNETES_VERSION kubeadm=$KUBERNETES_VERSION kubectl=$KUBERNETES_VERSION kubernetes-cni=$KUBERNETES_VERSION
|
apt-get install -y kubelet kubeadm kubectl kubernetes-cni
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Disabling swap for Kubernetes
|
#Disabling swap for Kubernetes
|
||||||
sysctl net.bridge.bridge-nf-call-iptables=1 > /dev/null
|
sysctl net.bridge.bridge-nf-call-iptables=1 > /dev/null
|
||||||
swapoff -a
|
swapoff -a
|
||||||
|
|
||||||
if [ -z "$CLIENT" ]
|
# Initialize Kubernetes as Master node
|
||||||
|
if [ "$NODE_TYPE" == "master" ]
|
||||||
then
|
then
|
||||||
# kubeadm init --ignore-preflight-errors=SystemVerification
|
## Set master node for internal network
|
||||||
# mkdir -p $HOME/.kube
|
if [ $INTERNAL ]; then
|
||||||
# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
|
touch /etc/default/kubelet
|
||||||
# chown $(id -u):$(id -g) $HOME/.kube/config
|
echo "KUBELET_EXTRA_ARGS=--node-ip=$MASTER_IP" > /etc/default/kubelet
|
||||||
:
|
fi
|
||||||
|
## Init Kubernetes
|
||||||
|
kubeadm init --ignore-preflight-errors=SystemVerification \
|
||||||
|
--apiserver-advertise-address=$MASTER_IP $POD_NETWORK_ARG
|
||||||
|
mkdir -p $HOME/.kube
|
||||||
|
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
|
||||||
|
chown $(id -u):$(id -g) $HOME/.kube/config
|
||||||
|
|
||||||
elif [ "$CLIENT" = "true" ]
|
echo "[master:$(hostname -s)] Node is up and running on $MASTER_IP"
|
||||||
|
|
||||||
|
# Initialize Kubernetes as Worker node
|
||||||
|
elif [ "$NODE_TYPE" = "worker" ]
|
||||||
then
|
then
|
||||||
kubeadm join $IP --token $TOKEN --discovery-token-ca-cert-hash $HASH
|
## Set worker node for internal network
|
||||||
echo "Client ($IP) joined to Master"
|
if [ $INTERNAL ]; then
|
||||||
|
IP=$(grep -oP \
|
||||||
|
'(?<=src )[^ ]*' \
|
||||||
|
<(grep -f <(ls -l /sys/class/net | grep pci | awk '{print $9}') \
|
||||||
|
<(ip ro sh) |
|
||||||
|
grep -v $(ip ro sh | grep default | awk '{print $5}')) |
|
||||||
|
head -1)
|
||||||
|
touch /etc/default/kubelet
|
||||||
|
echo "KUBELET_EXTRA_ARGS=--node-ip=$IP" > /etc/default/kubelet
|
||||||
|
else
|
||||||
|
IP=$(grep -oP '(?<=src )[^ ]*' <(ip ro sh | grep default))
|
||||||
|
fi
|
||||||
|
## Join to Kubernetes Master node
|
||||||
|
kubeadm join $MASTER_IP --token $TOKEN --discovery-token-ca-cert-hash $HASH \
|
||||||
|
--ignore-preflight-errors=SystemVerification
|
||||||
|
|
||||||
|
echo "[worker:$(hostname -s)] Client ($IP) joined to Master ($MASTER_IP)"
|
||||||
else
|
else
|
||||||
echo "Invalid argument"
|
echo "Invalid argument"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user