[Kubernetes (K8S) kubeasz] Use kubeasz to deploy a Kubernetes Cluster

kubeasz

kubeasz is committed to providing tools for rapid deployment of high-availability k8s clusters, and also strives to become a reference book for k8s practice and use; deployment based on binary mode and automation using ansible-playbook; not only provides one-click installation scripts, but also can be divided according to the installation guide Step by step to install each component.

  • Cluster features TLS mutual authentication, RBAC authorization, multi-Master high availability, support for

  • Network Policy, backup and recovery, offline installation

  • Cluster version kubernetes v1.18, v1.19, v1.20, v1.21

  • Operating system CentOS/RedHat 7, Debian 9/10, Ubuntu 16.04/18.04/20.04

  • Runtime docker 19.03.x, 20.10.x containerd v1.4.4

  • Network calico, cilium, flannel, kube-ovn, kube-router

Quick guide

The following is a quick experience of the testing and development environment of the k8s cluster-single node deployment (aio), which is much more convenient and simpler than the official minikube in the domestic environment.

Basic system configuration

  • Prepare a virtual machine with 2G RAM/30G hard disk

  • Minimize the installation of Ubuntu 16.04 server or CentOS 7 Minimal

  • Configure basic network, update source, SSH login, etc.


Note: Make sure to start the installation on a clean system. You cannot use the environment where kubeadm or other k8s releases have been installed.


Download the file

Download tool script ezdown, for example use kubeasz version 3.0.0

1
2
3
4
5
$ export release=3.0.0

$ curl -C- -fLO --retry 3 https://github.com/easzlab/kubeasz/releases/download/${release}/ezdown

$ chmod +x ./ezdown

See ezdown command

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ ./ezdown
Usage: ezdown [options] [args]
option: -{DdekSz}
-C stop&clean all local containers
-D download all into "/etc/kubeasz"
-P download system packages for offline installing
-R download Registry(harbor) offline installer
-S start kubeasz in a container
-d <ver> set docker-ce version, default "20.10.5"
-e <ver> set kubeasz-ext-bin version, default "0.9.4"
-k <ver> set kubeasz-k8s-bin version, default "v1.21.0"
-m <str> set docker registry mirrors, default "CN"(used in Mainland,China)
-p <ver> set kubeasz-sys-pkg version, default "0.4.1"
-z <ver> set kubeasz version, default "3.1.0"

Download the latest recommended k8s/docker and other versions by default (for more parameters of ezdown, run ./ezdown to view)

1
$ ./ezdown -D

Optional download offline system package (applicable to situations where yum/apt warehouse cannot be used)

1
$ ./ezdown -P

After the above script runs successfully, all files (kubeasz code, binary, offline mirroring) have been organized and placed in the directory /etc/kubeasz

/etc/kubeasz contains the release code of kubeasz version ${release}
/etc/kubeasz/bin contains binary files such as k8s/etcd/docker/cni
/etc/kubeasz/down contains the offline container image required for cluster installation
/etc/kubeasz/down/packages contains the basic system software needed for cluster installation

Install the cluster

Run kubeasz as a container, see the start_kubeasz_docker function in the ezdown script for details

1
$ ./ezdown -S

Install aio cluster with default configuration

1
$ docker exec -it kubeasz ezctl start-aio

Verify the installation

If it prompts kubectl: command not found, log out and log in again with SSH, and the environment variable will take effect.

1
2
3
4
$ kubectl version # Verify the cluster version
$ kubectl get node # Verify that the node is ready (Ready)
$ kubectl get pod -A # Verify cluster pod status, network plug-in, coredns, metrics-server, etc. have been installed by default
$ kubectl get svc -A # Verify cluster service status

Log in to the dashboard to view and manage the cluster. For more information, please refer to the dashboard document

Clean up

Please feel free to toss the K8S development and test environment created by the above steps. If you encounter errors, try to solve them by checking logs, searching on the Internet, submitting issues, etc.; of course, you can also clean up the cluster and recreate it.

On the host, follow the steps below to clean up

  • Clean up the cluster docker exec -it kubeasz ezctl destroy default

  • Clean up running containers ./ezdown -C

  • Clean up the container image docker system prune -a

  • Stop docker service systemctl stop docker

  • Delete docker file

    • umount /var/run/docker/netns/default

    • umount /var/lib/docker/overlay

    • rm -rf /var/lib/docker /var/run/docker

After the above cleanup script is successfully executed, it is recommended to restart the node to ensure that the remaining virtual network card, routing and other information are cleaned up.

References

[1] easzlab/kubeasz: 使用Ansible脚本安装K8S集群,介绍组件交互原理,方便直接,不受国内网络环境影响 - https://github.com/easzlab/kubeasz

[2] kubeasz/quickStart.md at master · easzlab/kubeasz - https://github.com/easzlab/kubeasz/blob/master/docs/setup/quickStart.md

[3] Kubernetes - https://kubernetes.io/

[4] Ansible is Simple IT Automation - https://www.ansible.com/