mirror of https://github.com/easzlab/kubeasz.git
更新easzctl start-aio安装
parent
bf4d5976fb
commit
27ff0e6b61
|
@ -20,6 +20,7 @@ Commands 2 (cluster-wide operation):
|
|||
destroy To destroy the current cluster, with '--purge' option to also delete the context
|
||||
list To list all of clusters managed
|
||||
setup To setup a cluster using the current context
|
||||
start-aio To quickly setup an all-in-one cluster for testing (like minikube)
|
||||
|
||||
Use "easzctl help <command>" for more information about a given command.
|
||||
EOF
|
||||
|
@ -50,19 +51,19 @@ function help-info() {
|
|||
}
|
||||
|
||||
function process_cmd() {
|
||||
echo -e "+---\033[33m$ACTION\033[0m---+ : $CMD"
|
||||
$CMD || { echo -e "+---\033[31mAction failed\033[0m---+ : $CMD"; return 1; }
|
||||
echo -e "+---\033[32mAction successed\033[0m---+ : $CMD"
|
||||
echo -e "[INFO] \033[33m$ACTION\033[0m : $CMD"
|
||||
$CMD || { echo -e "[ERROR] \033[31mAction failed\033[0m : $CMD"; return 1; }
|
||||
echo -e "[INFO] \033[32mAction successed\033[0m : $CMD"
|
||||
}
|
||||
|
||||
### in-cluster operation functions ##############################
|
||||
|
||||
function add-node() {
|
||||
# check new node's address regexp
|
||||
[[ $1 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { echo "ERROR: Invalid ip address!"; return 1; }
|
||||
[[ $1 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { echo "[ERROR] Invalid ip address!"; return 1; }
|
||||
|
||||
# check if the new node already exsited
|
||||
sed -n '/^\[kube-master/,/^\[harbor/p' $BASEPATH/hosts|grep "^$1" && { echo "ERROR: node $1 already existed!"; return 2; }
|
||||
sed -n '/^\[kube-master/,/^\[harbor/p' $BASEPATH/hosts|grep "^$1" && { echo "[ERROR] node $1 already existed!"; return 2; }
|
||||
|
||||
# add a node into 'kube-node' group
|
||||
sed -i "/\[kube-node/a $1 NEW_NODE=yes" $BASEPATH/hosts
|
||||
|
@ -76,13 +77,13 @@ function add-node() {
|
|||
|
||||
function add-master() {
|
||||
# check new master's address regexp
|
||||
[[ $1 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { echo "ERROR: Invalid ip address!"; return 2; }
|
||||
[[ $1 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { echo "[ERROR] Invalid ip address!"; return 2; }
|
||||
|
||||
# check if k8s with DPLOY_MODE='multi-master'
|
||||
grep '^DEPLOY_MODE=multi-master' $BASEPATH/hosts || { echo "ERROR: only k8s with DPLOY_MODE='multi-master' can have master node added!"; return 2; }
|
||||
grep '^DEPLOY_MODE=multi-master' $BASEPATH/hosts || { echo "[ERROR] only k8s with DPLOY_MODE='multi-master' can have master node added!"; return 2; }
|
||||
|
||||
# check if the new master already exsited
|
||||
sed -n '/^\[kube-master/,/^\[kube-node/p' $BASEPATH/hosts|grep "^$1" && { echo "ERROR: master $1 already existed!"; return 2; }
|
||||
sed -n '/^\[kube-master/,/^\[kube-node/p' $BASEPATH/hosts|grep "^$1" && { echo "[ERROR] master $1 already existed!"; return 2; }
|
||||
|
||||
# add a node into 'kube-master' group
|
||||
sed -i "/\[kube-master/a $1 NEW_MASTER=yes" $BASEPATH/hosts
|
||||
|
@ -96,15 +97,15 @@ function add-master() {
|
|||
|
||||
function add-etcd() {
|
||||
# check new node's address regexp
|
||||
[[ $1 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { echo "ERROR: Invalid ip address!"; return 2; }
|
||||
[[ $1 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { echo "[ERROR] Invalid ip address!"; return 2; }
|
||||
|
||||
# check if the new node already exsited
|
||||
sed -n '/^\[etcd/,/^\[kube-master/p' $BASEPATH/hosts|grep "^$1" && { echo "ERROR: node $1 already existed!"; return 2; }
|
||||
sed -n '/^\[etcd/,/^\[kube-master/p' $BASEPATH/hosts|grep "^$1" && { echo "[ERROR] node $1 already existed!"; return 2; }
|
||||
|
||||
# input an unique NODE_NAME of the node in etcd cluster
|
||||
echo "Please input an UNIQUE name(string) for the new node: "
|
||||
read NAME
|
||||
sed -n '/^\[etcd/,/^\[kube-master/p' $BASEPATH/hosts|grep "$NAME" && { echo "ERROR: name [$NAME] already existed!"; return 2; }
|
||||
read -t15 NAME
|
||||
sed -n '/^\[etcd/,/^\[kube-master/p' $BASEPATH/hosts|grep "$NAME" && { echo "[ERROR] name [$NAME] already existed!"; return 2; }
|
||||
|
||||
# add a node into 'kube-node' group
|
||||
sed -i "/\[etcd/a $1 NODE_NAME=$NAME" $BASEPATH/hosts
|
||||
|
@ -118,7 +119,7 @@ function add-etcd() {
|
|||
|
||||
function del-etcd() {
|
||||
# check node's address regexp
|
||||
[[ $1 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { echo "ERROR: Invalid ip address!"; return 2; }
|
||||
[[ $1 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { echo "[ERROR] Invalid ip address!"; return 2; }
|
||||
|
||||
#
|
||||
ansible-playbook $BASEPATH/tools/remove_etcd_node.yml -e ETCD_TO_DEL=$1
|
||||
|
@ -129,7 +130,7 @@ function del-etcd() {
|
|||
|
||||
function clean-node() {
|
||||
# check node's address regexp
|
||||
[[ $1 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { echo "ERROR: Invalid ip address!"; return 2; }
|
||||
[[ $1 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { echo "[ERROR] Invalid ip address!"; return 2; }
|
||||
|
||||
#
|
||||
ansible-playbook $BASEPATH/tools/clean_one_node.yml -e NODE_TO_DEL=$1
|
||||
|
@ -138,32 +139,19 @@ function clean-node() {
|
|||
save_context
|
||||
}
|
||||
|
||||
function start() {
|
||||
case "$1" in
|
||||
(aio)
|
||||
start-aio
|
||||
;;
|
||||
(*)
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function start-aio(){
|
||||
[ -f "$BASEPATH/hosts" ] && { echo -e "ERROR: file $BASEPATH/hosts exists!\nRemove it if you really want to start an aio cluster"; return 3; }
|
||||
if [ ! -n "$KUBEASZ_DOCKER_HOST" ]; then
|
||||
checkout aio
|
||||
set +u
|
||||
# Check ENV 'HOST_IP', if exist indecates running in a docker container, otherwise running in a host machine
|
||||
if [[ -z $HOST_IP ]];then
|
||||
# easzctl runs in a host machine, get host's ip
|
||||
HOST_IF=$(ip route|grep default|cut -d' ' -f5)
|
||||
HOST_IP=$(ip a|grep $HOST_IF|awk 'NR==2{print $2}'|cut -d'/' -f1)
|
||||
cp -f $BASEPATH/example/hosts.allinone.example.en $BASEPATH/hosts
|
||||
sed -i "s/192.168.1.1/$HOST_IP/g" $BASEPATH/hosts
|
||||
ansible-playbook $BASEPATH/90.setup.yml
|
||||
else
|
||||
# easzctl runs in a container
|
||||
cp -f $BASEPATH/example/hosts.allinone.example.en $BASEPATH/hosts
|
||||
sed -i "s/192.168.1.1/$KUBEASZ_DOCKER_HOST/g" $BASEPATH/hosts
|
||||
ansible-playbook $BASEPATH/90.setup.yml
|
||||
fi
|
||||
set -u
|
||||
cp -f $BASEPATH/example/hosts.allinone.example.en $BASEPATH/hosts
|
||||
sed -i "s/192.168.1.1/$HOST_IP/g" $BASEPATH/hosts
|
||||
setup
|
||||
}
|
||||
|
||||
### cluster-wide operation functions ############################
|
||||
|
@ -193,7 +181,7 @@ function save_context() {
|
|||
}
|
||||
|
||||
function install_context() {
|
||||
[ -f "$BASEPATH/.cluster/current_cluster" ] || { echo "Invalid Context"; return 1; }
|
||||
[ -f "$BASEPATH/.cluster/current_cluster" ] || { echo "[ERROR] Invalid Context"; return 1; }
|
||||
CLUSTER=$(cat $BASEPATH/.cluster/current_cluster)
|
||||
echo "[INFO] install context: $CLUSTER"
|
||||
echo "[INFO] install $CLUSTER roles' configration"
|
||||
|
@ -329,10 +317,6 @@ case "$1" in
|
|||
ACTION="Action: clean a node"
|
||||
CMD="clean-node $2"
|
||||
;;
|
||||
(start)
|
||||
ACTION="Action: start an AllInOne cluster"
|
||||
CMD="start $2"
|
||||
;;
|
||||
### cluster-wide operations #######################
|
||||
(checkout)
|
||||
[ "$#" -gt 1 ] || { usage >&2; exit 2; }
|
||||
|
@ -347,13 +331,17 @@ case "$1" in
|
|||
CMD="destroy"
|
||||
fi
|
||||
;;
|
||||
(list)
|
||||
ACTION="Action: list all of clusters managed"
|
||||
CMD="list"
|
||||
;;
|
||||
(setup)
|
||||
ACTION="Action: setup cluster with current context"
|
||||
CMD="setup"
|
||||
;;
|
||||
(list)
|
||||
ACTION="Action: list all of clusters managed"
|
||||
CMD="list"
|
||||
(start-aio)
|
||||
ACTION="Action: start an AllInOne cluster"
|
||||
CMD="start-aio"
|
||||
;;
|
||||
(help)
|
||||
[ "$#" -gt 1 ] || { usage >&2; exit 2; }
|
||||
|
|
|
@ -15,33 +15,33 @@ EOF
|
|||
function start_kubeasz_docker() {
|
||||
# kubeasz docker version
|
||||
KUBEASZ_DOCKER_VER=jmgao1983/kubeasz:$1
|
||||
echo "VERSION $KUBEASZ_DOCKER_VER"
|
||||
echo "[INFO] VERSION $KUBEASZ_DOCKER_VER"
|
||||
|
||||
# init host dir
|
||||
if [ -d "/etc/ansible/roles/" ];then
|
||||
echo "==> aleady Initialized."
|
||||
echo "[WARN] aleady Initialized."
|
||||
else
|
||||
rm -rf /etc/ansible
|
||||
echo "==> run a temporary container"
|
||||
echo "[INFO] run a temporary container"
|
||||
docker run -d --name temp_easz $KUBEASZ_DOCKER_VER
|
||||
echo "==> init host kubeasz dir..."
|
||||
echo "[INFO] init host kubeasz directory"
|
||||
docker cp temp_easz:/etc/ansible /etc/ansible
|
||||
echo "==> stop&remove temporary container"
|
||||
echo "[INFO] stop&remove temporary container"
|
||||
docker stop temp_easz
|
||||
docker rm temp_easz
|
||||
fi
|
||||
|
||||
# get host's IP
|
||||
HOST_IF=$(ip route|grep default|cut -d' ' -f5)
|
||||
HOST_IP=$(ip a|grep $HOST_IF|awk 'NR==2{print $2}'|cut -d'/' -f1)
|
||||
echo "==> get host IP: $HOST_IP"
|
||||
host_if=$(ip route|grep default|cut -d' ' -f5)
|
||||
host_ip=$(ip a|grep $host_if|awk 'NR==2{print $2}'|cut -d'/' -f1)
|
||||
echo "[INFO] get host IP: $host_ip"
|
||||
|
||||
# run kubeasz docker container
|
||||
echo "==> run kubeasz in a container"
|
||||
echo "[INFO] run kubeasz in a container"
|
||||
docker run --detach \
|
||||
--name kubeasz \
|
||||
--restart always \
|
||||
--env KUBEASZ_DOCKER_HOST=$HOST_IP \
|
||||
--env HOST_IP=$host_ip \
|
||||
--volume /etc/ansible:/etc/ansible \
|
||||
--volume /root/.kube:/root/.kube \
|
||||
--volume /root/.ssh/id_rsa:/root/.ssh/id_rsa:ro \
|
||||
|
@ -51,7 +51,7 @@ function start_kubeasz_docker() {
|
|||
}
|
||||
|
||||
function clean_container() {
|
||||
echo "==> clean all running containers"
|
||||
echo "[INFO] clean all running containers"
|
||||
docker ps -a|awk 'NR>1{print $1}'|xargs docker rm -f
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue