From e979b93fd9cc94592d3dda9333a9e4e5d3f75736 Mon Sep 17 00:00:00 2001 From: gjmzj Date: Fri, 22 Mar 2019 08:38:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0easzctl=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=A1=8C=E8=AF=B4=E6=98=8E=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 ++-- docs/setup/easzctl_cmd.md | 58 +++++++++++++++++++++++++++++++++++++++ tools/easzctl | 45 +++++++++++++++--------------- 3 files changed, 84 insertions(+), 24 deletions(-) create mode 100644 docs/setup/easzctl_cmd.md diff --git a/README.md b/README.md index 258af68..4af0220 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,9 @@ -- 公有云上部署请阅读 [使用kubeasz在公有云上创建k8s集群](docs/setup/kubeasz_on_public_cloud.md) -- 容器方式部署请阅读 [使用kubeasz容器创建k8s集群](docs/setup/docker_kubeasz.md) +- 命令行工具 [easzctl介绍](docs/setup/easzctl_cmd.md) +- 公有云部署 [使用kubeasz在公有云上创建k8s集群](docs/setup/kubeasz_on_public_cloud.md) +- 容器部署 [使用kubeasz容器创建k8s集群](docs/setup/docker_kubeasz.md) ## 使用指南 diff --git a/docs/setup/easzctl_cmd.md b/docs/setup/easzctl_cmd.md new file mode 100644 index 0000000..3abe538 --- /dev/null +++ b/docs/setup/easzctl_cmd.md @@ -0,0 +1,58 @@ +# easzctl 命令行介绍 + +## 为什么使用 easzctl + +作为 kubeasz 项目的推荐命令行脚本,easzctl 十分轻量、简单;目前它主要包含两类功能:(后续会不断完善补充) + +- 命令集 1:集群层面操作 + - 切换/创建集群 context + - 删除当前集群 + - 显示所有集群 + - 创建集群 + - 创建单机集群(类似 minikube) +- 命令集 2:集群内部操作 + - 增加工作节点 + - 增加主节点 + - 增加 etcd 节点 + - 删除 etcd 节点 + - 删除任意节点 + +集群 context 由 ansible hosts 配置、roles 配置等组成,用以区分不同的 k8s 集群,从而实现多集群的创建和管理;当然 easzctl 命令行不是必须的,你仍旧可以使用之前熟悉的方式安装/管理集群。 + +典型 easzctl 创建管理的集群拓扑如下: + +``` ++----------------+ +-----------------+ +|easzctl 1.1.1.1 | |cluster-aio: | ++--+---+---+-----+ |deploy 4.4.4.4 | + | | | |master 4.4.4.4 | + | | +-------------------->+etcd 4.4.4.4 | + | | |node 4.4.4.4 | + | +--------------+ +-----------------+ + | | + v v ++--+------------+ +---+----------------------------+ +| cluster-1: | | cluster-2: | +| deploy 2.2.2.1| | deploy 3.3.3.1 | +| master 2.2.2.1| | master 3.3.3.1/3.3.3.2 | +| etcd 2.2.2.2| | etcd 3.3.3.1/3.3.3.2/3.3.3.3 | +| node 2.2.2.3| | node 3.3.3.4/3.3.3.5/3.3.3.6 | ++---------------+ +--------------------------------+ +``` + +## 使用 easzctl 举例 + +- 随时运行 `easzctl help` 获取命令行提示信息 + +- 1.创建 context:准备集群名称(例如:test-cluster1),运行 `easzctl checkout test-cluster1` + - 如果 context: test-cluster1 不存在,那么会根据 default 配置创建它;如果存在则切换当前 context 为 test-cluster1 + +- 2.准备 context 以后,根据你的需要配置 ansible hosts 文件和其他配置,然后运行 `easzctl setup` + +- 3.安装成功后,运行 `easzctl list` 显示当前所有集群信息 + +- 4.重复步骤 1/2 可以创建多个集群 + +- 5.切换到某个集群 `easzctl checkout xxxx`,然后执行增加/删除节点操作 + +That's it! 赶紧动手测试吧,欢迎通过 Issues 和 PRs 反馈您的意见和建议! diff --git a/tools/easzctl b/tools/easzctl index 20fb967..e36f330 100755 --- a/tools/easzctl +++ b/tools/easzctl @@ -9,18 +9,18 @@ set -o errexit function usage() { cat < context, or create it if not existed 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) +Commands 2 (in-cluster opration): + add-node To add a kube-node(work node) to the k8s cluster + add-master To add a kube-master(master node) to the k8s cluster + add-etcd To add a etcd-node to the etcd cluster + del-etcd To delete a etcd-node from the etcd cluster + clean-node To clean a node, whatever role the node plays Use "easzctl help " for more information about a given command. EOF @@ -139,21 +139,6 @@ function clean-node() { save_context } -function start-aio(){ - 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) - 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 ############################ function save_context() { @@ -284,6 +269,22 @@ function destroy() { echo -e "\n[WARN] destroy aborted"; return 1; fi } + +function start-aio(){ + 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) + 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 +} + ### Main Lines ################################################## BASEPATH=/etc/ansible