环境初始化和安装 keepalibed、haproxy

设置yum源,可以查看Linux安装部署docker博客文章。(安装在所有节点)

设置环境初始化,可以查看Linux安装部署高可用k8s集群博客文章。(安装在相应的节点)。

使用 KubeKey 部署 KubeSphere 和 Kubernetes

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
# github受限,确保您从正确的区域下载
export KKZONE=cn

# 下载 KubeKey
curl -sfL https://get-kk.kubesphere.io | VERSION=v3.0.7 sh -

# 使 kk 成为可执行文件
chmod +x kk

# 默认配置创建一个示例配置文件 config-sample.yaml
./kk create config --with-kubesphere v3.1.1 --with-kubernetes v1.21.5

# 编辑文件以添加机器信息、配置负载均衡器
vi config-sample.yaml

...
spec:
hosts:
- {name: master01, address: 192.168.18.111, internalAddress: 192.168.18.111, user: root, password: Testing123}
- {name: master02, address: 192.168.18.112, internalAddress: 192.168.18.112, user: root, password: Testing123}
- {name: node01, address: 192.168.18.113, internalAddress: 192.168.18.113, user: root, password: Testing123}
- {name: node02, address: 192.168.18.114, internalAddress: 192.168.18.114, user: root, password: Testing123}
roleGroups:
etcd:
- master01
- master02
control-plane:
- master01
- master02
worker:
- node01
- node02
controlPlaneEndpoint:
domain: lb.kubesphere.local
address: 192.168.18.110 # The VIP address 若不创建高可用多主多从填""
port: 16443
...

# 需要安装的软件
yum install -y conntrack socat

# 开始安装
./kk create cluster -f config-sample.yaml
1
2
# 如果要卸载则执行
./kk delete cluster config-sample.yaml

验证安装

  • 查看日志

    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
  • 访问 Web 控制台

    通过 NodePort (IP:30880)(所有的节点机器的IP包括虚拟IP) 使用默认帐户和密码 (admin/P@88w0rd) 访问 Web 控制台

    You need to specify one of the following:

断电重启 KubeSphere

  • 关闭交换区

    1
    swapoff -a
  • k8s节点会自动重启,node节点需要重新加入master

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    # 查询master上的token
    [root@master01 ~]# kubeadm token list

    # 生成token
    [root@master01 ~]# kubeadm token create --print-join-command
    # 生成永久token
    [root@master01 ~]# kubeadm token create --ttl 0 --print-join-command
    kubeadm join lb.kubesphere.local:16443 --token xm4xza.iwzmethxedddy7dt --discovery-token-ca-cert-hash sha256:dc10b5360071cc5b7a305c34f21b4b2bfed445bad9290f7d6a4c9eba2f15ba23

    # node01节点加入master01
    [root@node01 ~]# rm -rf /etc/kubernetes/kubelet.conf
    [root@node01 ~]# rm -rf /etc/kubernetes/pki/ca.crt
    [root@node01 ~]# kubeadm join 192.168.18.111:16443 --token xm4xza.iwzmethxedddy7dt --discovery-token-ca-cert-hash sha256:dc10b5360071cc5b7a305c34f21b4b2bfed445bad9290f7d6a4c9eba2f15ba23

    # node02节点加入master02
    [root@node02 ~]# rm -rf /etc/kubernetes/kubelet.conf
    [root@node02 ~]# rm -rf /etc/kubernetes/pki/ca.crt
    [root@node02 ~]# kubeadm join 192.168.18.112:16443 --token xm4xza.iwzmethxedddy7dt --discovery-token-ca-cert-hash sha256:dc10b5360071cc5b7a305c34f21b4b2bfed445bad9290f7d6a4c9eba2f15ba23