一、关于 Kubekey 工具

1.1、Kubekey 概念相关
  • KubeKey 是北京青云科技股份有限公司(青云QingCloud)开源、KubeSphere 社区用 Go 语言开发的 一个 Kubernetes 集群自动化部署工具‌。

  • KubeKey 能够帮助企业一键在公有云或数据中心快速搭建 Kubernetes 集群,提供单节点、多节点、集群相关插件安装,以及集群升级与运维。

  • KubeKey 支持安装 Kubernetes、KubeSphere 及相关插件,安装过程简单而友好。KubeKey 不仅能帮助用户在线创建集群,还能作为离线安装解决方案。

  • KubeKey 用 Go 语言开发,支持多种安装模式,可以分别安装 Kubernetes 和 KubeSphere 或二者同时安装,既方便又高效,为用户提供了灵活的安装选择。

1.2、Kubekey 的使用场景
  • 仅安装 Kubernetes 集群

  • 使用一个命令同时安装 Kubernetes 和 Kubephere

  • 扩缩 Kubernetes 集群

  • 升级 Kubernetes 集群

  • 安装 Kubernetes 相关的插件(Registry、Chart、YAML )​

1.3、KubeKey 的主要特点
  • 多平台支持‌:可以在Linux、macOS和Windows等操作系统上使用。
  • ‌多场景支持‌:支持单节点、多节点、高可用、离线等多种部署场景。
  • ‌安全可靠‌:采用最佳实践进行部署,保证集群的安全性和可靠性‌。
  • ‌可扩展性‌:支持通过插件的方式扩展功能,用户可以根据需求自定义插件。
  • 安装简单:使用Go语言开发,相比其它安装程序,确保其安装的成功率。
  • ‌简单易用‌:采用YAML文件进行配置,编写简单的YAML文件即可进行集群部署。

二、Kubekey 的安装相关

2.1、Kubekey 的安装选项
  • 最小安装:只安装 Kubernetes 集群
  • 同时安装:安装 Kubernetes 和 KubeSphere 一条命令完成
  • 离线安装:在无法访问外部网络的环境中安装 Kubernetes 或 KubeSphere
  • 高可用安装:安装具有多个控制平面节点和 etcd 节点的高可用 Kubernetes 集群
2.2、Kubekey 安装集群的方式
  • 命令行的方式:使用 KK 命令得到配置文件后进行编辑,引用配置文件进行安装,安装包是 “kubekey-v3.X.X-linux-amd64.tar.gz” 格式
  • 图形化的方式:使用 KK 命令后调用出图形化的界面后根据提示操作,安装包是 “kubekey-v3.X-alpha.1-console-linux-amd64.tar.gz” 格式

三、Kubekey 命令行方式部署K8S集群

3.1、系统环境准备
# 1、 系统的基本初始化部 ( 所有主机节点 )

[root@localhost ~]# echo -e "nameserver  114.114.114.114  \nnameserver 202.96.209.5"  >> /etc/resolv.conf
[root@localhost ~]# echo -e "192.168.10.201  node201\n192.168.10.202  node202\n192.168.10.203  node203\n"  >> /etc/hosts
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# yum -y install epel-release net-tools sysstat vim gcc gcc-c++ curl wget git telnet ntp zip unzip

[root@localhost ~]# setenforce 0
[root@localhost ~]# sed -i 's/enforcing/disabled/' /etc/selinux/config
[root@localhost ~]# systemctl stop firewalld && systemctl disable firewalld

[root@localhost ~]# systemctl start ntpd && systemctl enable ntpd
[root@localhost ~]# timedatectl set-timezone "Asia/Shanghai"
[root@localhost ~]# ntpdate time1.aliyun.com


# 2、安装容器的依赖 ( 所有主机节点 )

[root@localhost ~]# swapoff -a
[root@localhost ~]# sed -ri 's/.*swap.*/#&/' /etc/fstab

[root@localhost ~]# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
[root@localhost ~]# sysctl -p

[root@localhost ~]# modprobe br_netfilter
[root@localhost ~]# lsmod | grep br_netfilter
[root@localhost ~]# sysctl --system

[root@localhost ~]# echo "net.bridge.bridge-nf-call-ip6tables = 1" >> /etc/sysctl.conf
[root@localhost ~]# echo "net.bridge.bridge-nf-call-iptables = 1" >> /etc/sysctl.conf
[root@localhost ~]# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
[root@localhost ~]# sysctl -p
   
[root@localhost ~]# yum -y install ipset ipvsadm
[root@localhost ~]# cat > /etc/sysconfig/modules/ipvs.modules
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack
EOF

[root@localhost ~]# chmod +x /etc/sysconfig/modules/ipvs.modules
[root@localhost ~]# /bin/bash /etc/sysconfig/modules/ipvs.modules
[root@localhost ~]# lsmod | grep -e ip_vs -e nf_conntrack
 
[root@localhost ~]# yum -y install conntrack socat


# 3、SSH 免密操作 ( 只在Master主机节点 )

[root@node201 ~]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
[root@node201 ~]# ssh-copy-id node202
[root@node201 ~]# ssh-copy-id node203

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
3.2、安装包相关准备
### 1、获取安装包相关


# 1.1、第一种方式:(受限于网络,有时需要执行多次)

执行下载命令,获取最新版的 kk
[root@localhost ~]# curl -sfL https://get-kk.kubesphere.io | sh -

指定具体版本的命令
[root@localhost ~]# curl -sfL https://get-kk.kubesphere.io | VERSION=v3.0.13 sh -


# 1.2、直接下载二进制包 (推进方式)

下载地址:https://github.com/kubesphere/kubekey/tags

[root@node201 ~]# tar -zxvf kubekey-v3.0.13-linux-amd64.tar.gz



### 2、KK 命令相关使用

[root@node201 ~]# mv kk /usr/local/bin

[root@node201 ~]# kk -h
Deploy a Kubernetes or KubeSphere cluster efficiently, flexibly and easily. There are three scenarios to use KubeKey.
1. Install Kubernetes only
2. Install Kubernetes and KubeSphere together in one command
3. Install Kubernetes first, then deploy KubeSphere on it using https://github.com/kubesphere/ks-installer

Usage:
  kk [command]

Available Commands:
  add         Add nodes to kubernetes cluster
  alpha       Commands for features in alpha
  artifact    Manage a KubeKey offline installation package
  certs       cluster certs
  completion  Generate shell completion scripts
  create      Create a cluster or a cluster configuration file
  delete      Delete node or cluster
  help        Help about any command
  init        Initializes the installation environment
  plugin      Provides utilities for interacting with plugins
  upgrade     Upgrade your cluster smoothly to a newer version with this command
  version     print the client version information

Use "kk [command] --help" for more information about a command.

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
3.3、具体的安装过程
3.3.1、配置文件说明
# 1、 查看下支持的 K8S 的版本
[root@node201 ~]# ./kk version --show-supported-k8s
v1.19.0
v1.19.8
v1.19.9
... ...
v1.26.5
v1.27.0
v1.27.1
v1.27.2


# 2、创建K8S集群配置文件
[root@node201 ~]# ./kk cre