二进制安装Kubernetes(k8s)v1.28.3
https://github.com/cby-chen/Kubernetes 开源不易,帮忙点个star,谢谢了
介绍
kubernetes(k8s)二进制高可用安装部署,支持IPv4+IPv6双栈。
我使用IPV6的目的是在公网进行访问,所以我配置了IPV6静态地址。
若您没有IPV6环境,或者不想使用IPv6,不对主机进行配置IPv6地址即可。
不配置IPV6,不影响后续,不过集群依旧是支持IPv6的。为后期留有扩展可能性。
若不要IPv6 ,不给网卡配置IPv6即可,不要对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://ghproxy.com/https://github.com/cby-chen/Kubernetes/releases/download/v1.28.3/kubernetes-v1.28.3.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://mirrors.tuna.tsinghua.edu.cn/help/
- # 对于 Ubuntu
- sed -i 's/cn.archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
- # 对于 CentOS 7
- sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
- -e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.tuna.tsinghua.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://mirrors.tuna.tsinghua.edu.cn/centos|g' \
- -i.bak \
- /etc/yum.repos.d/CentOS-*.repo
- # 对于私有仓库
- 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 系统,将 /etc/apt/sources.list 文件中的软件源地址 cn.archive.ubuntu.com 替换为 mirrors.ustc.edu.cn。
- #
- # 对于 CentOS 7 系统,将 /etc/yum.repos.d/CentOS-*.repo 文件中的 mirrorlist 注释掉,并将 baseurl 的值替换为 https://mirrors.tuna.tsinghua.edu.cn/centos。
- #
- # 对于 CentOS 8 系统,同样将 /etc/yum.repos.d/CentOS-*.repo 文件中的 mirrorlist 注释掉,并将 baseurl 的值替换为 https://mirrors.tuna.tsinghua.edu.cn/centos。
- #
- # 对于私有仓库,将 /etc/yum.repos.d/CentOS-*.repo 文件中的 mirrorlist 注释掉,并将 baseurl 的值替换为私有仓库地址 http://192.168.1.123/centos。
- #
- # 这些命令通过使用 sed 工具和正则表达式,对相应的配置文件进行批量的替换操作,从而更改系统软件源配置。
复制代码 1.5.安装一些必备工具
- # 对于 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
复制代码 1.5.1 下载离线所需文件(可选)
在互联网服务器上安装一个一模一样的系统进行下载所需包
CentOS7
- # 下载必要工具
- 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/* --skip-broken -y
- #### 备注 #####
- # 安装 chrony 和 libseccomp
- # yum install /root/centos7/libseccomp-2.5.1*.rpm -y
- # yum install /root/centos7/chrony-*.rpm -y
复制代码 1.6.选择性下载需要工具
- # 下载必要工具
- 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/* --skip-broken -y
复制代码 1.7.关闭防火墙
- #!/bin/bash
- logfile=123.log
- ret=""
- function getDepends()
- {
- echo "fileName is" $1>>$logfile
- # use tr to del < >
- ret=`apt-cache depends $1|grep Depends |cut -d: -f2 |tr -d "<>"`
- echo $ret|tee -a $logfile
- }
- # 需要获取其所依赖包的包
- libs="wget psmisc vim net-tools nfs-kernel-server telnet lvm2 git tar curl gcc keepalived haproxy bash-completion chrony sshpass ipvsadm ipset sysstat conntrack libseccomp"
- # download libs dependen. deep in 3
- i=0
- while [ $i -lt 3 ] ;
- do
- let i++
- echo $i
- # download libs
- newlist=" "
- for j in $libs
- do
- added="$(getDepends $j)"
- newlist="$newlist $added"
- apt install $added --reinstall -d -y
- done
- libs=$newlist
- done
- # 创建源信息
- apt install dpkg-dev
- sudo cp /var/cache/apt/archives/*.deb /data/ubuntu/ -r
- dpkg-scanpackages . /dev/null |gzip > /data/ubuntu/Packages.gz -r
- # 拷贝包到内网机器上
- scp -r ubuntu/ root@192.168.1.31:
- scp -r ubuntu/ root@192.168.1.32:
- scp -r ubuntu/ root@192.168.1.33:
- scp -r ubuntu/ root@192.168.1.34:
- scp -r ubuntu/ root@192.168.1.35:
- # 在内网机器上配置apt源
- vim /etc/apt/sources.list
- cat /etc/apt/sources.list
- deb file:////root/ ubuntu/
- # 安装deb包
- apt install ./*.deb
复制代码 1.8.关闭SELinux
- #!/bin/bash
- # 查看版本地址:
- #
- # https://github.com/containernetworking/plugins/releases/
- # https://github.com/containerd/containerd/releases/
- # https://github.com/kubernetes-sigs/cri-tools/releases/
- # https://github.com/Mirantis/cri-dockerd/releases/
- # https://github.com/etcd-io/etcd/releases/
- # https://github.com/cloudflare/cfssl/releases/
- # https://github.com/kubernetes/kubernetes/tree/master/CHANGELOG
- # https://download.docker.com/linux/static/stable/x86_64/
- # https://github.com/opencontainers/runc/releases/
- # https://mirrors.tuna.tsinghua.edu.cn/elrepo/kernel/el7/x86_64/RPMS/
- # https://github.com/helm/helm/tags
- # http://nginx.org/download/
- # Version numbers
- cni_plugins_version='v1.3.0'
- cri_containerd_cni_version='1.7.8'
- crictl_version='v1.28.0'
- cri_dockerd_version='0.3.7'
- etcd_version='v3.5.10'
- cfssl_version='1.6.4'
- kubernetes_server_version='1.28.3'
- docker_version='24.0.7'
- runc_version='1.1.10'
- kernel_version='5.4.260'
- helm_version='3.13.2'
- nginx_version='1.25.3'
- # URLs
- base_url='https://mirrors.chenby.cn/https://github.com'
- kernel_url="http://mirrors.tuna.tsinghua.edu.cn/elrepo/kernel/el7/x86_64/RPMS/kernel-lt-${kernel_version}-1.el7.elrepo.x86_64.rpm"
- runc_url="${base_url}/opencontainers/runc/releases/download/v${runc_version}/runc.amd64"
- docker_url="https://mirrors.ustc.edu.cn/docker-ce/linux/static/stable/x86_64/docker-${docker_version}.tgz"
- cni_plugins_url="${base_url}/containernetworking/plugins/releases/download/${cni_plugins_version}/cni-plugins-linux-amd64-${cni_plugins_version}.tgz"
- cri_containerd_cni_url="${base_url}/containerd/containerd/releases/download/v${cri_containerd_cni_version}/cri-containerd-cni-${cri_containerd_cni_version}-linux-amd64.tar.gz"
- crictl_url="${base_url}/kubernetes-sigs/cri-tools/releases/download/${crictl_version}/crictl-${crictl_version}-linux-amd64.tar.gz"
- cri_dockerd_url="${base_url}/Mirantis/cri-dockerd/releases/download/v${cri_dockerd_version}/cri-dockerd-${cri_dockerd_version}.amd64.tgz"
- etcd_url="${base_url}/etcd-io/etcd/releases/download/${etcd_version}/etcd-${etcd_version}-linux-amd64.tar.gz"
- cfssl_url="${base_url}/cloudflare/cfssl/releases/download/v${cfssl_version}/cfssl_${cfssl_version}_linux_amd64"
- cfssljson_url="${base_url}/cloudflare/cfssl/releases/download/v${cfssl_version}/cfssljson_${cfssl_version}_linux_amd64"
- helm_url="https://mirrors.huaweicloud.com/helm/v${helm_version}/helm-v${helm_version}-linux-amd64.tar.gz"
- kubernetes_server_url="https://storage.googleapis.com/kubernetes-release/release/v${kubernetes_server_version}/kubernetes-server-linux-amd64.tar.gz"
- nginx_url="http://nginx.org/download/nginx-${nginx_version}.tar.gz"
- # Download packages
- packages=(
- $kernel_url
- $runc_url
- $docker_url
- $cni_plugins_url
- $cri_containerd_cni_url
- $crictl_url
- $cri_dockerd_url
- $etcd_url
- $cfssl_url
- $cfssljson_url
- $helm_url
- $kubernetes_server_url
- $nginx_url
- )
- for package_url in "${packages[@]}"; do
- filename=$(basename "$package_url")
- if curl --parallel --parallel-immediate -k -L -C - -o "$filename" "$package_url"; then
- echo "Downloaded $filename"
- else
- echo "Failed to download $filename"
- exit 1
- fi
- done
复制代码 1.9.关闭交换分区
- # Ubuntu忽略,CentOS执行
- systemctl disable --now firewalld
复制代码 1.10.网络配置(俩种方式二选一)
[code]# Ubuntu忽略,CentOS执行# 方式一# 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 |