mirror of https://github.com/easzlab/kubeasz.git
fix easzctl脚本适应新流程
parent
2ef0e9f86c
commit
d0a481cd09
|
@ -2,7 +2,6 @@
|
|||
file: name={{ item }} state=directory
|
||||
with_items:
|
||||
- "{{ base_dir }}/.cluster/ssl"
|
||||
- "{{ base_dir }}/.cluster/yaml"
|
||||
|
||||
- name: 本地设置 bin 目录权限
|
||||
file: path={{ base_dir }}/bin state=directory mode=0755 recurse=yes
|
||||
|
@ -31,11 +30,11 @@
|
|||
file: path=/root/.kube state=absent
|
||||
|
||||
- name: 下载 group:read rbac 文件
|
||||
copy: src=read-group-rbac.yaml dest={{ base_dir }}/.cluster/yaml/read-group-rbac.yaml
|
||||
copy: src=read-group-rbac.yaml dest=/tmp/read-group-rbac.yaml
|
||||
when: USER_NAME == "read"
|
||||
|
||||
- name: 创建group:read rbac 绑定
|
||||
shell: "{{ base_dir }}/bin/kubectl apply -f {{ base_dir }}/.cluster/yaml/read-group-rbac.yaml"
|
||||
shell: "{{ base_dir }}/bin/kubectl apply -f /tmp/read-group-rbac.yaml"
|
||||
when: USER_NAME == "read"
|
||||
|
||||
- name: 准备kubectl使用的{{ USER_NAME }}证书签名请求
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
- kube-apiserver
|
||||
- kube-controller-manager
|
||||
- kube-scheduler
|
||||
- kubectl
|
||||
tags: upgrade_k8s
|
||||
|
||||
# 设置 kubernetes svc ip (一般是 SERVICE_CIDR 中第一个IP)
|
||||
|
|
|
@ -179,8 +179,9 @@ function del-master() {
|
|||
|
||||
# remove node in ansible hosts
|
||||
sed -i '/^\[kube-master/,/^\[kube-node/{/^'"$1"'[^0-9]*$/d}' $BASEPATH/hosts
|
||||
sed -i '/^\[kube-node/,/^\[harbor/{/^'"$1"'[^0-9]*$/d}' $BASEPATH/hosts
|
||||
|
||||
# reconfig kubeconfig in ansible controller
|
||||
# reconfig kubeconfig in ansible manage node
|
||||
ansible-playbook $BASEPATH/01.prepare.yml -t create_kctl_cfg
|
||||
|
||||
# reconfigure and restart the haproxy service on 'kube-node' nodes
|
||||
|
@ -235,6 +236,16 @@ function save_context() {
|
|||
echo "[INFO] save $CLUSTER kubeconfig"
|
||||
cp -fp /root/.kube/config $BASEPATH/.cluster/$CLUSTER/
|
||||
fi
|
||||
|
||||
if [ -f "$BASEPATH/.cluster/kube-proxy.kubeconfig" ];then
|
||||
echo "[INFO] save $CLUSTER kube-proxy.kubeconfig"
|
||||
cp -fp $BASEPATH/.cluster/kube-proxy.kubeconfig $BASEPATH/.cluster/$CLUSTER/kube-proxy.kubeconfig
|
||||
fi
|
||||
|
||||
if [ -d "$BASEPATH/.cluster/ssl" ];then
|
||||
echo "[INFO] save $CLUSTER certs"
|
||||
cp -rfp $BASEPATH/.cluster/ssl $BASEPATH/.cluster/$CLUSTER/ssl
|
||||
fi
|
||||
}
|
||||
|
||||
function install_context() {
|
||||
|
@ -256,23 +267,35 @@ function install_context() {
|
|||
echo "[INFO] install $CLUSTER kubeconfig"
|
||||
cp -fp $BASEPATH/.cluster/$CLUSTER/config /root/.kube/
|
||||
fi
|
||||
|
||||
if [ -f "$BASEPATH/.cluster/$CLUSTER/kube-proxy.kubeconfig" ];then
|
||||
echo "[INFO] install $CLUSTER kube-proxy.kubeconfig"
|
||||
cp -fp $BASEPATH/.cluster/$CLUSTER/kube-proxy.kubeconfig $BASEPATH/.cluster/kube-proxy.kubeconfig
|
||||
fi
|
||||
|
||||
if [ -d "$BASEPATH/.cluster/$CLUSTER/ssl" ];then
|
||||
echo "[INFO] install $CLUSTER certs"
|
||||
cp -rfp $BASEPATH/.cluster/$CLUSTER/ssl $BASEPATH/.cluster/ssl
|
||||
fi
|
||||
}
|
||||
|
||||
function checkout() {
|
||||
# check directory '.cluster', initialize it if not existed
|
||||
if [ ! -d "$BASEPATH/.cluster" ]; then
|
||||
if [ ! -f "$BASEPATH/.cluster/current_cluster" ]; then
|
||||
echo "[INFO] initialize directory $BASEPATH/.cluster"
|
||||
mkdir -p $BASEPATH/.cluster/default
|
||||
echo default > $BASEPATH/.cluster/current_cluster
|
||||
fi
|
||||
|
||||
# check if $1 is already the current context
|
||||
CLUSTER=$(cat $BASEPATH/.cluster/current_cluster)
|
||||
[ "$1" != "$CLUSTER" ] || { echo "[WARN] $1 is already the current context"; return 0; }
|
||||
# save context of the current cluster
|
||||
|
||||
echo "[INFO] save current context: $CLUSTER"
|
||||
save_context
|
||||
echo "[INFO] clean context: $CLUSTER"
|
||||
rm -rf $BASEPATH/hosts /root/.kube/*
|
||||
rm -rf $BASEPATH/hosts /root/.kube/* $BASEPATH/.cluster/ssl $BASEPATH/.cluster/kube-proxy.kubeconfig
|
||||
|
||||
# check context $1, install it if existed, otherwise initialize it using default context
|
||||
if [ ! -d "$BASEPATH/.cluster/$1" ];then
|
||||
echo "[INFO] context $1 not existed, initialize it using default context"
|
||||
|
@ -285,7 +308,7 @@ function checkout() {
|
|||
}
|
||||
|
||||
function setup() {
|
||||
[ -d "$BASEPATH/.cluster" ] || { echo "[ERROR] invalid context, run 'easzctl checkout <cluster_name>' first"; return 1; }
|
||||
[ -f "$BASEPATH/.cluster/current_cluster" ] || { echo "[ERROR] invalid context, run 'easzctl checkout <cluster_name>' first"; return 1; }
|
||||
[ -f "$BASEPATH/bin/kube-apiserver" ] || { echo "[ERROR] no binaries found, download then fist"; return 1; }
|
||||
[ -f "$BASEPATH/hosts" ] || { echo "[ERROR] no ansible hosts found, read 'docs/setup/00-planning_and_overall_intro.md'"; return 1; }
|
||||
CLUSTER=$(cat $BASEPATH/.cluster/current_cluster)
|
||||
|
@ -297,16 +320,16 @@ function setup() {
|
|||
}
|
||||
|
||||
function list() {
|
||||
[ -d "$BASEPATH/.cluster" ] || { echo "[ERROR] invalid context, run 'easzctl checkout <cluster_name>' first"; return 1; }
|
||||
[ -f "$BASEPATH/.cluster/current_cluster" ] || { echo "[ERROR] invalid context, run 'easzctl checkout <cluster_name>' first"; return 1; }
|
||||
CLUSTER=$(cat $BASEPATH/.cluster/current_cluster)
|
||||
echo -e "\nlist of managed contexts (current: $CLUSTER)"
|
||||
i=1; for Cluster in $(ls $BASEPATH/.cluster/ |grep -v current_cluster);
|
||||
echo -e "\nlist of managed contexts (current: \033[33m$CLUSTER\033[0m)"
|
||||
i=1; for Cluster in $(ls $BASEPATH/.cluster/ |grep -Ev "ssl|current_cluster|kubeconfig");
|
||||
do
|
||||
echo -e "==> context $i:\t$Cluster"
|
||||
let "i++"
|
||||
done
|
||||
echo -e "\nlist of installed clusters (current: $CLUSTER)"
|
||||
i=1; for Cluster in $(ls $BASEPATH/.cluster/ |grep -v current_cluster);
|
||||
echo -e "\nlist of installed clusters (current: \033[33m$CLUSTER\033[0m)"
|
||||
i=1; for Cluster in $(ls $BASEPATH/.cluster/ |grep -Ev "ssl|current_cluster|kubeconfig");
|
||||
do
|
||||
KUBECONF=$BASEPATH/.cluster/$Cluster/config
|
||||
if [ -f "$KUBECONF" ]; then
|
||||
|
@ -318,7 +341,7 @@ function list() {
|
|||
}
|
||||
|
||||
function destroy() {
|
||||
[ -d "$BASEPATH/.cluster" ] || { echo "[ERROR] invalid context, run 'easzctl checkout <cluster_name>' first"; return 1; }
|
||||
[ -f "$BASEPATH/.cluster/current_cluster" ] || { echo "[ERROR] invalid context, run 'easzctl checkout <cluster_name>' first"; return 1; }
|
||||
CLUSTER=$(cat $BASEPATH/.cluster/current_cluster)
|
||||
echo -n "[WARN] DELETE cluster: $CLUSTER, Continue? (y/n): "
|
||||
read -t10 -n1 ANS || { echo -e "\n[WARN] timeout, destroy aborted"; return 1; }
|
||||
|
@ -351,7 +374,7 @@ function start-aio(){
|
|||
HOST_IP=$(ip a|grep $HOST_IF|awk 'NR==2{print $2}'|cut -d'/' -f1)
|
||||
fi
|
||||
set -u
|
||||
cp -f $BASEPATH/example/hosts.allinone.example.en $BASEPATH/hosts
|
||||
cp -f $BASEPATH/example/hosts.allinone $BASEPATH/hosts
|
||||
sed -i "s/192.168.1.1/$HOST_IP/g" $BASEPATH/hosts
|
||||
setup
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue