• sealos一键部署K8S环境(sealos3.0时代教程过时了,目前已经4.0了,请移步使用Sealos一键安装K8S)


    1 安装Sealos(4.0版本)

    sealos部署k8s贼方便,只需要一条init命令即可,3分钟部署完(下载安装包的时间不算)。
    官方教程:https://www.sealyun.com/instructions/1st

    #主机名:
    hostnamectl set-hostname master  && bash
    hostnamectl set-hostname work  && bash
    hostnamectl set-hostname edge1  && bash
    hostnamectl set-hostname edge2  && bash
    
    
    #添加hosts:
    cat >> /etc/hosts << EOF
    192.168.186.128  master
    192.168.186.129  work
    192.168.186.130  edge1
    192.168.186.131  edge2
    EOF
    
    #所有机器上都操作
    ssh-keygen -t rsa #一路回车,不输入密码
    ###把本地的ssh公钥文件安装到远程主机对应的账户
    for i in master work edge1 edge2 ;do ssh-copy-id -i .ssh/id_rsa.pub $i ;done
    
    
    
    #关闭防火墙:
    systemctl stop firewalld
    systemctl disable firewalld
    #关闭selinux:
    sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
    setenforce 0 # 临时
    #关闭swap:
    swapoff -a # 临时
    sed -i 's/.*swap.*/#&/' /etc/fstab # 永久
    
    cat > /etc/resolv.conf <<EOF
    nameserver 8.8.8.8
    nameserver 114.114.114.114
    nameserver 223.5.5.5
    EOF
    
    
    #时间同步
    yum install -y chrony -y 
    cat > /etc/chrony.conf << EOF
    server ntp.aliyun.com iburst
    stratumweight 0
    driftfile /var/lib/chrony/drift
    rtcsync
    makestep 10 3
    bindcmdaddress 127.0.0.1
    bindcmdaddress ::1
    keyfile /etc/chrony.keys
    commandkey 1
    generatecommandkey
    logchange 0.5
    logdir /var/log/chrony
    EOF
    
    systemctl enable --now chronyd 
    chronyc sources 
    
    #设置yum源
    yum -y install wget
    wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
    wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    yum -y install wget
    wget https://github.com/labring/sealos/releases/download/v4.1.3/sealos_4.1.3_linux_amd64.tar.gz 
    
    tar zxvf sealos_4.1.3_linux_amd64.tar.gz sealos
    chmod +x sealos
    cp sealos /usr/bin
    sealos version
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    **可以从https://github.com/labring/sealos/releases找最新版本下载

    2. 创建K8S集群

    由于容器日志默认是保存在/var/log/pods下的,为了防止系统盘被日志打满,可以事先创建好一个软链,链接到数据盘,例:

    # 所有机器上执行
    mkdir -p /data/k8s/log/pods
    ln -s /data/k8s/log/pods /var/log/pods
    
    • 1
    • 2
    • 3

    使用root用户创建集群:(不能用sudo)

    sealos run labring/kubernetes:v1.24.3 labring/calico:v3.22.1 \
         --env criData=/data/k8s/containerd \
         --masters 192.168.64.2,192.168.64.22,192.168.64.20 \
         --nodes 192.168.64.21,192.168.64.19 -p [your-ssh-passwd]
    
    • 1
    • 2
    • 3
    • 4
    1. k8s版本可以从这里找:labring/kubernetes Tags | Docker Hub
    2. –masters参数是master节点ip列表
    3. –nodes参数是node节点ip列表
    4. -p是ssh密码

    3. 去除master污点(node节点多的话不需要此操作)

    #master节点去除污点后才能运行业务pod
    kubectl taint nodes --all node-role.kubernetes.io/control-plane-
    kubectl taint nodes --all node-role.kubernetes.io/master-
    
    • 1
    • 2
    • 3

    4. nerdctl

    现在k8s已经默认不使用docker,而是使用containerd,因此没有docker命令来管理镜像,可以使用nerdctl命令代替,命令基本上和docker一致。

    要注意的是,containerd有命名空间的概念:

    nerdctl namespace ls
    nerdctl load -i xxx.tar --namespace k8s.io
    
    • 1
    • 2

    5. 非root用户

    sealos目前版本只能使用root用户安装,如果你平时不使用root用户,需要使用非root用户执行:

    # 将.kube拷贝到当前用户目录下,否则无法执行kubectl命令
    sudo cp -r /root/.kube $HOME
    sudo chown -R ${whoami}:${whoami} $HOME/.kube
    
    # 给nerdctl提高权限,否则执行nerdctl需要sudo
    sudo chmod +s /usr/bin/nerdctl
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    6. 私有镜像仓库

    sealos自带了一个镜像仓库,部署在第一个master上。
    查看registry:

    nerdctl ps
    nerdctl login sealos.hub:5000 -u admin -p passw0rd  #登录
    
    • 1
    • 2
    #推送镜像到私有仓库:
    nerdctl tag xxx:v1.0.0 sealos.hub:5000/xxx:v1.0.0 --namespace k8s.io
    nerdctl push sealos.hub:5000/xxx:v1.0.0
    
    • 1
    • 2
    • 3
  • 相关阅读:
    基于JAVA的高校宿管理系统
    Toxel 与 PCPC II
    HarmonyOS鸿蒙原生应用开发设计- 华为分享图标
    虚拟机VMware+Ubuntu系统的自定义安装教程(详细图文教程)
    高校节能环保建设
    【ARM Coresight OpenOCD 系列 2 -- OpenOCD 脚本语法详细介绍】
    这款全自动自适应工具你用过了吗?autofit.js请求加入你的战场!
    Spring AOP 编程原理和实现
    DevOps-4:Jenkins配置.Net项目模板Job
    STM32控制max30102读取血氧心率数据(keil5工程)
  • 原文地址:https://blog.csdn.net/qq_14910065/article/details/133969136