安装搭建KubeSphere环境
KubeSphere是一个以Kubernetes为内核的云原生分布式操作系统,它的架构可以非常方便地使第三方应用与云原生生态组件进行即插即用的集成,支持云原生应用在多云与多集群的统一分发和运维管理
KubeSphere
KubeSphere概述
Kubernetes的默认dashboard功能有限,Kubesphere集成了很多套件,功能强大,但是集群要求较高
KubeSphere 是一款开源项目,在目前主流容器调度平台 Kubernetes 之上构建的企业级分布式多租户容器管理平台,提供简单易用的操作界面以及向导式操作方式,在降低用户使用容器调度平台学习成本的同时,极大降低开发、测试、运维的日常工作的复杂度。
KubeSphere官网:https://kubesphere.io/
文档地址:https://kubesphere.io/zh/docs/v3.3/introduction/what-is-kubesphere/
文档地址:https://v2-1.docs.kubesphere.io/docs/zh-CN/introduction/what-is-kubesphere/
kubesphere最大的优点是可以自定义安装可插拔的功能组件,并且所有组件都是开源免费的。
Kuboard也不错,集群要求不高
Kuboard :https://kuboard.cn/support/
Kuboard是一款免费的 Kubernetes管理工具,提供了丰富的功能,结合已有或新建的代码仓库、镜像仓库、CI/CD工具等,可以便捷的搭建一个生产可用的 Kubernetes 容器云平台,轻松管理和运行云原生应用。您也可以直接将 Kuboard 安装到现有的 Kubernetes 集群,通过 Kuboard 提供的 Kubernetes RBAC 管理界面,将 Kubernetes 提供的能力开放给您的开发/测试团队。
安装方式
kubesphere具有如下可选安装选项
All-in-One:在单个节点上安装 KubeSphere(仅为让用户快速熟悉 KubeSphere)。
多节点安装:在多个节点上安装 KubeSphere(用于测试或开发)。
在 Linux 上离线安装:将 KubeSphere 的所有镜像打包(便于在 Linux 上进行离线安装)。
高可用安装:安装具有多个节点的高可用 KubeSphere 集群,该集群用于生产环境。
最小化安装:仅安装 KubeSphere 所需的最少系统组件。以下是最低资源要求:
2 个 CPU
4 GB 运行内存
40 GB 存储空间
全家桶安装:安装 KubeSphere 的所有可用系统组件,例如 DevOps、服务网格、告警等。
这里使用All-in-One安装模式,仅需准备一台主机。官方文档写的很详细,照着来就行,这里纯粹记录个人开发过程、踩坑过程。
环境准备
硬件推荐配置
2 核 CPU,4 GB 内存,40 GB 磁盘空间
节点要求
节点必须能够通过 SSH
连接。
节点上可以使用 sudo
/curl
/openssl
/tar
命令
可用的容器
集群必须有一个可用的运行容器运行。如果使用KubeKey搭建集群,KubeKey会默认安装最新版本的Docker。或者可以在创建集群前手动安装Docker或其他容器。
依赖项要求
KubeKey可以将Kubernetes和KubeSphere一同安装。针对不同的Kubernetes版本,需要安装的依赖项可能有所不同。
可以参考以下列表,查看是否需要提前在节点上安装相关的依赖项。
依赖项 | Kubernetes 版本 ≥ 1.18 | Kubernetes 版本 < 1.18 |
---|---|---|
socat | 必须 | 可选但建议 |
conntrack | 必须 | 可选但建议 |
ebtables | 可选但建议 | 可选但建议 |
ipset | 可选但建议 | 可选但建议 |
安装依赖
yum install -y socat conntrack ebtables ipset
安装kubesphere
下载KubeKey
确保从正确的区域下载KubeKey
export KKZONE=cn
下载KubeKey
# 可以修改命令中的版本号下载指定版本
curl -sfL https://get-kk.kubesphere.io | VERSION=v2.2.1 sh -
为kk添加可执行权限
chmod +x kk
[root@administrator ~]# export KKZONE=cn
[root@administrator ~]# curl -sfL https://get-kk.kubesphere.io | VERSION=v2.2.1 sh -
Downloading kubekey v2.2.1 from https://kubernetes.pek3b.qingstor.com/kubekey/releases/download/v2.2.1/kubekey-v2.2.1-linux-amd64.tar.gz ...
Kubekey v2.2.1 Download Complete!
[root@administrator ~]# ls
kk
[root@administrator ~]# chmod +x kk
开始安装
只需执行一个命令即可进行安装,其模板如下
./kk create cluster [--with-kubernetes version] [--with-kubesphere version]
若要同时安装Kubernetes和KubeSphere,参考以下示例命令
./kk create cluster --with-kubernetes v1.22.10 --with-kubesphere v3.3.0
执行该命令后,KubeKey将检查安装环境,结果显示在一张表格中。输入yes继续安装流程。
[root@administrator ~]# chmod +x kk
[root@administrator ~]# ./kk create cluster --with-kubernetes v1.22.10 --with-kubesphere v3.3.0
WARN[0000] Failed to decode the keys ["storage.options.override_kernel_check"] from "/etc/containers/storage.conf".
_ __ _ _ __
| | / / | | | | / /
| |/ / _ _| |__ ___| |/ / ___ _ _
| \| | | | '_ \ / _ \ \ / _ \ | | |
| |\ \ |_| | |_) | __/ |\ \ __/ |_| |
\_| \_/\__,_|_.__/ \___\_| \_/\___|\__, |
__/ |
|___/
19:24:11 CST [GreetingsModule] Greetings
19:24:11 CST message: [administrator]
Greetings, KubeKey!
19:24:11 CST success: [administrator]
19:24:11 CST [NodePreCheckModule] A pre-check on nodes
19:24:12 CST success: [administrator]
19:24:12 CST [ConfirmModule] Display confirmation form
+---------------+------+------+---------+----------+-------+-------+---------+-----------+--------+----------+------------+------------+-------------+------------------+--------------+
| name | sudo | curl | openssl | ebtables | socat | ipset | ipvsadm | conntrack | chrony | docker | containerd | nfs client | ceph client | glusterfs client | time |
+---------------+------+------+---------+----------+-------+-------+---------+-----------+--------+----------+------------+------------+-------------+------------------+--------------+
| administrator | y | y | y | y | y | y | | y | y | 20.10.18 | 1.6.8 | y | | | CST 19:24:12 |
+---------------+------+------+---------+----------+-------+-------+---------+-----------+--------+----------+------------+------------+-------------+------------------+--------------+
This is a simple check of your environment.
Before installation, ensure that your machines meet all requirements specified at
https://github.com/kubesphere/kubekey#requirements-and-recommendations
Continue this installation? [yes/no]: yes
经过一段时间后,当出现如下内容时,代表安装结束。
clusterrolebinding.rbac.authorization.k8s.io/ks-installer unchanged
deployment.apps/ks-installer unchanged
clusterconfiguration.installer.kubesphere.io/ks-installer created
19:31:45 CST success: [administrator]
#####################################################
### Welcome to KubeSphere! ###
#####################################################
Console: http://172.22.4.21:30880
Account: admin
Password:
19:50:32 CST success: [administrator]
19:50:32 CST Pipeline[CreateClusterPipeline] execute successfully
Installation is complete.
Please check the result using the command:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-installer -o jsonpath='{.items[0].metadata.name}') -f
[root@administrator ~]#
验证安装结果
输入以下命令以检查安装结果
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控制台的IP地址和端口号,默认的NodePort是30880。
#####################################################
### Welcome to KubeSphere! ###
#####################################################
Console: http://172.22.4.21:30880
Account: admin
Password: P@88w0rd
NOTES:
1. After you log into the console, please check the
monitoring status of service components in
"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 2022-09-12 19:50:24
#####################################################
检查KubeSphere相关组件的运行状况,确保所有组件都是Running状态。
[root@master ~]# kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system calico-kube-controllers-75ddb95444-h5nsb 1/1 Running 0 30m
kube-system calico-node-jknjr 1/1 Running 0 30m
kube-system coredns-5495dd7c88-ln7cd 1/1 Running 0 30m
kube-system coredns-5495dd7c88-m5hts 1/1 Running 0 30m
kube-system kube-apiserver-master 1/1 Running 0 31m
kube-system kube-controller-manager-master 1/1 Running 0 31m
kube-system kube-proxy-tkj72 1/1 Running 0 30m
kube-system kube-scheduler-master 1/1 Running 0 31m
kube-system nodelocaldns-58hgk 1/1 Running 0 30m
kube-system openebs-localpv-provisioner-6c9dcb5c54-hl2rz 1/1 Running 0 30m
kube-system snapshot-controller-0 1/1 Running 0 29m
kubesphere-controls-system default-http-backend-56d9d4fdf7-29b57 1/1 Running 0 28m
kubesphere-controls-system kubectl-admin-7685cdd85b-jx27j 1/1 Running 0 26m
kubesphere-monitoring-system alertmanager-main-0 2/2 Running 0 27m
kubesphere-monitoring-system kube-state-metrics-89f49579b-v6qkp 3/3 Running 0 27m
kubesphere-monitoring-system node-exporter-v9p25 2/2 Running 0 27m
kubesphere-monitoring-system notification-manager-deployment-6ff7974fbd-cwvbq 2/2 Running 0 26m
kubesphere-monitoring-system notification-manager-operator-58bc989b46-xmdv8 2/2 Running 0 26m
kubesphere-monitoring-system prometheus-k8s-0 2/2 Running 0 27m
kubesphere-monitoring-system prometheus-operator-fc9b55959-q979p 2/2 Running 0 27m
kubesphere-system ks-apiserver-5db774f4f-v5h2w 1/1 Running 0 28m
kubesphere-system ks-console-64b56f967-4p6xq 1/1 Running 0 28m
kubesphere-system ks-controller-manager-7b5f77b47f-ck6z5 1/1 Running 0 28m
kubesphere-system ks-installer-9b4c69688-pts8c 1/1 Running 0 30m
访问kubesphere
访问控制台: NodeIP:30880
使用默认的帐户和密码登录
概览
集群状态
卸载KubeSphere和Kubernetes
按照快速入门 (All-in-One) 安装的 KubeSphere
./kk delete cluster
如果是使用高级模式安装的 KubeSphere(使用配置文件创建)
./kk delete cluster [-f config-sample.yaml]
异常处理
最初使用阿里云2C4G服务器,部署安装后发现存在异常情况。
在应用负载 -> 容器组发现2个异常容器
查看容器异常告警提示
错误提示为:0/1 nodes are available: 1 Insufficient cpu.
0/1 节点可用。1 CPU不足
安装kubesphere时提示需要2C4G,这里使用阿里云服务器2C4G,由于原本有一些服务在运行,因此猜测导致运行kubesphere的Pod服务时资源不足。
在应用负载 =》工作负载 =》 有状态副本集中找到异常Pod并点击进入
更多操作 =》编辑配置文件
找到资源设置相关项,调整资源设置,具体多少就多多尝试
resources:
limits:
cpu: xxm
memory: xxMi
requests:
cpu: xxm
memory: xxMi
最后,成功修复一个Pod,另一个Pod始终无法修复。后来各种解决方案尝试解决,无解!由于是阿里云服务器,于是果断升级服务器,异常得以解决。
多节点安装
多节点集群由至少一个主节点和一个工作节点组成。可以使用任何节点作为任务机来执行安装任务,也可以在安装之前或之后根据需要新增节点
对于多节点安装,需要通过指定配置文件来创建集群。
依赖项要求
KubeKey 可以一同安装 Kubernetes 和 KubeSphere。根据要安装的 Kubernetes 版本,需要安装的依赖项可能会不同。您可以参考下表,查看是否需要提前在节点上安装相关依赖项。
依赖项 | Kubernetes 版本 ≥ 1.18 | Kubernetes 版本 < 1.18 |
---|---|---|
socat | 必须 | 可选,但建议安装 |
conntrack | 必须 | 可选,但建议安装 |
ebtables | 可选,但建议安装 | 可选,但建议安装 |
ipset | 可选,但建议安装 | 可选,但建议安装 |
由于我这里当前各个节点缺少相关必要依赖,故执行安装操作
yum install socat conntrack y
如果缺少依赖,会有如下类似提示
[root@node01 work]# ./kk create cluster --with-kubernetes v1.23.10 --with-kubesphere v3.4.1
_ __ _ _ __
| | / / | | | | / /
| |/ / _ _| |__ ___| |/ / ___ _ _
| \| | | | '_ \ / _ \ \ / _ \ | | |
| |\ \ |_| | |_) | __/ |\ \ __/ |_| |
\_| \_/\__,_|_.__/ \___\_| \_/\___|\__, |
__/ |
|___/
12:21:18 CST [GreetingsModule] Greetings
12:21:19 CST message: [node01]
Greetings, KubeKey!
12:21:19 CST success: [node01]
12:21:19 CST [NodePreCheckModule] A pre-check on nodes
12:21:19 CST success: [node01]
12:21:19 CST [ConfirmModule] Display confirmation form
+--------+------+------+---------+----------+-------+-------+---------+-----------+--------+--------+------------+------------+-------------+------------------+--------------+
| name | sudo | curl | openssl | ebtables | socat | ipset | ipvsadm | conntrack | chrony | docker | containerd | nfs client | ceph client | glusterfs client | time |
+--------+------+------+---------+----------+-------+-------+---------+-----------+--------+--------+------------+------------+-------------+------------------+--------------+
| node01 | y | y | y | y | | y | | | y | 25.0.3 | 1.6.28 | | | | CST 12:21:19 |
+--------+------+------+---------+----------+-------+-------+---------+-----------+--------+--------+------------+------------+-------------+------------------+--------------+
12:21:19 CST [ERRO] node01: conntrack is required.
12:21:19 CST [ERRO] node01: socat is required.
This is a simple check of your environment.
Before installation, ensure that your machines meet all requirements specified at
https://github.com/kubesphere/kubekey#requirements-and-recommendations
下载 KubeKey
下载指定版本的KubeKey,同时为kk
添加可执行权
[root@node01 work]# curl -sfL https://get-kk.kubesphere.io | VERSION=v3.0.13 sh -
Downloading kubekey v3.0.13 from https://kubernetes.pek3b.qingstor.com/kubekey/releases/download/v3.0.13/kubekey-v3.0.13-linux-amd64.tar.gz ...
Kubekey v3.0.13 Download Complete!
[root@node01 work]# ls
kk
[root@node01 work]# chmod +x kk
创建示例配置文件
创建示例配置文件,命令如下:
./kk create config [--with-kubernetes version] [--with-kubesphere version] [(-f | --file) path]
执行如下命令,将创建默认文件config-sample.yaml
./kk create cluster --with-kubernetes v1.23.10 --with-kubesphere v3.4.1
编辑配置文件
针对该配置文件,主要修改各个主机节点信息,以下信息为参考,具体查看官方文档
apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:
name: sample
spec:
hosts:
- {name: node01, address: 192.168.5.211, internalAddress: 192.168.5.211, privateKeyPath: "~/.ssh/id_rsa"}
- {name: node02, address: 192.168.5.212, internalAddress: 192.168.5.212, privateKeyPath: "~/.ssh/id_rsa"}
- {name: node03, address: 192.168.5.213, internalAddress: 192.168.5.213, privateKeyPath: "~/.ssh/id_rsa"}
roleGroups:
etcd:
- node01
control-plane:
- node01
worker:
- node02
- node03
创建集群
使用配置文件创建集群,整个安装过程可能需要 10 到 20 分钟,具体取决于计算机和网络环境。
./kk create cluster -f config-sample.yaml
部分关键执行日志如下:
[root@node01 work]# ./kk create cluster -f config-sample.yaml
_ __ _ _ __
| | / / | | | | / /
| |/ / _ _| |__ ___| |/ / ___ _ _
| \| | | | '_ \ / _ \ \ / _ \ | | |
| |\ \ |_| | |_) | __/ |\ \ __/ |_| |
\_| \_/\__,_|_.__/ \___\_| \_/\___|\__, |
__/ |
|___/
12:32:48 CST [GreetingsModule] Greetings
12:32:49 CST message: [node03]
Greetings, KubeKey!
12:32:49 CST message: [node01]
Greetings, KubeKey!
12:32:49 CST message: [node02]
Greetings, KubeKey!
12:32:49 CST success: [node03]
12:32:49 CST success: [node01]
12:32:49 CST success: [node02]
12:32:49 CST [NodePreCheckModule] A pre-check on nodes
12:32:50 CST success: [node02]
12:32:50 CST success: [node01]
12:32:50 CST success: [node03]
12:32:50 CST [ConfirmModule] Display confirmation form
+--------+------+------+---------+----------+-------+-------+---------+-----------+--------+--------+------------+------------+-------------+------------------+--------------+
| name | sudo | curl | openssl | ebtables | socat | ipset | ipvsadm | conntrack | chrony | docker | containerd | nfs client | ceph client | glusterfs client | time |
+--------+------+------+---------+----------+-------+-------+---------+-----------+--------+--------+------------+------------+-------------+------------------+--------------+
| node01 | y | y | y | y | y | y | | y | y | 25.0.3 | 1.6.28 | | | | CST 12:32:50 |
| node02 | y | y | y | y | y | y | | y | y | 25.0.3 | 1.6.28 | | | | CST 12:32:50 |
| node03 | y | y | y | y | y | y | | y | y | 25.0.3 | 1.6.28 | | | | CST 12:32:50 |
+--------+------+------+---------+----------+-------+-------+---------+-----------+--------+--------+------------+------------+-------------+------------------+--------------+
This is a simple check of your environment.
Before installation, ensure that your machines meet all requirements specified at
https://github.com/kubesphere/kubekey#requirements-and-recommendations
Continue this installation? [yes/no]: yes
12:32:59 CST success: [LocalHost]
12:32:59 CST [NodeBinariesModule] Download installation binaries
12:32:59 CST message: [localhost]
downloading amd64 kubeadm v1.23.10 ...
12:32:59 CST message: [localhost]
kubeadm is existed
12:32:59 CST message: [localhost]
downloading amd64 kubelet v1.23.10 ...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 118M 100 118M 0 0 1018k 0 0:01:59 0:01:59 --:--:-- 1040k
安装成功后,将出现如下日志信息
#####################################################
### Welcome to KubeSphere! ###
#####################################################
Console: http://192.168.5.211:30880
Account: admin
Password: P@88w0rd
NOTES:
1. After you log into the console, please check the
monitoring status of service components in
"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 2024-02-29 12:51:11
#####################################################
12:51:13 CST success: [node01]
12:51:13 CST Pipeline[CreateClusterPipeline] execute successfully
Installation is complete.
Please check the result using the command:
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
启用kubectl自动补全
# Install bash-completion
yum install bash-completion
# Source the completion script in your ~/.bashrc file
echo 'source <(kubectl completion bash)' >>~/.bashrc
# Add the completion script to the /etc/bash_completion.d directory
kubectl completion bash >/etc/bash_completion.d/kubectl
访问kubesphere
访问IP:30880
,使用默认帐户和密码 (admin/P@88w0rd
) 访问 KubeSphere 的 Web 控制台
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)