• 二进制安装k8s 1.25.2 高可用集群


    一、环境准备

    1、环境说明(安装时配置IP及主机名)

    序号 主机IP 主机名 系统 备注
    1 192.168.3.101 master1 rockylinux8.6最小化安装 控制节点
    2 192.168.3.102 master2 rockylinux8.6最小化安装 控制节点
    3 192.168.3.103 master3 rockylinux8.6最小化安装 控制节点
    4 192.168.3.104 node1 rockylinux8.6最小化安装 工作节点
    5 192.168.3.105 node2 rockylinux8.6最小化安装 工作节点

    2、关闭selinux,firewalld及swap分区(在五台设备上执行)

    1. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
    2. systemctl disable firewalld
    3. swapoff -a
    4. reboot

    注:swapoff -a 为临时关闭swap分区。永久关闭swap分区,vi /etc/fstab  注释swap分区一行

    3、修改/etc/hosts文件,增加如下三行(五台设备)

    1. cat << EOF >> /etc/hosts
    2. 192.168.3.101 master1
    3. 192.168.3.102 master2
    4. 192.168.3.103 master3
    5. 192.168.3.104 node1
    6. 192.168.3.105 node2
    7. EOF

    4、更改yum源为阿里云(五台设备执行)

    1. sed -e 's|^mirrorlist=|#mirrorlist=|g' \
    2. -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \
    3. -i.bak \
    4. /etc/yum.repos.d/Rocky-*.repo
    5. dnf makecache

    5、配置命令补全及vim工具(五台设备执行)

    dnf install -y wget bash-completion vim

    6、配置免密登录(三台master上执行,可省)

    1. ssh-keygen
    2. for host in { master1 master2 master3 node1 node2 };do ssh-copy-id $host;done

    7、配置时间同步(五台设备执行)

    dnf install -y chrony

    更改  /etc/chrony.conf  配置文件

    将pool 2.pool.ntp.org iburst

    改为

    server ntp1.aliyun.com iburst
    server ntp2.aliyun.com iburst
    server ntp1.tencent.com iburst
    server ntp2.tencent.com iburst

    1. systemctl enable --now chronyd
    2. chronyc sources
    3. for host in { master1 master2 master3 node1 node2 };do ssh $host date;done

    8、修改内核参数(五台设备上执行)

    1. modprobe br_netfilter
    2. lsmod | grep br_netfilter
    3. cat > /etc/sysctl.d/k8s.conf <<EOF
    4. net.bridge.bridge-nf-call-ip6tables = 1
    5. net.bridge.bridge-nf-call-iptables = 1
    6. net.ipv4.ip_forward = 1
    7. EOF
    8. sysctl -p /etc/sysctl.d/k8s.conf

     9、安装依整包及配置docker源、k8s源(五台设备执行)

    1. dnf install -y yum-utils device-mapper-persistent-data lvm2 ipvsadm net-tools
    2. yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    3. sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
    4. cat <<EOF > /etc/yum.repos.d/kubernetes.repo
    5. [kubernetes]
    6. name=Kubernetes
    7. baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
    8. enabled=1
    9. gpgcheck=1
    10. repo_gpgcheck=1
    11. gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
    12. EOF
    13. dnf makecache

    10、开启Ipvs 五台设备

    1. lsmod|grep ip_vs
    2. modprobe -- ip_vs
    3. modprobe -- ip_vs_rr
    4. modprobe -- ip_vs_wrr
    5. modprobe -- ip_vs_sh
    6. lsmod|grep ip_vs
    7. modprobe br_netfilter
    8. echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
    9. echo 1 > /proc/sys/net/ipv4/ip_forward

    11、安装containerd(五台设备执行)

    1. dnf install -y containerd
    2. containerd config default > /etc/containerd/config.toml

    更改配置文件

    1. sed -i 's#SystemdCgroup = false#SystemdCgroup = true#g' /etc/containerd/config.toml
    2. sed -i "s#k8s.gcr.io/pause#registry.cn-hangzhou.aliyuncs.com/google_containers/pause#g" /etc/containerd/config.toml

    配置镜像加速

    1. sed -i '/registry.mirrors]/a\ \ \ \ \ \ \ \ [plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]' /etc/containerd/config.toml
    2. sed -i '/registry.mirrors."docker.io"]/a\ \ \ \ \ \ \ \ \ \ endpoint = ["https://0x3urqgf.mirror.aliyuncs.com"]' /etc/containerd/config.toml

    启动containerd

    1. systemctl enable --now containerd.service
    2. systemctl status containerd.service

    二、安装kubernetes 组件

    1、安装ETCD

    1. wget https://github.com/cloudflare/cfssl/releases/download/v1.6.1/cfssl_1.6.1_linux_amd64
    2. wget https://github.com/cloudflare/cfssl/releases/download/v1.6.1/cfssl-certinfo_1.6.1_linux_amd64
    3. wget https://github.com/cloudflare/cfssl/releases/download/v1.6.1/cfssljson_1.6.1_linux_amd64
    4. mv cfssl_1.6.1_linux_amd64 /usr/local/bin/cfssl
    5. mv cfssljson_1.6.1_linux_amd64 /usr/local/bin/cfssljson
    6. mv cfssl-certinfo_1.6.1_linux_amd64 /usr/local/bin/cfssl-certinfo
    7. chmod +x /usr/local/bin/cfssl*
    8. mkdir /cfspki
    9. mkdir -p /etc/etcd/pki
    10. mkdir -p /var/lib/etcd/default.etcd
    11. cd /cfspki/
    12. cat > ca-csr.json << EOF
    13. {
    14. "CN": "kubernetes",
    15. "key": {
    16. "algo": "rsa",
    17. "size": 2048
    18. },
    19. "names": [
    20. {
    21. "C": "CN",
    22. "ST": "Xinjiang",
    23. "L": "Urumqi",
    24. "O": "k8s",
    25. "OU": "system"
    26. }
    27. ],
    28. "ca": {
    29. "expiry": "87600h"
    30. }
    31. }
    32. EOF
    33. cfssl gencert -initca ca-csr.json | cfssljson -bare ca

    1. cat > ca-config.json << EOF
    2. {
    3. "signing": {
    4. "default": {
    5. "expiry": "87600h"
    6. },
    7. "profiles": {
    8. "kubernetes": {
    9. "usages": [
    10. "signing",
    11. "key encipherment",
    12. "server auth",
    13. "client auth"
    14. ],
    15. "expiry": "87600h"
    16. }
    17. }
    18. }
    19. }
    20. EOF
    21. cat > etcd-csr.json << EOF
    22. {
    23. "CN": "etcd",
    24. "hosts": [
    25. "127.0.0.1",
    26. "192.168.3.101",
    27. "192.168.3.102",
    28. "192.168.3.103",
    29. "192.168.3.110"
    30. ],
    31. "key": {
    32. "algo": "rsa",
    33. "size": 2048
    34. },
    35. "names": [{
    36. "C": "CN",
    37. "ST": "Xinjiang",
    38. "L": "Urumqi",
    39. "O": "k8s",
    40. "OU": "system"
    41. }]
    42. }
    43. EOF
    44. cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -conf
  • 相关阅读:
    2021.09青少年软件编程(Python)等级考试试卷(四级)
    【概率与统计】聊聊一些常见的概率分布
    java基础之适配器模式[30]
    GreenPlum优化点之参数篇
    【sfu】视频接收侧的创建流程
    欧美市场独立站选品技巧
    学习ASP.NET Core Blazor编程系列二——第一个Blazor应用程序(完)
    .NET 反向代理-YARP 部署Https(SSL)
    go学习-GMP模型
    Python之Excel数据相关
  • 原文地址:https://blog.csdn.net/w975121565/article/details/127596285