• rke方式安装k8s集群


    一、新机环境准备

    1.1主机名设置

    hostnamectl  set-hostname  XXX
    
    • 1

    1.2 主机名与ip地址解析

    vim /etc/hosts

    192.168.0.140  rke
    192.168.0.147  master1
    192.168.0.152  node1
    192.168.0.153  node2
    
    • 1
    • 2
    • 3
    • 4

    1.3安装docker

    tar -xf docker-20.10.24.tgz
    cp ${SHELL_FOLDER}/docker/* /usr/bin/
    mkdir /etc/docker
    
    • 1
    • 2
    • 3
    cat >>/usr/lib/systemd/system/docker.service<
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    vim /etc/docker/daemon.json

    {
    	"log-driver": "json-file",
    	"log-opts": {
    		"max-size": "10m",
    		"max-file": "3"
    	},
    	"exec-opts": ["native.cgroupdriver=systemd"],
    	"insecure-registries":["mirrors.com:80"],
    	"storage-driver": "overlay2",
    	"storage-opts": [
    		"overlay2.override_kernel_check=true"
    	]
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    systemctl daemon-reload
    systemctl enable docker
    systemctl start docker
    
    • 1
    • 2
    • 3

    1.4修改内核参数

    vim /etc/sysctl.d/90-k8s.conf
    vm.swappiness=0
    net.ipv4.ip_forward=1
    net.ipv6.conf.all.forwarding=1
    net.ipv4.ip_local_port_range = 1024     65000
    net.bridge.bridge-nf-call-iptables=1
    net.bridge.bridge-nf-call-ip6tables = 1
    net.ipv4.neigh.default.gc_thresh1=4096
    net.ipv4.neigh.default.gc_thresh2=6144
    net.ipv4.neigh.default.gc_thresh3=8192
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    1.5修改句柄数可进程数

    cat >>/etc/security/limits.d/90-nofile.conf<>/etc/security/limits.d/90-nproc.conf<
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    1.6关闭防火墙和swap分区

    systemctl stop firewalld && setenforce 0
    sed  -ri  's/.*swap/#&/'  /etc/fstab
    swapoff -a
    
    • 1
    • 2
    • 3

    1.7 添加rke用户

    useradd rke
    usermod  -aG  docker  rke
    echo 123 | passwd --stdin rke
    mkdir /home/rke/.ssh
    
    • 1
    • 2
    • 3
    • 4

    二、部署rke

    2.1下载rke工具

    下载地址

    https://github.com/rancher/rke/releases/download/v1.4.5/rke_linux-amd64
    
    • 1

    2.2rke机器对其他节点做免密

    ssh-copy-id rke@192.168.0.147
    ssh-copy-id rke@192.168.0.152
    ssh-copy-id rke@192.168.0.153
    
    • 1
    • 2
    • 3
    chown apps:apps -R /home/rke/.ssh
    chmod 700 /home/rke/.ssh
    chmod 600 /home/rke/.ssh/authorized_keys
    
    • 1
    • 2
    • 3

    2.3 rke配置与cluster文件

    mv   rke_linux-amd64   /usr/local/bin/rke
    chmod  +x  /usr/local/bin/rke
    ln  -s  /usr/local/bin/rke  /usr/bin/rke
    rke --version
    
    • 1
    • 2
    • 3
    • 4

    vim cluster.yaml

    nodes:
      - address: 192.168.0.147 # master节点IP
        user: root
        role: ["controlplane", "etcd", "worker"]
        ssh_key_path: /root/.ssh/id_rsa
      - address: 192.168.0.152 # node节点 IP
        user: root
        role: ["worker"]
        ssh_key_path: /root/.ssh/id_rsa
      - address: 192.168.0.153 # node节点 IP
        user: root
        role: ["worker"]
        ssh_key_path: /root/.ssh/id_rsa
    upgrade_strategy:
      max_unavailable_worker: 50%
      max_unavailable_controlplane: 1
      drain: false
    ignore_docker_version: true
    kubernetes_version: "v1.21.14-rancher1-1"
    network:
       plugin: calico
    services:
        etcd:
          snapshot: true
          creation: 6h
          retention: 24h
        kube-api:
          extra_args:
            enable-admission-plugins: "NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota,NodeRestriction,Priority,TaintNodesByCondition,PersistentVolumeClaimResize,PodNodeSelector"
    
    • 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

    三、集群部署

    rke up     #拉起集群
    如果报错失败,可以根据报错修改或者
    rke remove 之后重新拉起集群
    
    • 1
    • 2
    • 3

    四、安装kubectl(master节点)

    wget  https://storage.googleapis.com/kubernetes-release/release/v1.27.2/bin/linux/amd64/kubectl
    chmod  +x  kubectl
    mv  kubectl  /usr/local/bin
    mkdir -p /root/.kube/config
    将rke节点上生成的kube_config_cluster.yml  scp到 /root/.kube/config。即可使用kubectl命令
    
    • 1
    • 2
    • 3
    • 4
    • 5
  • 相关阅读:
    Python list列表删除元素(4种方法)
    ShareX使用说明——优秀的录屏软件
    OpenHarmony自定义构建函数:@Builder装饰器
    【C++】动态多态与虚函数
    Java学习之--类和对象
    优炫软件中标西南民族大学项目,护航教育行业主机安全
    ESP32C3 LuatOS TM1650②动态显示累加整数
    浅谈电气防火限流式保护器在小型人员密集场所中的应用
    springCloud-LoadBalancer负载均衡
    Centos7安装自动化运维Ansible
  • 原文地址:https://blog.csdn.net/m0_53563073/article/details/136340206