Update cluster-deploy
This commit is contained in:
parent
904a503229
commit
309195ca4a
159
cluster-deploy
159
cluster-deploy
@ -12,28 +12,24 @@
|
||||
PID=$$
|
||||
SCRIPTNAME="$(basename $0)"
|
||||
WORKER_LIST="worker.list"
|
||||
IP=""
|
||||
EXTERNAL=false
|
||||
MASTER_IP=""
|
||||
TOKEN=""
|
||||
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
|
||||
|
||||
#FIXME Write usage message
|
||||
function usage {
|
||||
cat << EOF
|
||||
|
||||
Usage: $SCRIPTNAME <CNI>
|
||||
|
||||
Available CNI plugins:
|
||||
Usage: $SCRIPTNAME [--external|-e] <CNI>
|
||||
--external|-e : Initizalize Kubernetes on the external network
|
||||
instead of on an internal one
|
||||
Available <CNI> plugins:
|
||||
* Calico
|
||||
* Cilium
|
||||
* Flannel
|
||||
* WeaveNet
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
@ -57,30 +53,22 @@ function wait_for_podnetwork {
|
||||
done
|
||||
}
|
||||
|
||||
## Check files from parameters
|
||||
# Preflight checks
|
||||
|
||||
## Check file from parameters
|
||||
if [ ! -f $WORKER_LIST ]; then
|
||||
echo_err "Worker list file ($WORKER_LIST) not exists."
|
||||
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."
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f $DOCKER_VERFILE ]; then
|
||||
echo_err "Docker version file ($DOCKER_VERFILE) not exists."
|
||||
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
|
||||
## Create array from file
|
||||
readarray WORKER < $WORKER_LIST
|
||||
|
||||
## Check for argument
|
||||
if [ "$#" -lt 1 ]; then
|
||||
@ -88,62 +76,95 @@ if [ "$#" -lt 1 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make the letters of the argument lowercase
|
||||
CNI=$(tr '[:upper:]' '[:lower:]' <<< $1)
|
||||
|
||||
## Setup Kubernetes
|
||||
./deploy/kubernetes_install.sh $DOCKER_vERSION $KUBERNETES_VERSION
|
||||
|
||||
## 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.;;
|
||||
|
||||
## Check for help parameter
|
||||
for i in "$@"
|
||||
do
|
||||
### Make the letters of the argument lowercase
|
||||
i=$(tr '[:upper:]' '[:lower:]' <<< $i)
|
||||
case $i in
|
||||
### 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
|
||||
*) echo_err "Unknown CNI plugin!";
|
||||
*) echo_err "Unkown parameter: $i option is not valid!";
|
||||
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)
|
||||
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?
|
||||
#./deploy/docker_registry_setup.sh $IP:5000
|
||||
|
||||
# Join the worker nodes
|
||||
for LINE in $(cat $WORKER_LIST | grep -vE "^#"); do
|
||||
WORKERNAME=`echo $LINE | awk -F"/" '{print $NF}'`
|
||||
|
||||
for WORKERNAME in ${WORKER[@]}; do
|
||||
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?
|
||||
wait_for_worker
|
||||
# wait_for_worker
|
||||
|
||||
#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."
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user