在 Linux 上以 All-in-One 模式安装 KubeSphere

发布时间 2023-12-22 16:51:32作者: sxFu9528

1、什么是 KubeSphere

   KubeSphere 是在 Kubernetes 之上构建的面向云原生应用的分布式操作系统,完全开源,支持多云与多集群管理,提供全栈的 IT 自动化运维能力,简化企业的 DevOps 工作流。它的架构可以非常方便地使第三方应用与云原生生态组件进行即插即用 (plug-and-play) 的集成。

  作为全栈的多租户容器平台,KubeSphere 提供了运维友好的向导式操作界面,帮助企业快速构建一个强大和功能丰富的容器云平台。KubeSphere 为用户提供构建企业级 Kubernetes 环境所需的多项功能,例如多云与多集群管理、Kubernetes 资源管理、DevOps、应用生命周期管理、微服务治理(服务网格)、日志查询与收集、服务与网络、多租户管理、监控告警、事件与审计查询、存储管理、访问权限控制、GPU 支持、网络策略、镜像仓库管理以及安全管理等。

  对于刚接触 KubeSphere 并想快速上手该容器平台的用户,All-in-One 安装模式是最佳的选择,它能够帮助您零配置快速部署 KubeSphere 和 Kubernetes。

2、环境配置

硬件推荐配置

操作系统最低配置
Ubuntu 16.0418.0420.0422.04 2 核 CPU,4 GB 内存,40 GB 磁盘空间
Debian BusterStretch 2 核 CPU,4 GB 内存,40 GB 磁盘空间
CentOS 7.x 2 核 CPU,4 GB 内存,40 GB 磁盘空间
Red Hat Enterprise Linux 7 2 核 CPU,4 GB 内存,40 GB 磁盘空间
SUSE Linux Enterprise Server 15/openSUSE Leap 15.2 2 核 CPU,4 GB 内存,40 GB 磁盘空间

本次部署环境配置

name ip 操作系统 cpu 内存 磁盘空间
master 192.168.43.128 CentOS Linux release 7.9.2009 (Core) 2 4 50
node1 192.168.43.129 CentOS Linux release 7.9.2009 (Core) 2 4 50
node2 192.168.43.130 CentOS Linux release 7.9.2009 (Core) 2 4 50

 节点要求

  • 节点必须能够通过 SSH 连接。
  • 节点上可以使用 sudo/curl/openssl/tar 命令。

容器运行时

您的集群必须有一个可用的容器运行时。如果您使用 KubeKey 搭建集群,KubeKey 会默认安装最新版本的 Docker。或者,您也可以在创建集群前手动安装 Docker 或其他容器运行时。

支持的容器运行时版本
Docker 20.10.16
containerd 最新版

依赖项要求

KubeKey 可以将 Kubernetes 和 KubeSphere 一同安装。针对不同的 Kubernetes 版本,需要安装的依赖项可能有所不同。您可以参考以下列表,查看是否需要提前在节点上安装相关的依赖项。

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

3、部署

#  安装依赖组件
yum install -y ebtables socat ipset conntrack

3.1、安装docker

yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast

yum -y install docker-ce-20.10.16-3.el7 docker-ce-cli-20.10.16

# 启动docker
systemctl enable docker && systemctl start docker

# 设置docker镜像加速器
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://gqk8w9va.mirror.aliyuncs.com"]
}
EOF
# 重启docker使配置生效
systemctl restart docker

docker info|grep "Registry Mirrors" -A 1

3.2、kubernetes相关

# 设置kubernetes仓库

cat > /etc/yum.repos.d/kubernetes.repo <<EOF                                                                                        
[kubernetes]                                                                                                                                               
name=Kubernetes                                                                                                                                             
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64                                                                               
enabled=1                                                                                                                                                   
gpgcheck=0                                                                                                                                                 
repo_gpgcheck=0                                                                                                                                             
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg                                                                                             
        http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg                                                                                   
EOF               

yum makecache fast  

安装kubelet和kubectl

yum install -y kubelet-1.17.9 kubectl-1.17.9

 4、下载kubekey

# 有几种方式下载,可参考官网:【https://kubesphere.io/zh/docs/v3.4/quick-start/all-in-one-on-linux/】

git clone https://github.com/kubesphere/kubekey.git
curl -sfL https://get-kk.kubesphere.io | VERSION=v3.0.7 sh -

# 使用kubekey安装kubernetes和kubesphere

./kk create cluster --with-kubernetes v1.22.12 --with-kubesphere v3.3.2

 # 验证安装结果

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

# 根据打印提示浏览器输入地址:http://192.168.43.128:30880/

遇到的坑

执行./kk create cluster --with-kubernetes v1.22.12 --with-kubesphere v3.3.2 命令拉取镜像时报错

downloading image: registry.cn-beijing.aliyuncs.com/kubesphereio/pause:3.5
12:22:47 UTC message: [master]
pull image failed: Failed to exec command: sudo -E /bin/bash -c "env PATH=$PATH docker pull registry.cn-beijing.aliyuncs.com/kubesphereio/pause:3.5 --platform amd64" 
"--platform" is only supported on a Docker daemon with experimental features enabled: Process exited with status 1

原因是docker 运行其他平台容器,需要使用 --platform 参数来指定平台,开始安装docker时安装得版本较低,不支持--platform参数,docker 19.03.9 及以上的版本才支持 --platform 参数,升级docker版本解决。

 

【参考:https://kubesphere.io/zh/docs/v3.4/quick-start/all-in-one-on-linux/】