Skip to content
This repository was archived by the owner on Mar 31, 2023. It is now read-only.

[K8sDeploy] Create an auto deployment script for Alcor in K8s #590

Open
cj-chung opened this issue Apr 9, 2021 · 0 comments
Open

[K8sDeploy] Create an auto deployment script for Alcor in K8s #590

cj-chung opened this issue Apr 9, 2021 · 0 comments
Assignees

Comments

@cj-chung
Copy link
Contributor

cj-chung commented Apr 9, 2021

The current Alcor k8s deployment scripts use ssh remote execution to parallel run deployment script on each node in the cluster. The parallel remote script execution cannot guarantee the completion of the task. We need to rewrite the deployment script using Ansible.

The involved files include:

  1. /aclor/kubenetes/*
  2. /aclor/scripts/build.sh
  3. The following scripts:

alcor-deploy.sh

#!/bin/bash

if [ ! -d ~/alcor_logs ]; then
    mkdir -p ~/alcor_logs
fi

export KUBECONFIG=/etc/kubernetes/admin.conf

echo "***** Delete Alcor Microservices *****" 2>&1 | tee ~/alcor_logs/alcor.log
/root/kube-yaml/deleteYaml.sh 2>&1 | tee -a ~/alcor_logs/alcor.log

cd /root
echo "***** Download and build images on each Node *****" 2>&1 | tee -a ~/alcor_logs/alcor.log
./deploy-alcor-nodes.sh update-alcor.sh alcor-nodes-ips

echo "***** Deploy Aclor Cluster *****" 2>&1 | tee -a ~/alcor_logs/alcor.log
cd /root/kube-yaml
/root/kube-yaml/createYaml.sh 2>&1 | tee -a ~/alcor_logs/alcor.log
cd /root

sleep 30s

echo "***** Alcor Microservices Status *****" 2>&1 | tee -a ~/alcor_logs/alcor.log
kubectl get pods -A 2>&1 | tee -a ~/alcor_logs/alcor.log

echo "***** Create Segments *****" 2>&1 | tee -a ~/alcor_logs/alcor.log
curl -X POST -H "Content-Type: application/json" -H "Accept: */*" "http://localhost:30001/segments/createDefaultTable" 2>&1 | tee -a ~/alcor_logs/alcor.log

echo "***** Register Nodes *****" 2>&1 | tee -a ~/alcor_logs/alcor.log
curl -X POST -H "Content-Type: multipart/form-data" -F "[email protected]" "http://localhost:30007/nodes/upload" 2>&1 | tee -a ~/alcor_logs/alcor.log

update-alcor.sh

#!/bin/bash

if [ ! -d /root/alcor ]; then
        git clone https://github.com/futurewei-cloud/alcor.git /root/alcor
else
        cd /root/alcor
        git stash
        git fetch
        git checkout master
        git pull
        #git reset --hard 28cfda5157c0f5e3bfaa4330c6b536217230b5d2
fi

echo "***** Delete Work Folder *****"
rm -rf /root/work

sed -i 's/<java.version>11<\/java.version>/<java.version>8<\/java.version>/g' /root/alcor/lib/pom.xml
sed -i 's/<source>11<\/source>/<source>8<\/source>/g' /root/alcor/lib/pom.xml
sed -i 's/<target>11<\/target>/<target>8<\/target>/g' /root/alcor/lib/pom.xml
sed -i 's/getFastPath() == null ? false/getFastPath() == null ? true/g' /root/alcor/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImpl.java
sed -i 's/return new UnicastGoalState() ? return null/g' /root/alcor/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImpl.java
sed -i 's/#logging.level.root=INFO/logging.level.root=DEBUG/g' /root/alcor/kubernetes/services/dpm_manager.yaml
sed -i 's/#logging.level.root=DEBUG/logging.level.root=DEBUG/g' /root/alcor/kubernetes/services/dpm_manager.yaml
sed -i 's/#logging.level.root=INFO/logging.level.root=DEBUG/g' /root/alcor/services/data_plane_manager/src/main/resources/application.properties
sed -i 's/portEntity.setStatus(StatusEnum.SUCCESS.getStatus())/portEntity.setStatus(com.futurewei.alcor.common.enumClass.NetworkStatusEnum.ACTIVE.getNetworkStatus())/g' /root/alcor/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/service/PortServiceImpl.java
echo "***** Build Alcor Images *****"
/root/alcor/scripts/build.sh

deploy-alcor-nodes.sh

#!/bin/bash

#
# SCP aca_update.sh to each compute node
# and run aca_update.sh
#
function deploy_alcor_node()
{
    local cmdfile=$1
    local ip=$2

    if [ ! -d ~/alcor_logs ]; then
        mkdir -p ~/alcor_logs
    fi

    echo "===== Copy $cmdfile to root@$ip:.  =====" 2>&1 | tee ~/alcor_logs/$ip.log
    scp $cmdfile "root@$ip:." 2>&1 | tee -a ~/alcor_logs/$ip.log
    echo "===== Run $cmdfile on root@$ip =====" 2>&1 | tee -a ~/alcor_logs/$ip.log
    Y="./$cmdfile"
    ssh "root@$ip" "$Y" 2>&1 | tee -a ~/alcor_logs/$ip.log
    echo "===== $ip update done! =====" 2>&1 | tee -a ~/alcor_logs/$ip.log
}

# Test an IP address for validity:
# Usage:
#      valid_ip IP_ADDRESS
#      if [[ $? -eq 0 ]]; then echo good; else echo bad; fi
#   OR
#      if valid_ip IP_ADDRESS; then echo good; else echo bad; fi
#
function valid_ip()
{
    local  ip=$1
    local  stat=1

    if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
        OIFS=$IFS
        IFS='.'
        ip=($ip)
        IFS=$OIFS
        [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
            && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
        stat=$?
    fi
    return $stat
}

FILE=
if [[ $# -lt 2 ]]; then
        echo "Usage: deploy-alcor-nodes <shell script file>  <nodes file>"
        exit 1
else
        CMDSFILE=$1
        NODESFILE=$2
fi

if [ ! -f "$CMDSFILE" ]; then
        echo "*** $CMDSFILE does not exist!"
        exit 1
fi

if [ ! -f "$NODESFILE" ]; then
        echo "*** $NODESFILE does not exist!"
        exit 1
fi

while IFS= read -r line
do
        if valid_ip $line; then
                echo "*********** process $line *****************"
                deploy_alcor_node $CMDSFILE $line &
        fi
done < "$NODESFILE"

wait
echo "*********** ALL AlCORE NODES UPDATE DONE!! *****************"
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants