安装搭建KubeSphere环境&&Kubernetes环境

Kubesphere概述

Kubernetes的默认dashboard功能有限,Kubesphere集成了很多套件,功能强大,但是集群要求较高

KubeSphere是一款开源项目,在目前主流容器调度平台Kukernetes之上构建的企业级分布式多租户容器管理平台,提供简单易用的操作界面以及向导式操作方式,在降低用户使用容器调度平台学习成本的同时,极大降低开发调试、测试、运维的日常工作的复杂度

KubeShpere官网:https://kubesphere.io/

文档地址:https://kubersphere.io/zh/docs/v3.3/introduction/what-is-kubesphere/

文档地址:https://v2-1.docs.kubesphere.io/docs/zh-CN/introduction/what-is-kubeshpere/

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,4GB内存,40GB磁盘空间 节点要求 节点必须能通过SSH连接

节点上可以使用sudo/curl/openssl/tar命令

可用的容器

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

依赖项要求

Kubesphere可以将Kubernetes和KubeSphere一同安装,针对不同的Kubernetes版本,需要安装的依赖项可能有所不同

可以参考以下列表,查看是否需要提前在节点上安装相关的依赖项。

安装依赖

yum install -y socat conntrack ebtables ipset

安装Kubesphere

下载KubeKey

确保从正确的区域下载KubeKey

export KKZONE=cn

下载KubeKey

#可以修改命令中的版本号下载指定版本
curl -sfL https://get-kk.kubesphere.io | VERSION=2.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

开始安装 首先需要创建一个配置文件,命令如下

kubeadm config print init-defaults > /etc/kubernetes/kubeadm-config.yaml

然后修改配置文件内容,如下模板,可以直接复制粘贴

apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controlPlaneEndpoint: 192.168.1.10:6443  # 请替换为实际控制平面节点的IP或主机名
apiServer:
  extraArgs:
    authorization-mode: Node,RBAC
  timeoutForControlPlane: 4m0s
controllerManager: {}
dns: {}
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers
kubernetesVersion: v1.23.17
networking:
  dnsDomain: cluster.local
  podSubnet: 172.20.0.0/16
  serviceSubnet: 10.96.0.0/12
scheduler: {}

配置文件修改之后需要导入密钥

sudo kubeadm init phase upload-certs --upload-certs --config /etc/kubernetes/kubeadm-config.yaml

导入密钥成功后就可以安装进行安装了

只需执行一个命令即可安装,其模板如下,ai了一下,原来通过这一个命令就可以安装好k8s集群和可视化平台,但是基本环境还是需要注意的,容易出问题的基本换进就是docker源、交换分区swap、docker驱动要改为systemd

环境配置参考文章:

微信公众号文章
https://mp.weixin.qq.com/s/2FDec7lOXHjDNWDSKulo5Q
CSDN文章
https://blog.csdn.net/chinese_cabbage0/article/details/149203811

是的,通过执行 ./kk create cluster --with-kubernetes v1.23.17 --with-kubesphere v3.0.0 命令,你可以在一个空环境中一键安装 Kubernetes 集群和 KubeSphere 可视化平台。

#获取k8s的版本
kubectl version --short

./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

使用默认的账号密码登录:admin/P@88w0rd 然后提示修改密码,修改即可

卸载KubeSphere和Kubernetes

按照快速入门 (All-in-One) 安装的 KubeSphere

./kk delete cluster

如果是使用高级模式安装的 KubeSphere(使用配置文件创建)

./kk delete cluster [-f config-sample.yaml]

如果可视化平台崩溃,使用如下命令重启一下ks-apiserverks-console的pod

kubectl rollout restart deployment ks-apiserver -n kubesphere-system
kubectl rollout restart deployment ks-console -n kubesphere-system

因为etcd报错后续排错修改使用的命令和解释

# 备份旧证书
sudo mv /etc/ssl/etcd /etc/ssl/etcd.bak
# 将现有的 etcd 证书目录移动到备份目录,以便在需要时恢复。

# 使用 kubeadm 重新生成证书
sudo kubeadm init phase certs etcd-ca
# 使用 kubeadm 重新生成 etcd CA(证书颁发机构)证书。

sudo kubeadm init phase certs etcd-server
# 使用 kubeadm 重新生成 etcd server 的证书。

sudo kubeadm init phase certs etcd-peer
# 使用 kubeadm 重新生成 etcd peer 的证书。

# 修复权限
sudo chown -R etcd:etcd /etc/ssl/etcd/
# 更改证书目录的权限,使其归 etcd 用户和用户组所有。

