利用KubeKey安装Kubernetes

概述

官方网站:KubeKey (kubesphere.com.cn)

KubeKey(由 Go 语言开发)是一种全新的安装工具,替代了以前使用的基于 ansible 的安装程序。KubeKey 为您提供灵活的安装选择,您可以仅安装 Kubernetes,也可以同时安装 Kubernetes 和 KubeSphere。

KubeSphere 是 GitHub上的一个开源项目,是成千上万名社区用户的聚集地。很多用户都在使用 KubeSphere 运行工作负载。对于在 Linux 上的安装,KubeSphere 既可以部署在云端,也可以部署在本地环境中,例如 AWS EC2、Azure VM 和裸机等。

KubeKey 的几种使用场景:

  • 仅安装 Kubernetes;
  • 使用一个命令同时安装 Kubernetes 和 KubeSphere;
  • 扩缩集群;
  • 升级集群;
  • 安装 Kubernetes 相关的插件(Chart 或 YAML)。

我们利用其安装Kubernetes

安装步骤

下载KubeKey

运行以下命令,以确保您从正确的区域下载 KubeKey。

export KKZONE=cn

运行以下命令来下载 KubeKey:

curl -sfL https://get-kk.kubesphere.io | VERSION=v2.2.2 sh -

KubeKey 的最新版本 (v2.2.2),可以更改命令中的版本号来下载特定的版本

准备Linux 主机

系统要求

系统 最低要求(每个节点)
Ubuntu 16.04,18.04,20.04, 22.04 CPU:2 核,内存:4 G,硬盘:40 G
Debian Buster,Stretch CPU:2 核,内存:4 G,硬盘:40 G
CentOS 7.x CPU:2 核,内存:4 G,硬盘:40 G
Red Hat Enterprise Linux 7 CPU:2 核,内存:4 G,硬盘:40 G
SUSE Linux Enterprise Server 15 /openSUSE Leap 15.2 CPU:2 核,内存:4 G,硬盘:40 G

节点要求

  • 所有节点必须都能通过 SSH 访问。
  • 所有节点时间同步。
  • 所有节点都应使用 sudo/curl/openssl/tar。

容器运行时
KubeKey 会默认安装最新版本的 Docker。或者,也可以在创建集群前手动安装 Docker 或其他容器运行时。

支持的容器运行时 版本
Docker 19.3.8+
containerd 最新版
CRI-O(试验版,未经充分测试) 最新版
iSula(试验版,未经充分测试) 最新版

依赖项要求
KubeKey 可以一同安装 Kubernetes 和 KubeSphere。根据要安装的 Kubernetes 版本,需要安装的依赖项可能会不同。

依赖项 Kubernetes 版本 ≥ 1.18 Kubernetes 版本 < 1.18
socat 必须 可选,但建议安装
conntrack 必须 可选,但建议安装
ebtables 可选,但建议安装 可选,但建议安装
ipset 可选,但建议安装 可选,但建议安装

网络和 DNS 要求

  • 确保 /etc/resolv.conf 中的 DNS 地址可用,否则,可能会导致集群中的 DNS 出现问题。
  • 关闭防火墙规则或安全组。
  • 支持的 CNI 插件:Calico 和 Flannel。

KubeKey 所有受支持的 Kubernetes 版本

运行 ./kk version --show-supported-k8s,查看能使用 KubeKey 安装的所有受支持的 Kubernetes 版本

[email protected]:~# ./kk version --show-supported-k8s
。。。
v1.21.2
v1.21.3
v1.21.4
v1.21.5
v1.21.6
v1.21.7
v1.21.8
v1.21.9
v1.21.10
v1.21.11
v1.21.12
v1.21.13
v1.22.0
v1.22.1
v1.22.2
v1.22.3
v1.22.4
v1.22.5
v1.22.6
v1.22.7
v1.22.8
v1.22.9
v1.22.10
v1.23.0
v1.23.1
v1.23.2
v1.23.3
v1.23.4
v1.23.5
v1.23.6
v1.23.7
v1.23.8
v1.24.0
v1.24.1

可以看到,还不支持最新的1.25版本。

但是,若需使用 KubeKey 来安装 Kubernetes 和 KubeSphere 3.3.0,请参见下表以查看所有受支持的 Kubernetes 版本。

KubeSphere 版本 受支持的 Kubernetes 版本
v3.3.0 v1.19.x、v1.20.x、v1.21.x、v1.22.x、v1.23.x(实验性支持)

创建Cluster配置文件并修改

./kk create config -f config-sample.yaml

[email protected]:/home/zyi#./kk create config -f config-sample.yaml
[email protected]:/home/zyi# vim config-sample.yaml 

apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:
  name: test-cluster
