大道至简

学必求其心得,业必贵于专精。

0%

K8S集群创建(KubeSphere)

步骤 1:准备 Linux 机器

8 核 CPU,16 GB 内存,100 GB 磁盘空间

1、节点要求
节点必须能够通过 SSH 连接。
所有节点时间同步.
节点上可以使用 sudo/curl/openssl/tar 命令

/var/lib/docker 路径主要用于存储容器数据,在使用和操作过程中数据量会逐渐增加。因此,在生产环境中,建议为 /var/lib/docker 单独挂载一个硬盘。
CPU 必须为 x86_64,暂时不支持 Arm 架构的 CPU

2、依赖:

1
yum install -y socat  conntrack ebtables  ipset ipvsadm

3、网络和 DNS 要求
确保 /etc/resolv.conf 中的 DNS 地址可用
防火墙或安全组,确保基础结构组件可以通过特定端口相互通信
支持的 CNI 插件:Calico 和 Flannel。

步骤 2:下载 KubeKey

1
2
3
4
5
export KKZONE=cn
curl -sfL https://get-kk.kubesphere.io | VERSION=v2.2.1 sh -

为 kk 添加可执行权限:
chmod +x kk

步骤 3:创建集群

1、创建配置文件

1
2
./kk create config [--with-kubernetes version] [--with-kubesphere version] [(-f | --file) path]
如: ./kk create config --with-kubernetes v1.22.10 --with-kubesphere v3.3.0

2、编辑配置文件
config-sample.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
spec:
hosts:
- {name: master, address: 192.168.147.45, internalAddress: 192.168.147.45, user: root, password: "awifi@123"}
- {name: node1, address: 192.168.147.46, internalAddress: 192.168.147.46, user: root, password: "awifi@123"}
- {name: node2, address: 192.168.147.47, internalAddress: 192.168.147.47, user: root, password: "awifi@123"}

roleGroups:
etcd:
- master
control-plane:
- master
worker:
- node1
- node2
controlPlaneEndpoint:
domain: lb.kubesphere.local
address: ""
port: 6443
  1. 使用配置文件创建集群
    1
    ./kk create cluster -f config-sample.yaml

步骤 4:验证安装结果

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
#####################################################

### Welcome to KubeSphere! ###

#####################################################



Console: http://192.168.0.2:30880

Account: admin

Password: P@88w0rd



NOTES:

1. After you log into the console, please check the

monitoring status of service components in

the "Cluster Management". If any service is not

ready, please wait patiently until all components

are up and running.

2. Please change the default password after login.



#####################################################

https://kubesphere.io 20xx-xx-xx xx:xx:xx

#####################################################

现在,您可以通过 <NodeIP:30880 使用默认帐户和密码 (admin/P@88w0rd) 访问 KubeSphere 的 Web 控制台。

1
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}') -f

kubekey集群维护

1
2
3
4
5
6
7
8
9
10
11
12
13
1、添加节点
kk add nodes -f config-sample.yaml

2、 删除节点
kk delete node <nodeName> -f config-sample.yaml

3、删除集群
kk delete cluster
kk delete cluster [-f config-sample.yaml]

4、集群升级
kk upgrade [--with-kubernetes version] [--with-kubesphere version]
kk upgrade [--with-kubernetes version] [--with-kubesphere version] [(-f | --file) path]