Ubuntu22.04 KubeSphere 安装K8S集群

一、系统环境

  • 系统:Ubuntu 22.04
  • 集群IP分布
hostname角色IP地址
mastermaster,etcd192.168.1.110
node1worker192.168.1.111
node2worker192.168.1.112
  • 修改hots文件
    加入Master与Node 之间的对应关系

     vim /etc/hosts
     192.168.1.110 master
     192.168.1.111 node1
     192.168.1.112 node2
    
  • 修改/etc/ssh/sshd_config文件

    # master 节点上
    root@master:~# echo "PubkeyAcceptedKeyTypes +ssh-rsa" >> /etc/ssh/sshd_config
    
    # node1 节点上
    root@node1:~# echo "PubkeyAcceptedKeyTypes +ssh-rsa" >> /etc/ssh/sshd_config
    
    # node2 节点上
    root@node2:~# echo "PubkeyAcceptedKeyTypes +ssh-rsa" >> /etc/ssh/sshd_config
    

二、搭建K8s集群

2.1 节点要求

  • 所有节点必须都能通过 SSH 访问。

    # 访问node1
    root@master:~# ssh dieteng@192.168.1.111
    
    # 访问node2
    root@master:~# ssh dieteng@192.168.1.112
    
  • 所有节点时间同步。

    # 1.跟新软件包
    apt install update
    
    # 2.设置时区
    timedatectl set-timezone 'Aisa/Shanghai'
    
    # 3.安装时间同步工具
    apt install chrony
    
    # 4.安装chrony默认会启动,我们手动重启一下
    systemctl restart chrony
    
    # 5.timedatectl 对比时间是否同步
    root@node1:/home/dieteng# timedatectl
                   Local time: Wed 2022-06-22 15:29:16 CST
               Universal time: Wed 2022-06-22 07:29:16 UTC
                     RTC time: Wed 2022-06-22 07:29:16
                    Time zone: Asia/Shanghai (CST, +0800)
    System clock synchronized: yes
                  NTP service: active
              RTC in local TZ: no
    ...
    
  • 所有节点都应使用 sudo/curl/openssl

2.2 依赖项要求

依赖项Kubernetes 版本 ≥ 1.18Kubernetes 版本 < 1.18
socat必须可选,但建议安装
conntrack必须可选,但建议安装
apt install socat conntrack

2.3 下载KubeKey

  1. 在master主机上先执行以下命令以确保您从正确的区域下载 KubeKey。
export KKZONE=cn
  1. 在master主机上执行以下命令下载 KubeKey
curl -sfL https://get-kk.kubesphere.io | VERSION=v2.0.0 sh -
  1. 添加执行权限

    chmod +x kk
    

2.4 开始部署

  1. 生成配置文件

    root@master:~/playground# ./kk create config  --with-kubernetes v1.21.5 --with-kubesphere v3.2.1
    
  2. 修改配置文件, 如果您不更改名称,那么将创建默认文件 config-sample.yaml。编辑文件,以下是多节点集群(具有一个主节点)配置文件的示例

    vim config-sample.yaml
    
  • 多节点版本
    spec:
      hosts:
      - {name: master, address: 192.168.0.2, internalAddress: 192.168.0.2, user: ubuntu, password: Testing123}
      - {name: node1, address: 192.168.0.3, internalAddress: 192.168.0.3, user: ubuntu, password: Testing123}
      - {name: node2, address: 192.168.0.4, internalAddress: 192.168.0.4, user: ubuntu, password: Testing123}
      roleGroups:
        etcd:
        - master
        control-plane:
        - master
        worker:
        - node1
        - node2
      controlPlaneEndpoint:
        domain: lb.kubesphere.local
        address: ""
        port: 6443
    
  • 单节点版本
apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:
  name: sample
spec:
  hosts:
  - {name: HostName, address: 192.168.1.xxx, internalAddress: 192.168.1.120, user: UserName, password: "Password"}
  roleGroups:
    etcd:
    - HostName
    control-plane:
    - HostName
    worker:
  controlPlaneEndpoint:
    ## Internal loadbalancer for apiservers
    # internalLoadbalancer: haproxy

注意:
上面配置中的name为你的hosts文件所配置的name
cat /etc/hosts

  1. 开始安装

    ./kk create cluster -f config-sample.yaml
    
  2. 等待10分钟左右安装完成。 具体取决于您的计算机和网络环境 。

    安装完成后,您会看到如下内容:

    #####################################################
    ###              Welcome to KubeSphere!           ###
    #####################################################
    
    Console: http://192.168.1.110:30880
    Account: A*****
    Password: P*****
    
    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
    #####################################################
    

参考网址:https://kubesphere.com.cn/docs/installing-on-linux/introduction/multioverview/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值