spec:
  hosts:
  - {name: cp4, address: 172.16.10.10, internalAddress: 172.16.10.10, password: "cisco123"}
  - {name: worker41, address: 172.16.10.11, internalAddress: 172.16.10.11, password: "cisco123"}
  roleGroups:
    etcd:
    - cp4
    control-plane:
    - cp4
    worker:
    - cp4
    - worker41
  controlPlaneEndpoint:
    ## Internal loadbalancer for apiservers 
    # internalLoadbalancer: haproxy

    domain: lb.kubesphere.local
    address: ""
    port: 6443
  kubernetes:
    version: v1.24.1
    clusterName: cluster24.smartx.lab
    autoRenewCerts: true
    containerManager: containerd
  etcd:
    type: kubekey
  network:
    plugin: calico
    kubePodsCIDR: 10.244.64.0/18
    kubeServiceCIDR: 10.244.0.0/18
    ## multus support. https://github.com/k8snetworkplumbingwg/multus-cni
    multusCNI:
      enabled: false
  registry:
    privateRegistry: ""
    namespaceOverride: ""
    registryMirrors: []
    insecureRegistries: []
  addons: []

以上配置使用:

  • 两节点cp4/worker41;
  • Runtime-Containerd
  • Kubernetes 1.24.1
  • CNI-Calico

    运行kk创建集群

    ./kk create config -f config-sample.yaml

    [email protected]:/home/zyi# export KKZONE=cn 
    [email protected]:/home/zyi# ./kk create cluster -f config-sample.yaml 
    
     _   __      _          _   __           
    | | / /     | |        | | / /           
    | |/ / _   _| |__   ___| |/ /  ___ _   _ 
    |    \| | | | '_ \ / _ \    \ / _ \ | | |
    | |\  \ |_| | |_) |  __/ |\  \  __/ |_| |
    \_| \_/\__,_|_.__/ \___\_| \_/\___|\__, |
                                      __/ |
                                     |___/
    
    12:16:04 UTC [GreetingsModule] Greetings
    12:16:05 UTC message: [worker41]
    Greetings, KubeKey!
    12:16:05 UTC message: [cp4]
    Greetings, KubeKey!
    12:16:05 UTC success: [worker41]
    12:16:05 UTC success: [cp4]
    12:16:05 UTC [NodePreCheckModule] A pre-check on nodes
    12:16:05 UTC success: [worker41]
    12:16:05 UTC success: [cp4]
    12:16:05 UTC [ConfirmModule] Display confirmation form...
    
    Continue this installation? [yes/no]: yes
    12:16:08 UTC success: [LocalHost]
    12:16:08 UTC [NodeBinariesModule] Download installation binaries
    12:16:08 UTC message: [localhost]
    downloading amd64 kubeadm v1.24.1 ...
    12:16:08 UTC message: [localhost]
    kubeadm is existed
    12:16:08 UTC message: [localhost]
    downloading amd64 kubelet v1.24.1 ...
    12:16:09 UTC message: [localhost]
    kubelet is existed
    12:16:09 UTC message: [localhost]
    downloading amd64 kubectl v1.24.1 ...
    12:16:09 UTC message: [localhost]
    kubectl is existed
    12:16:09 UTC message: [localhost]
    downloading amd64 helm v3.6.3 ...
    ...
    
    Please check the result using the command:
    
          kubectl get pod -A

在Master上面查看集群情况

[email protected]:/home/zyi# kubectl get node
NAME       STATUS     ROLES                  AGE   VERSION
cp4        NotReady   control-plane,worker   44s   v1.24.1
worker41   NotReady   worker                 8s    v1.24.1

[email protected]:/home/zyi# kubectl get po -A
NAMESPACE     NAME                                      READY   STATUS    RESTARTS   AGE
kube-system   calico-kube-controllers-f9f9bbcc9-b2xxx   1/1     Running   0          22s
kube-system   calico-node-mcbpn                         1/1     Running   0          22s
kube-system   calico-node-zbm8p                         1/1     Running   0          22s
kube-system   coredns-f657fccfd-6tnvr                   1/1     Running   0          43s
kube-system   coredns-f657fccfd-rqwsm                   1/1     Running   0          43s
kube-system   kube-apiserver-cp4                        1/1     Running   0          58s
kube-system   kube-controller-manager-cp4               1/1     Running   0          57s
kube-system   kube-proxy-2q4p9                          1/1     Running   0          23s
kube-system   kube-proxy-ml5sx                          1/1     Running   0          43s
kube-system   kube-scheduler-cp4                        1/1     Running   0          56s
kube-system   nodelocaldns-4srdw                        1/1     Running   0          23s
kube-system   nodelocaldns-fd9gx                        1/1     Running   0          43s

你可能感兴趣的:(kubernetes)