Ubuntu22.04 KubeSphere 安装K8S集群

一、系统环境

  • 系统:Ubuntu 22.04
  • 集群IP分布
hostname 角色 IP地址
master master,etcd 192.168.1.110
node1 worker 192.168.1.111
node2 worker 192.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 [email protected]
    
    # 访问node2
    root@master:~# ssh [email protected]
    
  • 所有节点时间同步。

    # 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.18 Kubernetes 版本 < 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
    
  3. 开始安装

    ./kk create cluster -f config-sample.yaml
    
  4. 等待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/

你可能感兴趣的:(虚拟化,Linux,kubernetes,docker,运维)