卡卷网
当前位置:卡卷网 / 每日看点 / 正文

Kubesphere 与 Rancher 有什么区别?

作者:卡卷网发布时间:2024-12-08 15:29浏览数量:102次评论数量:0次

KubeSphere V4已经开源一段时间了,推出了全新的 KubeSphere 架构:KubeSphere LuBan,它构建在 Kubernetes 之上,支持高度可配置和可扩展。
该版本只安装KubeSphere Core核心组件,即可实现KubeSphre Web控制台的使用。前几天在2核4G的VM虚拟机体验了一下。安装过程极快,服务非常精简。

本文演示在线联网部署,在线安装相对简单,以下部署过程较多简写,必要位置进行了注意事项和详细说明。如要查看具体安装过程和含义可浏览官方文档 在 Linux 上安装 Kubernetes 和 KubeSphere

服务器配置:all in one形式部署

主机名IPCPU内存架构OS用途
node1192.168.150.12824x86_64Ubuntu24.04.1主集群
node1192.168.150.12924x86_64Ubuntu24.04.1成员集群

前提条件

  • 官网原话:

集群节点的操作系统和版本须为 Ubuntu 16.04、Ubuntu 18.04、Ubuntu 20.04、Ubuntu 22.04、Debian 9、Debian 10、CentOS 7、CentOS Stream、RHEL 7、RHEL 8、SLES 15 或 openSUSE Leap 15。多台服务器的操作系统可以不同。关于其它操作系统和版本支持,请联系 KubeSphere 技术支持。

Tips:也可以联系笔者

  • 安装依赖项和初始化操作系统请看 2.4 初始化操作系统章节,在线安装非常简单。

创建 Kubernetes 集群

2.1 创建安装目录

home目录下创建ks目录,用于安装部署K8S+KubeSphere

此处之所以在/home目录下安装,是之前有些操作系统默认根目录下只有50G空间,而更大的空间在/home目录下。笔者所在公司可能需要到用户提供的服务器和操作系统安装集群,为避免空间占用不足,直接到/home下新建。

mkdir -p /home/ks cd /home/ks

2.2 下载kk


export KKZONE=cn curl -sfL https://get-kk.kubesphere.io | sh -

该命令会下载最新版kk,不同版本kk,所依赖的服务(如:docker,etcd等)和镜像版本(如:pause)不同。若需要指定版本的kk,可使用命令

curl -sfL https://get-kk.kubesphere.io | VERSION={version} sh -

version为需要的版本。如:curl -sfL https://get-kk.kubesphere.io | VERSION=v3.1.5 sh -

2.3 创建集群配置文件

查看kk支持的k8s版本

./kk version --show-supported-k8s v1.19.0 v1.19.8 v1.19.9 v1.19.15 ... v1.29.10 v1.30.0 v1.30.1 v1.30.2 v1.30.3 v1.30.4 v1.30.5 v1.30.6 v1.31.0 v1.31.1 v1.31.2

由于本次重在体验和测试,这里使用较新的1.30.6版本

./kk create config --with-kubernetes v1.30.6

2.4 初始化操作系统


./kk init os

该命令kk会自动判断操作系统以安装依赖项和进行必要的初始化配置。关于这点官方文档是使用的apt install去下载依赖项,可能考虑节点多的话,需要每次下载/拷贝kk麻烦。实际上在线部署使用kk init os还是很方便的,笔者在线部署场景经常使用,命令少,好记。注意:离线部署,该命令不可用。

初始化前:

未初始化时,直接创建集群会报错提示并中断执行。


Kubesphere 与 Rancher 有什么区别?  第1张


初始化后:


Kubesphere 与 Rancher 有什么区别?  第2张


2.5 修改配置文件

由于笔者用惯了docker,此处修改容器运行时为docker。生产环境k8s 1.24以上版本建议还是使用containerd

apiVersion: kubekey.kubesphere.io/v1alpha2 kind: Cluster metadata: name: sample spec: hosts: - {name: node1, address: 192.168.150.128, internalAddress: 192.168.150.128, user: root, password: "123@213"} roleGroups: etcd: - node1 control-plane: - node1 worker: - node1 controlPlaneEndpoint: ## Internal loadbalancer for apiservers # internalLoadbalancer: haproxy domain: lb.kubesphere.local address: "" port: 6443 system: ntpServers: - node1 # 配置时间同步,所有节点服务器同步node1的时间 timezone: "Asia/Shanghai" kubernetes: version: v1.30.6 clusterName: cluster.local autoRenewCerts: true # 此处修改运行时为:docker containerManager: docker # 部署 kubernetes v1.24+ 版本,建议将 containerManager 设置为 containerd etcd: type: kubekey network: plugin: calico kubePodsCIDR: 10.233.64.0/18 kubeServiceCIDR: 10.233.0.0/18 ## multus support. https://github.com/k8snetworkplumbingwg/multus-cni multusCNI: enabled: false registry: privateRegistry: "" namespaceOverride: "" registryMirrors: [] insecureRegistries: [] addons: []

