二进制安装Kubernetes(k8s)v1.31.1
介绍
https://github.com/cby-chen/Kubernetes 开源不易,帮助点个star,谢谢了
kubernetes(k8s)二进制高可用安装部署,支持IPv4+IPv6双栈。
剧烈建议在Github上查看文档 !!!
Github出问题会更新文档,而且后续尽可能第一时间更新新版本文档 !!!
手动项目所在:https://github.com/cby-chen/Kubernetes
1.情况
主机名称IP所在阐明软件192.168.1.60外网节点下载各种所需安装包Master01192.168.1.31master节点kube-apiserver、kube-controller-manager、kube-scheduler、etcd、
kubelet、kube-proxy、nfs-client、haproxy、keepalived、nginxMaster02192.168.1.32master节点kube-apiserver、kube-controller-manager、kube-scheduler、etcd、
kubelet、kube-proxy、nfs-client、haproxy、keepalived、nginxMaster03192.168.1.33master节点kube-apiserver、kube-controller-manager、kube-scheduler、etcd、
kubelet、kube-proxy、nfs-client、haproxy、keepalived、nginxNode01192.168.1.34node节点kubelet、kube-proxy、nfs-client、nginxNode02192.168.1.35node节点kubelet、kube-proxy、nfs-client、nginx192.168.1.36VIP网段
物理主机:192.168.1.0/24
service:10.96.0.0/12
pod:172.16.0.0/12
安装包已经整理好:https://mirrors.chenby.cn/https://github.com/cby-chen/Kubernetes/releases/download/v1.31.1/kubernetes-v1.31.1.tar
1.1.k8s底子系统情况设置
1.2.设置IP
1.3.设置主机名
- hostnamectl set-hostname k8s-master01
- hostnamectl set-hostname k8s-master02
- hostnamectl set-hostname k8s-master03
- hostnamectl set-hostname k8s-node01
- hostnamectl set-hostname k8s-node02
- # 参数解释
- #
- # 参数: set-hostname
- # 解释: 这是hostnamectl命令的一个参数,用于设置系统的主机名。
- #
- # 参数: k8s-master01
- # 解释: 这是要设置的主机名,将系统的主机名设置为"k8s-master01"。
复制代码 1.4.设置yum源
- # 其他系统的源地址
- # https://help.mirrors.cernet.edu.cn/
- # 对于私有仓库
- sed -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^#baseurl=http://mirror.centos.org/\$contentdir|baseurl=http://192.168.1.123/centos|g' -i.bak /etc/yum.repos.d/CentOS-*.repo
- # 对于 Ubuntu
- sed -i 's/cn.archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
- # epel扩展源
- sudo yum install -y epel-release
- sudo sed -e 's!^metalink=!#metalink=!g' \
- -e 's!^#baseurl=!baseurl=!g' \
- -e 's!https\?://download\.fedoraproject\.org/pub/epel!https://mirror.nju.edu.cn/epel!g' \
- -e 's!https\?://download\.example/pub/epel!https://mirror.nju.edu.cn/epel!g' \
- -i /etc/yum.repos.d/epel{,-testing}.repo
- # 对于 CentOS 7
- sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
- -e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirror.nju.edu.cn/centos|g' \
- -i.bak \
- /etc/yum.repos.d/CentOS-*.repo
- # 对于 CentOS 8
- sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
- -e 's|^#baseurl=http://mirror.centos.org/$contentdir|baseurl=https://mirror.nju.edu.cn/centos|g' \
- -i.bak \
- /etc/yum.repos.d/CentOS-*.repo
- # 对于CentOS 9
- cat <<'EOF' > /etc/yum.repos.d/centos.repo
- [baseos]
- name=CentOS Stream $releasever - BaseOS
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/BaseOS/$basearch/os
- # metalink=https://mirrors.centos.org/metalink?repo=centos-baseos-$stream&arch=$basearch&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- countme=1
- enabled=1
- [baseos-debuginfo]
- name=CentOS Stream $releasever - BaseOS - Debug
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/BaseOS/$basearch/debug/tree/
- # metalink=https://mirrors.centos.org/metalink?repo=centos-baseos-debug-$stream&arch=$basearch&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- enabled=0
- [baseos-source]
- name=CentOS Stream $releasever - BaseOS - Source
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/BaseOS/source/tree/
- # metalink=https://mirrors.centos.org/metalink?repo=centos-baseos-source-$stream&arch=source&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- enabled=0
- [appstream]
- name=CentOS Stream $releasever - AppStream
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/AppStream/$basearch/os
- # metalink=https://mirrors.centos.org/metalink?repo=centos-appstream-$stream&arch=$basearch&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- countme=1
- enabled=1
- [appstream-debuginfo]
- name=CentOS Stream $releasever - AppStream - Debug
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/AppStream/$basearch/debug/tree/
- # metalink=https://mirrors.centos.org/metalink?repo=centos-appstream-debug-$stream&arch=$basearch&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- enabled=0
- [appstream-source]
- name=CentOS Stream $releasever - AppStream - Source
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/AppStream/source/tree/
- # metalink=https://mirrors.centos.org/metalink?repo=centos-appstream-source-$stream&arch=source&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- enabled=0
- [crb]
- name=CentOS Stream $releasever - CRB
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/CRB/$basearch/os
- # metalink=https://mirrors.centos.org/metalink?repo=centos-crb-$stream&arch=$basearch&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- countme=1
- enabled=1
- [crb-debuginfo]
- name=CentOS Stream $releasever - CRB - Debug
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/CRB/$basearch/debug/tree/
- # metalink=https://mirrors.centos.org/metalink?repo=centos-crb-debug-$stream&arch=$basearch&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- enabled=0
- [crb-source]
- name=CentOS Stream $releasever - CRB - Source
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/CRB/source/tree/
- # metalink=https://mirrors.centos.org/metalink?repo=centos-crb-source-$stream&arch=source&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- enabled=0
- EOF
- cat <<'EOF' > /etc/yum.repos.d/centos-addons.repo
- [highavailability]
- name=CentOS Stream $releasever - HighAvailability
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/HighAvailability/$basearch/os
- # metalink=https://mirrors.centos.org/metalink?repo=centos-highavailability-$stream&arch=$basearch&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- countme=1
- enabled=0
- [highavailability-debuginfo]
- name=CentOS Stream $releasever - HighAvailability - Debug
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/HighAvailability/$basearch/debug/tree/
- # metalink=https://mirrors.centos.org/metalink?repo=centos-highavailability-debug-$stream&arch=$basearch&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- enabled=0
- [highavailability-source]
- name=CentOS Stream $releasever - HighAvailability - Source
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/HighAvailability/source/tree/
- # metalink=https://mirrors.centos.org/metalink?repo=centos-highavailability-source-$stream&arch=source&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- enabled=0
- [nfv]
- name=CentOS Stream $releasever - NFV
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/NFV/$basearch/os
- # metalink=https://mirrors.centos.org/metalink?repo=centos-nfv-$stream&arch=$basearch&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- countme=1
- enabled=0
- [nfv-debuginfo]
- name=CentOS Stream $releasever - NFV - Debug
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/NFV/$basearch/debug/tree/
- # metalink=https://mirrors.centos.org/metalink?repo=centos-nfv-debug-$stream&arch=$basearch&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- enabled=0
- [nfv-source]
- name=CentOS Stream $releasever - NFV - Source
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/NFV/source/tree/
- # metalink=https://mirrors.centos.org/metalink?repo=centos-nfv-source-$stream&arch=source&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- enabled=0
- [rt]
- name=CentOS Stream $releasever - RT
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/RT/$basearch/os
- # metalink=https://mirrors.centos.org/metalink?repo=centos-rt-$stream&arch=$basearch&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- countme=1
- enabled=0
- [rt-debuginfo]
- name=CentOS Stream $releasever - RT - Debug
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/RT/$basearch/debug/tree/
- # metalink=https://mirrors.centos.org/metalink?repo=centos-rt-debug-$stream&arch=$basearch&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- enabled=0
- [rt-source]
- name=CentOS Stream $releasever - RT - Source
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/RT/source/tree/
- # metalink=https://mirrors.centos.org/metalink?repo=centos-rt-source-$stream&arch=source&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- enabled=0
- [resilientstorage]
- name=CentOS Stream $releasever - ResilientStorage
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/ResilientStorage/$basearch/os
- # metalink=https://mirrors.centos.org/metalink?repo=centos-resilientstorage-$stream&arch=$basearch&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- countme=1
- enabled=0
- [resilientstorage-debuginfo]
- name=CentOS Stream $releasever - ResilientStorage - Debug
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/ResilientStorage/$basearch/debug/tree/
- # metalink=https://mirrors.centos.org/metalink?repo=centos-resilientstorage-debug-$stream&arch=$basearch&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- enabled=0
- [resilientstorage-source]
- name=CentOS Stream $releasever - ResilientStorage - Source
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/$releasever-stream/ResilientStorage/source/tree/
- # metalink=https://mirrors.centos.org/metalink?repo=centos-resilientstorage-source-$stream&arch=source&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- enabled=0
- [extras-common]
- name=CentOS Stream $releasever - Extras packages
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/SIGs/$releasever-stream/extras/$basearch/extras-common
- # metalink=https://mirrors.centos.org/metalink?repo=centos-extras-sig-extras-common-$stream&arch=$basearch&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Extras-SHA512
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- countme=1
- enabled=1
- [extras-common-source]
- name=CentOS Stream $releasever - Extras packages - Source
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/SIGs/$releasever-stream/extras/source/extras-common
- # metalink=https://mirrors.centos.org/metalink?repo=centos-extras-sig-extras-common-source-$stream&arch=source&protocol=https,http
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Extras-SHA512
- gpgcheck=1
- repo_gpgcheck=0
- metadata_expire=6h
- enabled=0
- EOF
复制代码 1.6.选择性下载需要工具
- # 对于 Ubuntu
- apt update && apt upgrade -y && apt install -y wget psmisc vim net-tools nfs-kernel-server telnet lvm2 git tar curl
- # 对于 CentOS 7
- yum update -y && yum -y install wget psmisc vim net-tools nfs-utils telnet yum-utils device-mapper-persistent-data lvm2 git tar curl
- # 对于 CentOS 8
- yum update -y && yum -y install wget psmisc vim net-tools nfs-utils telnet yum-utils device-mapper-persistent-data lvm2 git network-scripts tar curl
- # 对于 CentOS 9
- yum update -y && yum -y install wget psmisc vim net-tools nfs-utils telnet yum-utils device-mapper-persistent-data lvm2 git tar curl
复制代码 1.7.关闭防火墙
- # 下载必要工具
- yum -y install createrepo yum-utils wget epel*
- # 下载全量依赖包
- repotrack createrepo wget psmisc vim net-tools nfs-utils telnet yum-utils device-mapper-persistent-data lvm2 git tar curl gcc keepalived haproxy bash-completion chrony sshpass ipvsadm ipset sysstat conntrack libseccomp
- # 删除libseccomp
- rm -rf libseccomp-*.rpm
- # 下载libseccomp
- wget http://rpmfind.net/linux/centos/8-stream/BaseOS/x86_64/os/Packages/libseccomp-2.5.1-1.el8.x86_64.rpm
- # 创建yum源信息
- createrepo -u -d /data/centos7/
- # 拷贝包到内网机器上
- scp -r /data/centos7/ root@192.168.1.31:
- scp -r /data/centos7/ root@192.168.1.32:
- scp -r /data/centos7/ root@192.168.1.33:
- scp -r /data/centos7/ root@192.168.1.34:
- scp -r /data/centos7/ root@192.168.1.35:
- # 在内网机器上创建repo配置文件
- rm -rf /etc/yum.repos.d/*
- cat > /etc/yum.repos.d/123.repo << EOF
- [cby]
- name=CentOS-$releasever - Media
- baseurl=file:///root/centos7/
- gpgcheck=0
- enabled=1
- EOF
- # 安装下载好的包
- yum clean all
- yum makecache
- yum install /root/centos7/* --skip-broken -y
- #### 备注 #####
- # 安装完成后,可能还会出现yum无法使用那么再次执行
- rm -rf /etc/yum.repos.d/*
- cat > /etc/yum.repos.d/123.repo << EOF
- [cby]
- name=CentOS-$releasever - Media
- baseurl=file:///root/centos7/
- gpgcheck=0
- enabled=1
- EOF
- yum clean all
- yum makecache
- yum install /root/centos7/*.rpm --skip-broken -y
- #### 备注 #####
- # 安装 chrony 和 libseccomp
- # yum install /root/centos7/libseccomp-2.5.1*.rpm -y
- # yum install /root/centos7/chrony-*.rpm -y
复制代码 1.8.关闭SELinux
- # 下载必要工具
- yum -y install createrepo yum-utils wget epel*
- # 下载全量依赖包
- repotrack wget psmisc vim net-tools nfs-utils telnet yum-utils device-mapper-persistent-data lvm2 git network-scripts tar curl gcc keepalived haproxy bash-completion chrony sshpass ipvsadm ipset sysstat conntrack libseccomp
- # 创建yum源信息
- createrepo -u -d /data/centos8/
- # 拷贝包到内网机器上
- scp -r centos8/ root@192.168.1.31:
- scp -r centos8/ root@192.168.1.32:
- scp -r centos8/ root@192.168.1.33:
- scp -r centos8/ root@192.168.1.34:
- scp -r centos8/ root@192.168.1.35:
- # 在内网机器上创建repo配置文件
- rm -rf /etc/yum.repos.d/*
- cat > /etc/yum.repos.d/123.repo << EOF
- [cby]
- name=CentOS-$releasever - Media
- baseurl=file:///root/centos8/
- gpgcheck=0
- enabled=1
- EOF
- # 安装下载好的包
- yum clean all
- yum makecache
- yum install /root/centos8/* --skip-broken -y
- #### 备注 #####
- # 安装完成后,可能还会出现yum无法使用那么再次执行
- rm -rf /etc/yum.repos.d/*
- cat > /etc/yum.repos.d/123.repo << EOF
- [cby]
- name=CentOS-$releasever - Media
- baseurl=file:///root/centos8/
- gpgcheck=0
- enabled=1
- EOF
- yum clean all
- yum makecache
- yum install /root/centos8/*.rpm --skip-broken -y
复制代码 1.9.关闭交换分区
- # 下载必要工具
- yum -y install createrepo yum-utils wget epel*
- # 下载全量依赖包
- repotrack wget psmisc vim net-tools nfs-utils telnet yum-utils device-mapper-persistent-data lvm2 git tar curl
- # 创建yum源信息
- createrepo -u -d centos9/
- # 拷贝包到内网机器上
- scp -r centos9/ root@192.168.1.31:
- scp -r centos9/ root@192.168.1.32:
- scp -r centos9/ root@192.168.1.33:
- scp -r centos9/ root@192.168.1.34:
- scp -r centos9/ root@192.168.1.35:
- # 在内网机器上创建repo配置文件
- rm -rf /etc/yum.repos.d/*
- cat > /etc/yum.repos.d/123.repo << EOF
- [cby]
- name=CentOS-$releasever - Media
- baseurl=file:///root/centos9/
- gpgcheck=0
- enabled=1
- EOF
- # 安装下载好的包
- yum clean all
- yum makecache
- yum install /root/centos9/*.rpm --skip-broken -y
复制代码 1.10.网络设置(俩种方式二选一)
[code]# Ubuntu忽略,CentOS执行,CentOS9不支持方式一# 方式一# systemctl disable --now NetworkManager# systemctl start network && systemctl enable network# 方式二cat > /etc/NetworkManager/conf.d/calico.conf /etc/chrony.conf /etc/chrony.conf > /etc/security/limits.conf /etc/modules-load.d/ipvs.conf |