Update cluster-deploy

This commit is contained in:
Torma Kristóf 2019-04-24 13:26:06 +02:00 committed by GitHub
parent 904a503229
commit 309195ca4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,28 +12,24 @@
PID=$$ PID=$$
SCRIPTNAME="$(basename $0)" SCRIPTNAME="$(basename $0)"
WORKER_LIST="worker.list" WORKER_LIST="worker.list"
IP="" EXTERNAL=false
MASTER_IP=""
TOKEN="" TOKEN=""
HASH="" HASH=""
KUBERNETES_VERFILE="kubernetes.version"
DOCKER_VERFILE="docker.version"
DOCKER_VERSION=$(echo $(cat $DOCKER_VERFILE)|tr -d '\n')
KUBERNETES_VERSION=$(echo $(cat $KUBERNETES_VERFILE)|tr -d '\n')
# Functions # Functions
#FIXME Write usage message
function usage { function usage {
cat << EOF cat << EOF
Usage: $SCRIPTNAME [--external|-e] <CNI>
Usage: $SCRIPTNAME <CNI> --external|-e : Initizalize Kubernetes on the external network
instead of on an internal one
Available CNI plugins: Available <CNI> plugins:
* Calico * Calico
* Cilium * Cilium
* Flannel * Flannel
* WeaveNet * WeaveNet
EOF EOF
} }
@ -57,30 +53,22 @@ function wait_for_podnetwork {
done done
} }
## Check files from parameters # Preflight checks
## Check file from parameters
if [ ! -f $WORKER_LIST ]; then if [ ! -f $WORKER_LIST ]; then
echo_err "Worker list file ($WORKER_LIST) not exists." echo_err "Worker list file ($WORKER_LIST) not exists."
exit 1 exit 1
else if [ ! -s $WORKER_LIST ]; then fi
## Check the file contents
if [ ! -s $WORKER_LIST ]; then
echo_err "Worker list file ($WORKER_LIST) is empty." echo_err "Worker list file ($WORKER_LIST) is empty."
fi exit 1
fi fi
if [ ! -f $DOCKER_VERFILE ]; then ## Create array from file
echo_err "Docker version file ($DOCKER_VERFILE) not exists." readarray WORKER < $WORKER_LIST
exit 1
else if [ ! -s $DOCKER_VERFILE ]; then
echo_err "Docker version file ($DOCKER_VERFILE) is empty."
fi
fi
if [ ! -f $KUBERNETES_VERFILE ]; then
echo_err "Kubernetes version file ($DOCKER_VERFILE) not exists."
exit 1
else if [ ! -s $DOCKER_VERFILE ]; then
echo_err "Kubernetes version file ($DOCKER_VERFILE) is empty."
fi
fi
## Check for argument ## Check for argument
if [ "$#" -lt 1 ]; then if [ "$#" -lt 1 ]; then
@ -88,62 +76,95 @@ if [ "$#" -lt 1 ]; then
exit 1 exit 1
fi fi
# Make the letters of the argument lowercase ## Check for help parameter
CNI=$(tr '[:upper:]' '[:lower:]' <<< $1) for i in "$@"
do
## Setup Kubernetes ### Make the letters of the argument lowercase
./deploy/kubernetes_install.sh $DOCKER_vERSION $KUBERNETES_VERSION i=$(tr '[:upper:]' '[:lower:]' <<< $i)
case $i in
## Initialize Master and install CNI plugin
case $CNI in
### Setup Calico
calico) echo "[CNI] Installing Calico... ";
./deploy/calico_setup.sh;
echo "[CNI]" Calico installion is completed.;;
### Setup Cilium
cilium) echo "[CNI] Installing Cilium... ";
./deploy/cilium_setup.sh;
echo "[CNI]" Cilium installion is completed.;;
### Setup Flannel
flannel) echo "[CNI] Installing Flannel... ";
./deploy/flannel_setup.sh;
echo "[CNI]" Flannel installion is completed.;;
### Setup WeaveNet
weavenet) echo "[CNI] Installing WeaveNet... ";
./deploy/weavenet_setup.sh;
echo "[CNI]" WeaveNet installion is completed.;;
### Print out help message ### Print out help message
help) usage; exit 0;; help|h|-h|--help) usage; exit 0;;
esac
done
## Check parameters and setup variables for Kubernetes installation
for i in "$@"
do
### Make the letters of the argument lowercase
i=$(tr '[:upper:]' '[:lower:]' <<< $i)
case $i in
### Kubernetes network usage (internal|external)
-e|--external) echo "# Kubernetes will be set up for external network. #";
EXTERNAL=false;;
### Set parameters for Calico
calico) echo "[CNI] Calico selected...";
CNI="calico";
POD_NETWORK="192.168.0.0/16";;
### Set parameters for Cilium
cilium) echo "[CNI] Cilium selected...";
CNI="cilium";
POD_NETWORK="";;
### Set parameters for Flannel
flannel) echo "[CNI] Flannel selected...";
CNI="flannel";
POD_NETWORK="10.244.0.0/16";;
### Set parameters for WeaveNet...
weavenet) echo "[CNI] WeaveNet selected...";
CNI="weavenet";
POD_NETWORK="";;
### Wrong argument, print error message ### Wrong argument, print error message
*) echo_err "Unknown CNI plugin!"; *) echo_err "Unkown parameter: $i option is not valid!";
exit 1;; exit 1;;
esac esac
done
## Get Master node IP address
if [ $EXTERNAL ]; then
MASTER_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)
if [ "x$MASTER_IP" == "x" ]; then
EXTERNAL=false
MASTER_IP=$(grep -oP '(?<=src )[^ ]*' <(ip ro sh | grep default))
fi
else
MASTER_IP=$(grep -oP '(?<=src )[^ ]*' <(ip ro sh | grep default))
fi
## Setup Kubernetes
./deploy/kubernetes_install.sh master $EXTERNAL $MASTER_IP $POD_NETWORK
## Install CNI Plugin
./deploy/${CNI}_setup.sh
IP=$(ip addr sh dev $(ip ro sh | grep default | awk '{print $5}') scope global | grep inet | awk '{split($2,addresses,"/"); print addresses[1]}')
#IP=$(ifconfig $(route | grep '^default' | grep -o '[^ ]*$') | grep "inet addr:" | awk '{print $2}' | cut -c6-)
TOKEN=$(kubeadm token list | tail -n 1 | cut -d ' ' -f 1) TOKEN=$(kubeadm token list | tail -n 1 | cut -d ' ' -f 1)
HASH=sha256:$(openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //') HASH=sha256:$(openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt |
openssl rsa -pubin -outform der 2>/dev/null |
openssl dgst -sha256 -hex |
sed 's/^.* //')
#FIXME Do I need local docker-registry? #FIXME Do I need local docker-registry?
#./deploy/docker_registry_setup.sh $IP:5000 #./deploy/docker_registry_setup.sh $IP:5000
# Join the worker nodes # Join the worker nodes
for LINE in $(cat $WORKER_LIST | grep -vE "^#"); do for WORKERNAME in ${WORKER[@]}; do
WORKERNAME=`echo $LINE | awk -F"/" '{print $NF}'`
echo "[worker:$WORKERNAME] Deploying..." echo "[worker:$WORKERNAME] Deploying..."
ssh $WORKERNAME -o "StrictHostKeyChecking no" "bash -s" < ./deploy/kubernetes_install.sh $DOCKER_vERSION $KUBERNETES_VERSION true $IP:6443 $TOKEN $HASH ssh $WORKERNAME -o "StrictHostKeyChecking no" \
"bash -s" < ./deploy/kubernetes_install.sh worker $EXTERNAL $MASTER_IP:6443 $TOKEN $HASH
#FIXME Do I need to wait for the worker? #FIXME Do I need to wait for the worker?
wait_for_worker # wait_for_worker
#FIXME Do I need local docker-registry? #FIXME Do I need local docker-registry?
#ssh $WORKERNAME -o "StrictHostKeyChecking no" "bash -s" < ./deploy/docker_registry_setup.sh $IP:5000 # ssh $WORKERNAME -o "StrictHostKeyChecking no" "bash -s" < ./deploy/docker_registry_setup.sh $MASTER_IP:5000
echo "[worker:$WORKERNAME] Deployment is completed." echo "[worker:$WORKERNAME] Deployment is completed."
done done