sudo rm -rf /var/lib/etcd/*
# 删除 etcd 数据目录中的所有数据,清空 etcd 的存储。

ETCDCTL_API=3 etcdctl --endpoints=https://192.168.1.10:2379 --cacert=/etc/ssl/etcd/ssl/ca.pem --cert=/etc/ssl/etcd/ssl/admin-master.pem --key=/etc/ssl/etcd/ssl/admin-master-key.pem endpoint health
# 使用 etcdctl 检查 etcd 集群的健康状态。指定了证书和密钥文件进行认证。

# 重新加载 systemd 管理的服务配置
sudo systemctl daemon-reload
# 重新加载 systemd 管理的所有服务配置,以便识别任何变更。

# 重启 etcd 服务
sudo systemctl restart etcd
# 重启 etcd 服务,使证书更新生效。

# 查看 etcd 服务的状态,确认其是否正常运行
sudo systemctl status etcd
# 查看 etcd 服务的状态。

# 确保 etcd 服务已停止
sudo systemctl stop etcd
# 停止 etcd 服务。

sudo pkill -9 etcd
# 强制杀死所有运行中的 etcd 进程。

# 删除备份的证书(可选,或者移动到其他位置)
sudo mv /etc/ssl/etcd.bak /etc/ssl/etcd.bak.old
# 将备份的证书文件夹重新命名,或者移动到其他位置。

# 重新创建证书目录
sudo mkdir -p /etc/ssl/etcd/ssl
# 创建 etcd 证书存储目录。

sudo chown -R etcd:etcd /etc/ssl/etcd
# 更改证书目录的权限,确保 etcd 用户可以访问。

# 强制重新生成 etcd 相关证书
sudo kubeadm init phase certs etcd-ca --force
# 强制重新生成 etcd CA 证书。

sudo kubeadm init phase certs etcd-server --force
# 强制重新生成 etcd server 证书。

sudo kubeadm init phase certs etcd-peer --force
# 强制重新生成 etcd peer 证书。

# 设置正确的权限
sudo chown -R etcd:etcd /etc/ssl/etcd
# 设置正确的权限,确保 etcd 用户对证书文件夹具有访问权限。

sudo rm -rf /var/lib/etcd/*
# 清除 etcd 数据目录中的所有文件。

# 重新加载 systemd 管理的服务配置
sudo systemctl daemon-reload
# 重新加载 systemd 管理的服务配置。

# 启动 etcd 服务
sudo systemctl start etcd
# 启动 etcd 服务。

# 查看 etcd 服务的详细状态,确保其正在运行
sudo systemctl status etcd -l
# 查看 etcd 服务的详细状态,确保其正在运行。

ETCDCTL_API=3 etcdctl --endpoints=https://192.168.1.10:2379 --cacert=/etc/ssl/etcd/ssl/ca.pem --cert=/etc/ssl/etcd/ssl/admin-master.pem --key=/etc/ssl/etcd/ssl/admin-master-key.pem endpoint health
# 再次检查 etcd 集群的健康状态,确保其正常运行。

# 查看证书 `peer-master.pem` 的详细信息,并提取其中的 "Subject Alternative Name" 信息
sudo openssl x509 -in /etc/ssl/etcd/ssl/peer-master.pem -text -noout | grep -A1 "Subject Alternative Name"

# 使用 `kk` 工具删除 Kubernetes 集群
./kk delete cluster
# 删除现有的 Kubernetes 集群。

# 使用 `kk` 工具创建 Kubernetes 集群,指定 Kubernetes 和 KubeSphere 的版本
./kk create cluster --with-kubernetes v1.23.17 --with-kubesphere v3.2.1
# 创建新的 Kubernetes 集群并安装 KubeSphere。

# 查看 `kubesphere-system` 命名空间下的所有 pod 的状态
kubectl get pods -n kubesphere-system
# 查看 `kubesphere-system` 命名空间下的所有 pod。

# 查看 `kubesphere-system` 命名空间下的所有服务
kubectl get svc -n kubesphere-system
# 查看 `kubesphere-system` 命名空间下的所有服务。

# 查看 `kubesphere-system` 命名空间下 `ks-installer` 应用的日志
kubectl logs -n kubesphere-system -l app=ks-installer
# 查看 `kubesphere-system` 命名空间下 `ks-installer` 应用的日志。

# 查看 Kubernetes 集群中的所有节点
kubectl get nodes
# 查看 Kubernetes 集群中的所有节点。

# 查看 `kubesphere-system` 命名空间下 `ks-apiserver` 应用的日志
kubectl logs -n kubesphere-system -l app=ks-apiserver
# 查看 `kubesphere-system` 命名空间下 `ks-apiserver` 应用的日志。

# 查看 `kubesphere-system` 命名空间下 `ks-console` 应用的日志
kubectl logs -n kubesphere-system -l app=ks-console
# 查看 `kubesphere-system` 命名空间下 `ks-console` 应用的日志。

# 查看 `kubesphere-system` 命名空间下 `ks-controller-manager` 应用的日志
kubectl logs -n kubesphere-system -l app=ks-controller-manager
# 查看 `kubesphere-system` 命名空间下 `ks-controller-manager` 应用的日志。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值