说明: 具体参数含义可查看官方文档:在 Linux 上安装 Kubernetes 和 KubeSphere,这里写一下注意事项

config-sample.yaml 配置文件的 spec:hosts 参数

官方介绍

  • address 服务器的 SSH 登录 IP 地址。
  • internalAddress 服务器在子网内部的 IP 地址。

注:若部署的服务器在同一区域,内网IP可以互通,address 和internalAddress 都使用内网IP。之前遇到过有的小伙伴买的云服务器做测试,address使用公网IP,由于部署过程通信拷贝文件走了address,公网带宽又低。导致创建集群时异常的慢。

2.6 创建k8s集群

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

由于运行时使用了docker,执行后会有如下Notice提示

root@gj-VM:/home/ks# ./kk create cluster -f config-sample.yaml _ __ _ _ __ | | / / | | | | / / | |/ / _ _| |__ ___| |/ / ___ _ _ | \| | | | '_ \ / _ \ \ / _ \ | | | | |\ \ |_| | |_) | __/ |\ \ __/ |_| | \_| \_/\__,_|_.__/ \___\_| \_/\___|\__, | __/ | |___/ 11:39:29 CST [GreetingsModule] Greetings 11:39:29 CST message: [node1] Greetings, KubeKey! 11:39:29 CST success: [node1] 11:39:29 CST [NodePreCheckModule] A pre-check on nodes 11:39:29 CST success: [node1] 11:39:29 CST [ConfirmModule] Display confirmation form +-------+------+------+---------+----------+-------+-------+---------+-----------+--------+--------+------------+------------+-------------+------------------+--------------+ | name | sudo | curl | openssl | ebtables | socat | ipset | ipvsadm | conntrack | chrony | docker | containerd | nfs client | ceph client | glusterfs client | time | +-------+------+------+---------+----------+-------+-------+---------+-----------+--------+--------+------------+------------+-------------+------------------+--------------+ | node1 | y | y | y | y | y | y | y | y | y | | y | | | | CST 11:39:29 | +-------+------+------+---------+----------+-------+-------+---------+-----------+--------+--------+------------+------------+-------------+------------------+--------------+ 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 Install k8s with specify version: v1.30.6 [Notice] For Kubernetes v1.24 and later, dockershim has been deprecated. Current runtime is set to Docker and `cri-dockerd` will be installed to support Kubernetes v1.24 and later. Yoc can also specify a container runtime other than Docker to install Kubernetes v1.24 or later. You can set "spec.kubernetes.containerManager" in the configuration file to "containerd" or add "--container-manager containerd" to the "./kk create cluster" command. For more information, see: https://github.com/kubesphere/kubekey/blob/master/docs/commands/kk-create-cluster.md https://kubernetes.io/docs/setup/production-environment/container-runtimes/#container-runtimes https://kubernetes.io/blog/2022/02/17/dockershim-faq/ https://github.com/Mirantis/cri-dockerd Continue this installation? [yes/no]:

输入y或者yes开始安装部署

大概等待10分钟,部署完成

11:50:23 CST success: [LocalHost] 11:50:23 CST Pipeline[CreateClusterPipeline] execute successfully Installation is complete. Please check the result using the command: kubectl get pod -A

ps:若发现下载服务过程很慢,可以尝试ctrl + c后重新输入export KKZONE=cn。有个小伙伴电脑,出现同一个窗口,输入了export KKZONE=cn后下载了两个服务后不生效了。需要重新输入后再次执行create cluster才可以,不确定是否为当前版本bug,暂未排查原因。

2.7 验证

root@gj-VM:/home/ks# kubectl get pod -A NAMESPACE NAME READY STATUS RESTARTS AGE kube-system calico-kube-controllers-848b87ffbc-6hh97 1/1 Running 0 29m kube-system calico-node-ks586 1/1 Running 0 29m kube-system coredns-848f88b9dc-hsmh9 1/1 Running 0 29m kube-system coredns-848f88b9dc-k9djl 1/1 Running 0 29m kube-system kube-apiserver-node1 1/1 Running 0 29m kube-system kube-controller-manager-node1 1/1 Running 0 29m kube-system kube-proxy-2l2rx 1/1 Running 0 29m kube-system kube-scheduler-node1 1/1 Running 0 29m kube-system nodelocaldns-l59qn 1/1 Running 0 29m

