kubespher的安装

   之前的安装或多或少都有一些坑,官方建议还是安装集群的。官方的安装文档和演示都是以云服务器为主,可我比较穷买不起云服务器,查看了官方的资料,找到在物理机安装kubesphere的方法。我是随便创建了三台虚拟机。

介绍

KubeSphere 除了可以在云上安装,还可以在裸机上安装。由于在裸机上没有虚拟层,基础设施的开销大大降低,从而可以给部署的应用提供更多的计算和存储资源,硬件效率得到提高。以下示例介绍如何在裸机上安装 KubeSphere。

准备工作

  • 您需要了解如何在多节点集群中安装 KubeSphere。有关详情,请参见多节点安装
  • 您的环境中需要有足够的服务器和网络冗余。
  • 如果搭建生产环境,建议您提前准备持久化存储并创建 StorageClass。如果搭建开发测试环境,您可以直接使用集成的 OpenEBS 配置 LocalPV 存储服务。

准备 Linux 主机

本教程使用 3 台物理机,硬件配置为 DELL 620 Intel (R) Xeon (R) CPU E5-2640 v2 @ 2.00GHz (32G memory)。在这 3 台物理机上将安装 CentOS Linux release 7.6.1810 (Core) 操作系统,用于 KubeSphere 最小化安装。

安装 CentOS

请提前下载并安装CentOS 镜像。请确保根目录已至少分配 200 GB 空间用于存储 Docker 镜像(如果 KubeSphere 仅用于测试,您可以跳过这一步)。

有关系统要求的更多信息,请参见系统要求

三台主机的角色分配如下,供参考。

主机 IP 地址

主机名

角色

192.168.60.152

master1

master1, etcd

192.168.60.153

worker1

worker

192.168.60.154

worker2

worker

设置网卡

  1. 清空网卡配置。
ifdown em1
ifdown em2
rm -rf /etc/sysconfig/network-scripts/ifcfg-em1
rm -rf /etc/sysconfig/network-scripts/ifcfg-em2

2.创建 bond 网卡。

nmcli con add type bond con-name bond0 ifname bond0 mode 802.3ad ip4 192.168.66.152/24 gw4 192.168.60.254

3.设置 bond 模式。

nmcli con mod id bond0 bond.options mode=802.3ad,miimon=100,lacp_rate=fast,xmit_hash_policy=layer2+3

4.将物理网卡绑定至 bond。

nmcli con add type bond-slave ifname em1 con-name em1 master bond0
nmcli con add type bond-slave ifname em2 con-name em2 master bond0

5.修改网卡模式。

vi /etc/sysconfig/network-scripts/ifcfg-bond0
BOOTPROTO=static

6.重启 Network Manager。

systemctl restart NetworkManager
nmcli con # Display NIC information

7.修改主机名和 DNS。

hostnamectl set-hostname worker-1
vim /etc/resolv.conf

设置时间

  1. 开启时间同步。
yum install -y chrony
systemctl enable chronyd
systemctl start chronyd
timedatectl set-ntp true

2.设置时区。

timedatectl set-timezone Asia/Shanghai

3.检查 ntp-server 是否可用。

chronyc activity -v

设置防火墙

执行以下命令停止并禁用 firewalld 服务:

iptables -F
systemctl status firewalld
systemctl stop firewalld
systemctl disable firewalld

更新系统包和依赖项

执行以下命令更新系统包并安装依赖项:

这个太墨迹了,我没更新,有需要的可以更新一下

yum update
yum install openssl openssl-devel
yum install socat
yum install epel-release
yum install conntrack-tools

安装docker环境

sudo yum remove docker*
sudo yum install -y yum-utils

#配置docker的yum地址
sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo


#安装指定版本
sudo yum install -y docker-ce-20.10.7 docker-ce-cli-20.10.7 containerd.io-1.4.6

#	启动&开机启动docker
systemctl enable docker --now

# docker加速配置
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://82m9ar63.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

下载 KubeKey

KubeKey 是新一代 Kubernetes 和 KubeSphere 安装器,可帮助您以简单、快速、灵活的方式安装 Kubernetes 和 KubeSphere。

请按照以下步骤下载 KubeKey。

先执行以下命令以确保您从正确的区域下载 KubeKey:

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

为 kk 文件添加可执行权限。

chmod +x kk

创建多节点集群

您可用使用 KubeKey 同时安装 Kubernetes 和 KubeSphere,通过自定义配置文件中的参数创建多节点集群。

创建安装有 KubeSphere 的 Kubernetes 集群(例如使用 --with-kubesphere v3.2.0):

./kk create config --with-kubernetes v1.21.5 --with-kubesphere v3.2.0

