系统要求
- 一台或多台运行兼容 deb/rpm 的 Linux 操作系统的计算机,例如 Ubuntu 或 CentOS。
- 每台机器 2 GB 以上的内存,内存不足时应用会受限制。
- 用作控制平面节点的计算机上至少有 2 个 CPU。
- 集群中所有计算机之间具有完全的网络连接。你可以使用公共网络或专用网络。
节点网络配置:
1 | root@master:~# cat /etc/netplan/50-cloud-init.yaml |
系统依赖
Kubernetes 要求操作系统预装以下依赖:
socat conntrack ipset ebtables chrony ipvsadm
安装系统依赖
1 | apt install socat conntrack ebtables ipset chrony ipvsadm -y |
在线安装会自动download依赖包进行安装
KubeKey 已为部分 Linux 发行版制作了预编译的依赖包,可在 iso-latest 获取。 支持的具体发行版与构建方式详见 依赖包管理。
一、获取KubeKey
- 方式一: Release 页面
在 Release 页面获取对应的二进制文件。
- 方式二: 执行脚本下载KubeKey最新版本
1 | export KKZONE=cn |
| 原文件 | 解压后文件 |
|---|---|
| kubekey-v4.x.x-linux-amd64.tar.gz | kk:为 KubeKey 的二进制文件 |
| web-installer.tgz | dist:Web 页面资源。 host-check.yaml,kubernetes,kubesphere:任务模板文件。 schema:配置文件。 README.md:安装说明文档。 |
| package.sh | 离线安装包的构建脚本。 |
[!NOTE]
在线安装
二、安装K8s
2.1创建节点配置文件,执行以下命令创建文件
1 | root@master:~# ./kk create inventory -o . |
节点配置文件如下:
1 | root@master:~# cat inventory.yaml |
[!note]
密码字段字符串需用引号引起来
2.2 创建安装配置文件
1 | root@master:~# ./kk create config --with-kubernetes v1.34 -o . |
1 | root@master:~# cat config-v1.34.yaml |
三、安装Kubernetes
1 | ./kk create cluster -i inventory.yaml -c config.yaml |
四、启用 kubectl 自动补全
KubeKey 默认不启用 kubectl 自动补全。
前置条件:确保已安装 bash-autocompletion 并正常工作。
1 | # 安装 bash-completion |
五、删除集群
[!note]
清理包括网络资源、容器运行时、DNS hosts等配置
1 | ./kk delete cluster -i inventory.yaml --all --with-data |
六、添加节点
方式一:清单文件
1 | ./kk add nodes -i inventory.yaml -c config.yaml |
方式二:Add Nodes via Command-Line Flags
Ensure
inventory.yamldefines the connection information for the nodes to be added.Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16spec:
hosts:
node1:
connector:
type: ssh
host: 192.168.1.101
port: 22
user: root
password: 123456
node2:
connector:
type: ssh
host: 192.168.1.102
port: 22
user: root
password: 123456Execute the following command to add nodes and specify their roles:
1
./kk add nodes --control-plane node1 --worker node2 -i inventory.yaml -c config.yaml --override
--control-plane: Specifies the hostnames to be added as control plane nodes. Multiple nodes are separated by commas.--worker: Specifies the hostnames to be added as worker nodes. Multiple nodes are separated by commas.--etcd: Specifies the hostnames to be added as etcd nodes. Multiple nodes are separated by commas.--override: After successful execution, automatically adds the nodes to the corresponding groups and updatesinventory.yaml.