可以看到k8s所有pod运行中,k8s已经部署完成。

安装 KubeSphere

本章节只部署KubeSphere4.1.2的ks-core核心组件,扩展组件暂不安装。安装完成后,即可访问 KubeSphere Web 控制台,k8s和ks的核心功能已可使用。

3.1 安装helm

curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash root@gj-VM:/home/ks# curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 11903 100 11903 0 0 13760 0 --:--:-- --:--:-- --:--:-- 13760 [WARNING] Could not find git. It is required for plugin installation. Helm v3.16.3 is available. Changing from version v3.14.3. Downloading https://get.helm.sh/helm-v3.16.3-linux-amd64.tar.gz Verifying checksum... Done. Preparing to install helm into /usr/local/bin helm installed into /usr/local/bin/helm

3.2 安装 KubeSphere Core

helm upgrade --install -n kubesphere-system --create-namespace ks-core https://charts.kubesphere.io/main/ks-core-1.1.3.tgz --debug --wait --set global.imageRegistry=swr.cn-southwest-2.myhuaweicloud.com/ks

部署过程非常快,快到让人怀疑,2H4G的硬件,不到2分钟安装完了,比之前版本离线部署还快。

Thank you for choosing KubeSphere Helm Chart. Please be patient and wait for several seconds for the KubeSphere deployment to complete. 1. Wait for Deployment Completion Confirm that all KubeSphere components are running by executing the following command: kubectl get pods -n kubesphere-system 2. Access the KubeSphere Console Once the deployment is complete, you can access the KubeSphere console using the following URL: http://192.168.150.128:30880 3. Login to KubeSphere Console Use the following credentials to log in: Account: admin Password: P@88w0rd

再次查看pod情况

root@node1:~# kubectl get pod -A NAMESPACE NAME READY STATUS RESTARTS AGE kube-system calico-kube-controllers-848b87ffbc-2mqwb 1/1 Running 1 (2m25s ago) 130m kube-system calico-node-kmspv 1/1 Running 1 (2m25s ago) 130m kube-system coredns-9dc95d955-4th25 1/1 Running 1 (2m25s ago) 130m kube-system coredns-9dc95d955-zr77b 1/1 Running 1 (2m25s ago) 130m kube-system kube-apiserver-node1 1/1 Running 1 (2m25s ago) 131m kube-system kube-controller-manager-node1 1/1 Running 1 (2m25s ago) 131m kube-system kube-proxy-rlnsq 1/1 Running 1 (2m25s ago) 130m kube-system kube-scheduler-node1 1/1 Running 1 (2m25s ago) 131m kube-system nodelocaldns-rx4w2 1/1 Running 1 (2m25s ago) 130m kubesphere-system extensions-museum-d77fddd77-5tqpp 1/1 Running 1 (2m25s ago) 70m kubesphere-system ks-apiserver-59b7c94c77-fpkmv 1/1 Running 1 (2m25s ago) 70m kubesphere-system ks-console-b9ff8948c-687zd 1/1 Running 1 (2m25s ago) 70m kubesphere-system ks-controller-manager-777888fdb8-nlkmr 1/1 Running 1 (2m25s ago) 70m

可以看到kubespehre-system的pod只有4个,kube-sysem的pod有9个,对比k8s1.23和1.22也少了3~4个。也没有其他的ns,整体非常精简。

体验KubeSphere控制平台

4.1 登录

访问http://IP:30080登录ks管理平台


Kubesphere 与 Rancher 有什么区别?  第3张


输入默认用户名密码:admin/P@88w0rd登录,之前版本不会强制要求更改默认密码。4.1.2版本使用默认用户登录后,要求更改默认密码才可后续访问。


Kubesphere 与 Rancher 有什么区别?  第4张


注意:根据海勒姆定律,非必要不修改。此变更,虽提高了安全性,若业务系统有使用的默认用户名密码调用KubeSphere的,影响比较大。需要业务系统同步修改(PS:之前我司有个研发小伙伴写的代码没有使用后创建的账号而用了默认admin/P@88w0rd)。

若想不修改密码继续使用后续功能。可通过以下二种方式规避。

  • 修改浏览器url去掉password/confirm

如,修改192.168.150.128:30880/password/confirm去掉后直接访问192.168.150.128:30880


Kubesphere 与 Rancher 有什么区别?  第5张


  • 先修改成一个复杂密码,然后用复杂密码登录后再修改为P@88w0rd。由于修改过密码之后再登录不会出现强制修改密码。

登录后,此时将会看到全新的ks页面


Kubesphere 与 Rancher 有什么区别?  第6张


4.2 集群管理