系统将创建默认的 config-sample.yaml 文件。您可以根据您的环境修改此文件。

vi config-sample.yaml
apiVersion: kubekey.kubesphere.io/v1alpha1
kind: Cluster
metadata:
  name: config-sample
spec:
  hosts:
  - {name: master1, address: 192.168.60.152, internalAddress: 192.168.60.152, user: root, password: P@ssw0rd}
  - {name: worker1, address: 192.168.60.153, internalAddress: 192.168.60.153, user: root, password: P@ssw0rd}
  - {name: worker2, address: 192.168.60.154, internalAddress: 192.168.60.154, user: root, password: P@ssw0rd}
  roleGroups:
    etcd:
    - master1
    master:
    - master1
    worker:
    - worker1
    - worker2
  controlPlaneEndpoint:
    domain: lb.kubesphere.local
    address: ""                    
    port: 6443

执行以下命令使用自定义的配置文件创建集群:

先安装一个前置工具

yum install -y conntrack
./kk create cluster -f config-sample.yaml

打印的信息

+---------+------+------+---------+----------+-------+-------+-----------+---------+------------+-------------+------------------+--------------+
| name    | sudo | curl | openssl | ebtables | socat | ipset | conntrack | docker  | nfs client | ceph client | glusterfs client | time         |
+---------+------+------+---------+----------+-------+-------+-----------+---------+------------+-------------+------------------+--------------+
| worker2 | y    | y    | y       | y        |       | y     | y         | 20.10.7 |            |             |                  | CST 15:48:21 |
| worker1 | y    | y    | y       | y        |       | y     | y         | 20.10.7 |            |             |                  | CST 15:48:21 |
| master  | y    | y    | y       | y        |       | y     | y         | 20.10.7 |            |             |                  | CST 15:48:21 |
+---------+------+------+---------+----------+-------+-------+-----------+---------+------------+-------------+------------------+--------------+

验证安装

安装结束后,您可以执行以下命令查看安装日志:

kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

如果返回欢迎日志,则安装成功。

**************************************************
#####################################################
###              Welcome to KubeSphere!           ###
#####################################################
Console: http://192.168.60.152:30880
Account: admin
Password: P@88w0rd
NOTES:
  1. After you log into the console, please check the
     monitoring status of service components in
     the "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             20xx-xx-xx xx:xx:xx
#####################################################

最后安装成功了就是这样

登录控制台

您可以使用默认的帐户和密码 admin/P@88w0rd 登录 KubeSphere 控制台并开始使用 KubeSphere。请在登录后修改默认密码。

启用可插拔组件(可选)

以上示例演示了默认的最小化安装流程。如需启用 KubeSphere 的其他组件,请参考启用可插拔组件

优化系统

更新系统。

yum update

添加所需的内核引导参数。

sudo /sbin/grubby --update-kernel=ALL --args='cgroup_enable=memory cgroup.memory=nokmem swapaccount=1'

启用 overlay2 内核模块。

echo "overlay2" | sudo tee -a /etc/modules-load.d/overlay.conf

刷新动态生成的 grub2 配置。

sudo grub2-set-default 0

调整内核参数并使修改生效

cat <<EOF | sudo tee -a /etc/sysctl.conf
vm.max_map_count = 262144
fs.may_detach_mounts = 1
net.ipv4.ip_forward = 1
vm.swappiness=1
kernel.pid_max =1000000
fs.inotify.max_user_instances=524288
EOF
sudo sysctl -p

调整系统限制。

vim /etc/security/limits.conf
*                soft    nofile         1024000
*                hard    nofile         1024000
*                soft    memlock        unlimited
*                hard    memlock        unlimited
root             soft    nofile         1024000
root             hard    nofile         1024000
root             soft    memlock        unlimited

删除旧的限制配置。

sudo rm /etc/security/limits.d/20-nproc.conf

重启系统。

reboot

分析一下

安装的时候总是报错,我发现报错这种

 不是这个文件下载失败就是那个文件下载失败,后来忍不了,就将下载不了的文件的访问路径拿来了,直接去浏览器上下载,发现浏览器也是这样下载速度很快,没几秒就莫名其妙的失败,失败了我就重试了几次直到下载完成,然后直接把文件上传到虚拟机对应的路径就是以下的东西。它就直接跳过下载了。要是像我这样直接下载传进去吧。

安装特别慢,需要有耐心。

百度网盘地址:

链接:https://pan.baidu.com/s/158HHQtIEUlkojHUWRMrwug 
提取码:0529

主要下载的东西

路径:

/root/kubekey/v1.21.5/amd64

这个路径有这些文件

最后go语言脚本kubekey又把文件放到了这个路径下

/tmp/kubekey

不过只有5个文件,所有的节点都是,无关主从

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值