点击集群管理,可以看到之前联邦集群的页面,


Kubesphere 与 Rancher 有什么区别?  第7张


进入主集群会看到左侧熟悉的菜单,跟之前的功能基本一致。


Kubesphere 与 Rancher 有什么区别?  第8张


添加其他集群,组建集群联邦


Kubesphere 与 Rancher 有什么区别?  第9张


5.1 概述

如今,各种组织跨不同的云厂商或者在不同的基础设施上运行和管理多个 Kubernetes 集群的做法非常普遍。由于每个 Kubernetes 集群都是一个相对独立的单元,上游社区正在艰难地研究和开发多集群管理解决方案。即便如此,Kubernetes 集群联邦(Kubernetes Cluster Federation,简称 KubeFed)可能是其中一种可行的方法。

5.2 部署成员集群

重复以上步骤,在129,130创建all in one k8s集群

这里使用129作为主集群,添加128为成员集群


Kubesphere 与 Rancher 有什么区别?  第10张


5.3 添加成员集群

获取成员集群的kubeconfig

kubectl config view --raw


Kubesphere 与 Rancher 有什么区别?  第11张


复制 kubeconfig 信息,并修改其中的 clusters:cluster:server 参数

clusters: - cluster: server: https://<member-cluster-node-ip>:6443


Kubesphere 与 Rancher 有什么区别?  第12张


注意:成员集群不要安装kubesphere,否则页面点击创建时会没有反应。通过F12查看开发者选项,可以看到400错误,提示current cluster is managed by another host cluster 'host' 成员集群已经由另一个主集群管理。需要先卸载成员集群中的kubesphere部分helm -n kubesphere-system uninstall ks-core


Kubesphere 与 Rancher 有什么区别?  第13张



Kubesphere 与 Rancher 有什么区别?  第14张


点击下一步后,集群配置不填写,直接点击创建。

注意:成员集群加入过程,成员集群会部署kubesphere相关服务。而成员集群部署kubesphere服务时,直接使用hub.docker镜像,由于访问限制,国内没梯子的话会显示一直镜像拉取失败。

修复措施:将以下相关镜像,重新打标签 。因为可以使用优先本地镜像,就不需要去hub.docker拉取了。

如:

docker tag swr.cn-southwest-2.myhuaweicloud.com/ks/kubesphere/kubectl:v1.27.17 kubesphere/kubectl:v1.27.17 docker tag swr.cn-southwest-2.myhuaweicloud.com/ks/kubesphere/ks-console:v4.1.2 kubesphere/ks-console:v4.1.2


Kubesphere 与 Rancher 有什么区别?  第15张


然而extensions-museum设置的是每次拉取镜像,这时候,我们需要通过edit修改为优先使用本地镜像kubectl edit deployment extensions-museum -n kubesphere-systemIfNotPresent


Kubesphere 与 Rancher 有什么区别?  第16张


待成员集群中的kubesphere-system项目中的pod都启动正常后,返回主集群管理页面,可以看到成员集群已经准备就绪,添加成功。


Kubesphere 与 Rancher 有什么区别?  第17张


点击成员集群,可以进入成员集群管理界面。


Kubesphere 与 Rancher 有什么区别?  第18张



Kubesphere 与 Rancher 有什么区别?  第19张


5.4 创建企业空间

点击工作台-左侧企业空间-创建企业空间,填写名称后选择要创建哪个集群。当选择主集群时会出现提示:当前系统为多集群系统,请尽量避免在主集群上创建资源。主集群负载过高会导致多集群系统稳定性下降。


Kubesphere 与 Rancher 有什么区别?  第20张


5.5 创建项目

点击新建企业空间后,进入企业空间的项目。当有多个集群有该企业空间时,可选择集群,然后创建至哪个集群。


Kubesphere 与 Rancher 有什么区别?  第21张


其他创建/查看应用仓库、工作负载、服务等跟之前一样,具体可自行体验。

到这里,我们用最小化的配置完成了KubeSphere4.1.2的部署,联邦集群的添加。整体使用下来,令人很是心动。若是第一次使用或是学习还是推荐使用该版本的。

本文主要为测试体验Kubesphere4.1.2新版本特性和功能。由于只默认安装了kubesphere核心组件,像之前的Prometheus监控,告警以及日志等都没有安装。如有需要可通过扩展组件,需自行研究安装。若要用于生产环境,也请自行充分测试验证。

END

免责声明:本文由卡卷网编辑并发布,但不代表本站的观点和立场,只提供分享给大家。

卡卷网

卡卷网 主页 联系他吧

请记住:卡卷网 Www.Kajuan.Net

欢迎 发表评论:

请填写验证码