【k8s】Kubernetes 1.29.4离线安装部署(总)

(一)kubernetes1.29.4离线部署之-安装文件准备
(二)kubernetes1.29.4离线部署之-镜像文件准备
(三)kubernetes1.29.4离线部署之-环境初始化
(四)kubernetes1.29.4离线部署之-组件安装
(五)kubernetes1.29.4离线部署之-初始化第一个控制平面
(六)kubernetes1.29.4离线部署之-加入Node节点
(七)kubernetes1.29.4离线部署之-网络插件
(八)kubernetes1.29.4离线部署之-测试验证

友情提示: 由于本文过长,不便于阅读,已经拆分为多个章节,可以点击上面的地址单独阅读

本文容器运行时采用的时Containerd

本文网络插件采用的时calico tigera-operator

本文涉及的所有脚本文件可以从如下地址获取:
https://gitee.com/qingplus/qingcloud-platform/tree/develop/qingcloud-deploy/service

前情提要:

本文不介绍K8S架构及细节,仅仅分享Kubernetes部署实施完整过程。
本文主要采用kubeadm方式安装部署。另外本文直接采用单控制平面方式快速完成版本部署,etcd的部署方式为堆叠方式,独立方式的切换后续完成文档说明。
高可用集群拓扑的两个选项介绍:
高可用集群拓扑的两个选项:

  • 使用堆叠(stacked)控制平面节点,其中 etcd 节点与控制平面节点共存
  • 使用外部 etcd 节点,其中 etcd 在与控制平面不同的节点上运行

本文主要采用第一种堆叠方式:

环境准备

硬件环境

服务器由6台ESXi虚拟化服务器组成,详情参考《ESXi网络配置与物理交换机VLAN ID规划》

本文为单控制平面部署,非高可用集群部署,并未用到规划中的所有节点。后续集群部署会继续使用。

主机名称ESXi 节点名角色IP地址资源配置安装组件
itserver-master1xenserver01master10.0.0.108C/16G/200G
itserver-master2xenserver02master10.0.0.138C/16G/200G
itserver-node01xenserver01node10.0.0.1116C/64G/500G
itserver-node02xenserver01node10.0.0.1216C/64G/500G
itserver-node03xenserver02node10.0.0.1416C/64G/500G
itserver-node04xenserver02node10.0.0.1516C/64G/500G
物理服务器节点(安装ESXi)
三台物理服务器
ESXi 节点名ip地址用户名备注
xenserver01192.168.3.50root
xenserver02192.168.3.60root
xenserver03192.168.3.100root
网络分配
角色IP地址备注
node网络10.0.0.0/24
Service 网络10.96.0.0/16
Pod网络172.16.0.0/16
网络部署图

企业基础网络结构拓扑.png

离线安装文件准备

需要准备如下几个必须的安装文件,可以离线下载后通过本地nginx代理供其他节点下载使用
  1. kubernetes_server

直接下载最新版二进制文件

  1. containerd

本文容器运行时采用containerd而非docker,如果容器运行时采用docker,需要另外的部署版本。本文直接下载三合一版本cri_containerd_cni

  1. cni_plugins
  2. crictl

命令行执行工具 。类似docker命令行

  1. runc

需要单独下载完整版,只是需要检查本地环境是否存在libcommp.so

  1. etcd

采用外部 etcd 节点部署时需要用到,如果使用的是堆叠的方式,直接用默认的etcd容器即可,可以不用下载。

完整的离线文件下载脚本:
#!/bin/bashENV_CFG=./env.cfg
if [ -f ${ENV_CFG} ] ; thenchmod 777 ${ENV_CFG}source ${ENV_CFG}
fi# Internet URLs
kernel_url="http://mirrors.tuna.tsinghua.edu.cn/elrepo/kernel/el7/x86_64/RPMS/${kernel_name}"cni_plugins_url="https://github.com/containernetworking/plugins/releases/download/${cni_plugins_version}/${cni_plugins_name}"
cri_containerd_cni_url="https://github.com/containerd/containerd/releases/download/v${cri_containerd_cni_version}/${cri_containerd_cni_name}"
crictl_url="https://github.com/kubernetes-sigs/cri-tools/releases/download/${crictl_version}/${crictl_name}"
runc_url="https://github.com/opencontainers/runc/releases/download/v${runc_version}/${runc_name}"etcd_url="https://github.com/etcd-io/etcd/releases/download/${etcd_version}/${etcd_name}"
kubernetes_server_url="https://storage.googleapis.com/kubernetes-release/release/${KUBERNETES_VERSION}/${kubernetes_server_name}"
nginx_url="http://nginx.org/download/${nginx_name}"# Download packages
packages=($kernel_url$runc_url$cni_plugins_url$cri_containerd_cni_url$crictl_url$cri_dockerd_url$etcd_url$kubernetes_server_url
)for package_url in "${packages[@]}"; dofilename=$(basename "$package_url")if curl -k -L -C - -o "$filename" "$package_url"; thenecho "Downloaded $filename"elseecho "Failed to download $filename"exit 1fi
done

离线镜像文件准备

注意:离线安装需要准备大量的镜像,这一步千万要仔细否则会出现各种意想不到的问题

需要准备的镜像文件
  1. kube-apiserver
  2. kube-controller-manager
  3. kube-scheduler
  4. kube-proxy
  5. kube-proxy
  6. coredns
  7. pause
  8. etcd

以上镜像文件可以从: registry.cn-hangzhou.aliyuncs.com/google_containers下载

  1. calico/node
  2. calico/kube-controllers
  3. calico/node
  4. calico/typha
  5. calico/node-driver-registrar
  6. calico/csi
  7. calico/cni
  8. calico/ctl
  9. calico/pod2daemon-flexvol
  10. calico/apiserver

以上可以直接从docker.io下载即可

注意: 以上所有的镜像文件务必准备到位。本文脚本中的几个版本便令注意修改到位:
KUBERNETES_VERSION=${KUBERNETES_VERSION:-“v1.29.4”}
COREDNS_VERSION=${COREDNS_VERSION:-‘v1.11.1’}
PAUSE_VERSION=${PAUSE_VERSION:-‘3.9’}
ETCD_VERSION=${ETCD_VERSION:-‘3.5.12-0’}
REGISTRY_VERSION=${REGISTRY_VERSION:-‘2.8.3’}
CALICO_VERSION=${CALICO_VERSION:-‘v3.27.3’}

完整的镜像下载脚本
#!/bin/bashENV_CFG=./env.cfg
if [ -f ${ENV_CFG} ] ; thenchmod 777 ${ENV_CFG}source ${ENV_CFG}
fi
image_list="${IMAGE_DOMAIN}/${IMAGE_NAMESPACE}/kube-apiserver:${KUBERNETES_VERSION}
${IMAGE_DOMAIN}/${IMAGE_NAMESPACE}/kube-controller-manager:${KUBERNETES_VERSION}
${IMAGE_DOMAIN}/${IMAGE_NAMESPACE}/kube-scheduler:${KUBERNETES_VERSION}
${IMAGE_DOMAIN}/${IMAGE_NAMESPACE}/kube-proxy:${KUBERNETES_VERSION}
${IMAGE_DOMAIN}/${IMAGE_NAMESPACE}/coredns:${COREDNS_VERSION}
${IMAGE_DOMAIN}/${IMAGE_NAMESPACE}/pause:${PAUSE_VERSION}
${IMAGE_DOMAIN}/${IMAGE_NAMESPACE}/etcd:${ETCD_VERSION}
calico/node:${CALICO_VERSION}
calico/kube-controllers:${CALICO_VERSION}
calico/node:${CALICO_VERSION}
calico/typha:${CALICO_VERSION}
calico/node-driver-registrar:${CALICO_VERSION}
calico/csi:${CALICO_VERSION}
calico/cni:${CALICO_VERSION}
calico/ctl:${CALICO_VERSION}
calico/pod2daemon-flexvol:${CALICO_VERSION}
calico/apiserver:${CALICO_VERSION}
"
#${IMAGE_DOMAIN}/${IMAGE_NAMESPACE}/registry:${REGISTRY_VERSION}newimage_list=()
for image in ${image_list}; dodocker pull "${image}"newimage=$(echo $image | sed -e "s/calico/${LOCAL_IMAGE_DOMAIN}\/calico/")newimage=$(echo $newimage | sed -e "s/${IMAGE_DOMAIN}\/${IMAGE_NAMESPACE}/${LOCAL_IMAGE_DOMAIN}\/${LOCAL_IMAGE_NAMESPACE}/")newimage_list+="${newimage} "docker tag $image $newimagedocker push $newimage
donedocker save -o qinghub-kube-"${VERSION}".tar ${newimage_list}
轻云官方下载

https:/qingplus.cn/pkg/kubernetes/v1.29.4/qinghub-kube-v1.29.4.tar
下载完成后再手动导入所有的镜像即可。详细过程不在细说。

环境初始化

检查步骤
  1. 关闭防火墙
  2. 关闭 swap partition permanently
  3. 配置检查时间同步
  4. 配置安装时间同步组件
  5. 配置检查 nfs-utils kubeadmin方式安装不需要检查
  6. 配置检查内核版本
  7. 配置检查资源情况
  8. 配置检查SSH
  9. 配置检查系统配置
  10. 配置检查转发 IPv4
  11. 配置检查Docker用户并添加ssh免密认证<authoirzed_keys> (建议手动执行)
  12. 配置检查Docker (容器运行时为Containerd时,不需要检查)
  13. 配置检查Docker用户权限 (容器运行时为Containerd时,不需要检查)
  14. 配置检查网络
完整的初始化脚本
#!/bin/bash###############################################
# QingHub K8S Install 版本: $VERSION
# 架构: $ARCH_TYPE 目前版本主要支持amd64,其他待敬请期待
# 操作系统: $os_type
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################ENV_CFG=./env.cfg
if [ -f ${ENV_CFG} ] ; thenchmod 777 ${ENV_CFG}source ${ENV_CFG}
fiexport CONSOLE=${CONSOLE:-false}
os_type=$(cat /etc/os-release | grep "^ID=" | awk -F= '{print $2}' | tr -d [:punct:])
os_version_id=$(cat /etc/os-release | grep "VERSION_ID=" | awk -F= '{print $2}' | tr -d [:punct:])if [ "$EUID" -ne 0 ]; thenif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${RED}[ERROR] 当前用户不是 root 用户,请切换到 root 用户执行该脚本.${NC}"exit 1elseecho -e "${RED}[ERROR] Current user is not root user, please switch to root user to execute the script.${NC}"exit 1fi
fiif [ -z "$SSH_RSA" ]; thenif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${RED}[ERROR] 请设置环境变量 SSH_RSA, 该变量为 SSH 公钥.${NC}"exit 1elseecho -e "${RED}[ERROR] Please set the environment variable SSH_RSA, the variable is SSH public key.${NC}"exit 1fi
fi###############################################
# 新增ubuntu 用户
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function add_user_in_ubuntu() {useradd --create-home -s /bin/bash -g root "$1"echo "$1":"$2" | chpasswdif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${GREEN}[INFO] 用户 $1 已经创建.${NC}"elseecho -e "${GREEN}[INFO] User $1 has been created.${NC}"fi
}###############################################
# 新增redhat 用户
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function add_user_in_redhat() {adduser -g root "$1"echo "$1":"$2" | chpasswdif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${GREEN}[INFO] 用户 $1 已经创建.${NC}"elseecho -e "${GREEN}[INFO] User $1 has been created.${NC}"fi
}###############################################
# 描述: 检查并新增用户, 有些版本可以不用检查,请使用时根据
# 情况自行注释掉
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function check_user() {if ! grep -q docker /etc/group; thengroupadd --force dockerfiif id -u "${DOCKER_USER}" >/dev/null 2>&1; thenif ! id -nG "${DOCKER_USER}" | grep -qw "docker"; thengpasswd -a "${DOCKER_USER}" dockerfiif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${GREEN}[INFO] 用户 ${DOCKER_USER} 已经存在.${NC}"elseecho -e "${GREEN}[INFO] User ${DOCKER_USER} already exists.${NC}"fielsecase $os_type incentos|redhat|euleros|fusionos|anolis|kylin|rhel|rocky|fedora|openEuler)add_user_in_redhat "${DOCKER_USER}" "${DOCKER_PASS}";;ubuntu|debian)add_user_in_ubuntu "${DOCKER_USER}" "${DOCKER_PASS}";;*)if [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${RED}[ERROR] 暂不支持 $os_type 操作系统.${NC}"exit 1elseecho -e "${RED}[ERROR] The $os_type operating system is temporarily not supported.${NC}"exit 1fi;;esacfi$CONSOLE$CONSOLE || add_ssh_rsa "${DOCKER_USER}"
}function add_ssh_rsa() {if id -u "$user" >/dev/null 2>&1; thenif [ ! -d "/home/$1/.ssh" ]; thenif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${GREEN}[INFO] 创建 /home/$1/.ssh 目录.${NC}"elseecho -e "${GREEN}[INFO] Create /home/$1/.ssh directory.${NC}"fimkdir -p /home/"$1"/.sshfiif [ -f "/home/$1/.ssh/authorized_keys" ]; thenif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${GREEN}[INFO] /home/$1/.ssh/authorized_keys 已经存在.${NC}"elseecho -e "${GREEN}[INFO] /home/$1/.ssh/authorized_keys already exists.${NC}"fichmod 777 /home/"$1"/.ssh/authorized_keysif ! < /home/"$1"/.ssh/authorized_keys grep -q "$SSH_RSA"; thenecho "$SSH_RSA" >> /home/"$1"/.ssh/authorized_keysfielseif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${GREEN}[INFO] 创建 /home/$1/.ssh/authorized_keys.${NC}"elseecho -e "${GREEN}[INFO] Create /home/$1/.ssh/authorized_keys.${NC}"fitouch /home/"$1"/.ssh/authorized_keyschmod 777 /home/"$1"/.ssh/authorized_keysecho "$SSH_RSA" > /home/"$1"/.ssh/authorized_keysfiif < /home/"$1"/.ssh/authorized_keys grep -q "$SSH_RSA"; thenif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${GREEN}[INFO] 成功将 SSH 公钥添加到 /home/$1/.ssh/authorized_keys.${NC}"elseecho -e "${GREEN}[INFO] Successfully added ssh public key to /home/$1/.ssh/authorized_keys.${NC}"fielseif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${RED}[ERROR] 将 SSH 公钥添加到 /home/$1/.ssh/authorized_keys 失败.${NC}"exit 1elseecho -e "${RED}[ERROR] Add ssh public key to /home/$1/.ssh/authorized_keys failed.${NC}"exit 1fifichmod 600 /home/"$1"/.ssh/authorized_keyschown -R "$1":"$1"  /home/"$1"/.sshfi
}function check_user_permission(){if su ${DOCKER_USER} -c "docker ps" >/dev/null 2>&1; thenif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${GREEN}[INFO] Docker 用户有权限执行 docker 命令.${NC}"elseecho -e "${GREEN}[INFO] Docker users have the permission to execute docker commands.${NC}"fielseif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${RED}[ERROR] Docker 用户无权限执行 docker 命令, 请尝试重启docker 'systemctl restart docker'. 重启 docker 后, 再次执行该脚本.${NC}"exit 1elseecho -e "${RED}[ERROR] Docker users have no permission to execute docker commands, Please try to restart docker 'systemctl restart docker'. After restarting docker, execute the script again.${NC}"exit 1fifi
}###############################################
# 描述: 关闭防火墙
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function disable_firewalld() {if systemctl status firewalld | grep Active | grep -q running >/dev/null 2>&1; thensystemctl stop firewalld >/dev/null 2>&1systemctl disable firewalld >/dev/null 2>&1if [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${GREEN}[INFO] 检测到 Firewalld 服务已启动,正在将 Firewalld 服务关闭并禁用.${NC}"elseecho -e "${GREEN}[INFO] The Firewalld service has been started, Firewalld service is being turned off and disabled.${NC}"fielseif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${GREEN}[INFO] Firewalld 服务已经停止或未安装.${NC}"elseecho -e "${GREEN}[INFO] Firewalld service is not installed.${NC}"fifi
}###############################################
# 描述: 关闭swap
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function disable_swap() {if swapoff -a; thensed -i '/swap/s/^/#/' /etc/fstabif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${GREEN}[INFO] swap 已经禁用.${NC}"elseecho -e "${GREEN}[INFO] swap has been disabled.${NC}"fifi
}function check_time_sync() {if timedatectl status | grep "NTP synchronized" | grep -q "yes" >/dev/null 2>&1 || timedatectl show | grep "NTPSynchronized=yes" >/dev/null 2>&1; thenif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${GREEN}[INFO] NTP 时间同步已经启用.${NC}"elseecho -e "${GREEN}[INFO] NTP time synchronization has been enabled.${NC}"fielseif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${YELLOW}[WARN] NTP 时间同步未启用.${NC}"elseecho -e "${YELLOW}[WARN] NTP time synchronization is not enabled.${NC}"fifi
}###############################################
# 描述: 安装时钟同步,请酌情修改并安装
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
install_chrony(){case $os_type inubuntu|debian)if dpkg -l | grep -q chrony >/dev/null 2>&1; thenecho -e "${GREEN}[INFO] chrony 已经安装在主机上.${NC}"elseecho -e "${YELLOW}[WARN] chrony 未安装在主机上, 请执行命令安装 'apt -y install chrony'.${NC}"apt -y install chrony &> /dev/null;systemctl restart chronyd && systemctl enable --now chronyd &> /dev/nullsystemctl is-active chronyd &> /dev/nullfi;;*)if rpm -qa | grep -q chrony >/dev/null 2>&1; thenif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${GREEN}[INFO] chrony 已经安装在主机上.${NC}"elseecho -e "${GREEN}[INFO] chrony has been installed on the host.${NC}"fielseif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${YELLOW}[WARN] chrony 未安装在主机上, 请执行命令安装 'yum -y install chrony'.${NC}"elseecho -e "${YELLOW}[WARN] chrony is not installed on the host, please execute the command install 'yum -y install chrony'.${NC}"fiyum -y install chronyfi;;esacif [ "${CHRONY_TYPE}" == 'server' ]; thensudo bash -c 'cat > /etc/chrony.conf << EOF
pool ntp.aliyun.com iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
allow 10.0.0.0/24
local stratum 10
keyfile /etc/chrony.keys
leapsectz right/UTC
logdir /var/log/chrony
EOF'elsesudo bash -c 'cat > /etc/chrony.conf << EOF
pool ${CHRONY_SERVER} iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
keyfile /etc/chrony.keys
leapsectz right/UTC
logdir /var/log/chrony
EOF'fisystemctl restart chronyd && systemctl enable --now chronyd &> /dev/nullsystemctl is-active chronyd &> /dev/nullif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${GREEN}[INFO] chrony 完成配置在主机上.${NC}"elseecho -e "${GREEN}[INFO] chrony has been configured on the host.${NC}"fi
}###############################################
# 描述: 优化配置forwarding_ipv4
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function check_forwarding_ipv4() {sudo bash -c 'cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF'sudo modprobe overlaysudo modprobe br_netfiltersudo bash -c 'cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF'sudo sysctl --system#加载ipvs模块sudo bash -c 'cat <<EOF | sudo tee /etc/modules-load.d/ipvs.conf <<EOF
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
nf_conntrack
ip_tables
ip_set
xt_set
ipt_set
ipt_rpfilter
ipt_REJECT
ipip
EOF'systemctl restart systemd-modules-load.service
}###############################################
# 描述: 检查服务器资源状况
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function check_resource(){cpu=$(grep -c 'processor' /proc/cpuinfo)mem=$(free -g | awk '/^Mem/{print $2}')DISK_SPACE=$(df /|sed -n '2p'|awk '{print $2}')# check cpuif [ "${cpu}" -lt 2 ]; thenif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${YELLOW}[WARN] CPU核数建议至少为2核.${NC}"elseecho -e "${YELLOW}[WARN] The cpu is recommended to be at least 2C.${NC}"fifi# check memoryif [ "${mem}" -lt 3 ]; thenif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${YELLOW}[WARN] 内存建议至少为8G.${NC}"elseecho -e "${YELLOW}[WARN] The Memory is recommended to be at least 8G.${NC}"fifi# check disk spaceif [ "${DISK_SPACE}" -lt 47185920 ];thenif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${YELLOW}[WARN] 根分区空间需大于 50G.${NC}"elseecho -e "${YELLOW}[WARN] The root partition space must be greater than 50G.${NC}"fifi
}###############################################
# 描述: 检查内核版本
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function check_kernel() {kernel_version=$(uname -r | awk -F. '{print $1}')if [ "$kernel_version" -lt "4" ]; thenif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${YELLOW}[WARN] 内核版本必须高于4.0, 请尽快升级内核到4.0+.${NC}"elseecho -e "${YELLOW}[WARN] Kernel version must be higher than 4.0, Please upgrade the kernel to 4.0+ as soon as possible.${NC}"fifi
}###############################################
# 描述: 检查 nfs是否安装,这里并未自动安装
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function check_nfscli(){case $os_type inubuntu|debian)if dpkg -l | grep -q nfs-common >/dev/null 2>&1; thenif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${GREEN}[INFO] nfs-common 已经安装在主机上.${NC}"elseecho -e "${GREEN}[INFO] nfs-common has been installed on the host.${NC}"fielseif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${YELLOW}[WARN] nfs-common 未安装在主机上, 请执行命令安装 'apt -y install nfs-common'.${NC}"elseecho -e "${YELLOW}[WARN] nfs-common is not installed on the host, please execute the command install 'apt-get update && apt -y install nfs-common'.${NC}"fifi;;*)if rpm -qa | grep -q nfs-utils >/dev/null 2>&1; thenif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${GREEN}[INFO] nfs-utils 已经安装在主机上.${NC}"elseecho -e "${GREEN}[INFO] nfs-utils has been installed on the host.${NC}"fielseif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${YELLOW}[WARN] nfs-utils 未安装在主机上, 请执行命令安装 'yum -y install nfs-utils'.${NC}"elseecho -e "${YELLOW}[WARN] nfs-utils is not installed on the host, please execute the command install 'yum -y install nfs-utils'.${NC}"fifi;;esac
}function check_openssh(){if ssh -V >/dev/null 2>&1; thenOPENSSH_VERSION=$(ssh -V |& awk -F[_.] '{print $2}')if [ "${OPENSSH_VERSION}" -lt "7" ];thenif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${YELLOW}[WARN] Openssh 版本必须高于 7.0.${NC}"elseecho -e "${YELLOW}[WARN] Openssh version must be higher than 7.0 ${NC}"fifielseif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${RED}[ERROR] 需要安装 7.0+ 版本的openssh.${NC}"exit 1elseecho -e "${RED}[ERROR] Need to install 7.0+ version of openssh.${NC}"exit 1fifiif grep -v "^\s*#" /etc/ssh/sshd_config | grep "AllowTcpForwarding yes" >/dev/null 2>&1; thenif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${GREEN}[INFO] /etc/ssh/sshd_config 已经配置 AllowTcpForwarding yes.${NC}"elseecho -e "${GREEN}[INFO] /etc/ssh/sshd_config has been configured AllowTcpForwarding yes.${NC}"fielseif grep "AllowTcpForwarding no" /etc/ssh/sshd_config >/dev/null 2>&1; thensed -i '/AllowTcpForwarding/s/^/#/' /etc/ssh/sshd_configsed -i '$a\AllowTcpForwarding yes' /etc/ssh/sshd_configelsesed -i '$a\AllowTcpForwarding yes' /etc/ssh/sshd_configfiif [ "$LANG" == "zh_CN.UTF-8" ]; thenecho -e "${YELLOW}[WARN] /etc/ssh/sshd_config 配置 AllowTcpForwarding yes 成功, 请执行命令重启 sshd 服务生效, 'systemctl restart sshd'.${NC}"elseecho -e "${YELLOW}[WARN] /etc/ssh/sshd_config AllowTcpForwarding yes is successfully configured, Run the following command to restart the sshd service to take effect, 'systemctl restart sshd'.${NC}"fifi
}###############################################
# 描述: 优化参数
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function optimize_linux() {sudo bash -c 'cat > /etc/sysctl.conf << EOF
net.bridge.bridge-nf-call-ip6tables=1
net.bridge.bridge-nf-call-iptables=1
net.ipv4.ip_forward=1
net.ipv4.conf.all.forwarding=1
net.ipv4.neigh.default.gc_thresh1=4096
net.ipv4.neigh.default.gc_thresh2=6144
net.ipv4.neigh.default.gc_thresh3=8192
net.ipv4.neigh.default.gc_interval=60
net.ipv4.neigh.default.gc_stale_time=120
kernel.perf_event_paranoid=-1
#sysctls for k8s node config
net.ipv4.tcp_slow_start_after_idle=0
net.core.rmem_max=16777216
fs.inotify.max_user_watches=524288
kernel.softlockup_all_cpu_backtrace=1
kernel.softlockup_panic=0
kernel.watchdog_thresh=30
fs.file-max=2097152
fs.inotify.max_user_instances=8192
fs.inotify.max_queued_events=16384
vm.max_map_count=262144
fs.may_detach_mounts=1
net.core.netdev_max_backlog=16384
net.ipv4.tcp_wmem=4096 12582912 16777216
net.core.wmem_max=16777216
net.core.somaxconn=32768
net.ipv4.ip_forward=1
net.ipv4.tcp_max_syn_backlog=8096
net.ipv4.tcp_rmem=4096 12582912 16777216net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1kernel.yama.ptrace_scope=0
vm.swappiness=0
kernel.core_uses_pid=1
# Do not accept source routing
net.ipv4.conf.default.accept_source_route=0
net.ipv4.conf.all.accept_source_route=0# Promote secondary addresses when the primary address is removed
net.ipv4.conf.default.promote_secondaries=1
net.ipv4.conf.all.promote_secondaries=1# Enable hard and soft link protection
fs.protected_hardlinks=1
fs.protected_symlinks=1net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_announce=2
net.ipv4.conf.all.arp_announce=2net.ipv4.tcp_max_tw_buckets=5000
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_fin_timeout=30
net.ipv4.tcp_synack_retries=2
kernel.sysrq=1
EOF'sudo sysctl -p >/dev/null 2>&1echo -e "${GREEN}[INFO] 优化kernel参数成功${NC}"
}function optimize_limits() {sudo bash -c 'cat >> /etc/security/limits.conf <<EOF
* soft nofile 1024000
* hard nofile 1024000
EOF'echo -e "${GREEN}[INFO] 优化limits参数成功${NC}"
}
function check_syscfg(){sudo chmod 777 /etc/sysctl.confsudo chmod 777 /sbin/sysctlsudo chmod 777 /etc/security/limits.confoptimize_linuxoptimize_limitssudo chmod 644 /etc/sysctl.confsudo chmod 755 /sbin/sysctlsudo chmod 644 /etc/security/limits.conf
}###############################################
# 描述: calico 网络配置初始化
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function  check_network() {sudo bash -c 'cat >> /etc/NetworkManager/conf.d/calico.conf << EOF
[keyfile]
unmanaged-devices=interface-name:cali*;interface-name:tunl*
unmanaged-devices=interface-name:cali*;interface-name:tunl*;interface-name:vxlan.calico;interface-name:wireguard.cali
EOF'systemctl restart NetworkManager
}###############################################
# 描述: 主入口函数
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function main {echo -e "${GREEN}[INFO] ==========开始检查并配置初始化========= ${NC}"# 停止 friewallddisable_firewalld# 关闭 swap partition permanentlydisable_swap# 配置检查时间同步check_time_sync# 配置安装时间同步组件install_chrony# 配置检查 nfs-utils kubeadmin方式安装不需要检查#check_nfscli# 配置检查内核版本check_kernel# 配置检查资源情况check_resource# 配置检查SSHcheck_openssh# 配置检查系统配置check_syscfg# 转发 IPv4check_forwarding_ipv4# 配置检查Docker用户并添加ssh免密认证<authoirzed_keys>check_user# 配置检查Docker  容器运行时为Containerd时,不需要检查#check_docker# 配置检查Docker用户权限 容器运行时为Containerd时,不需要检查#check_user_permission# 配置检查网络check_networkecho -e "${GREEN}[INFO] ==========成功完成检查并配置初始化========= ${NC}"
}main

组件安装

需要安装的组件列表
  1. 安装containerd
  2. 部署containerd 配置文件
  3. 安装cni plugin
  4. 安装crictl
  5. 安装runc
  6. 安装部署kubeadm、kubelet、kubectl

特别关注:
再拷贝kubeadm、kubelet、kubectl文件后,务必记得要创建必须要的几个目录,否则会导致后面初始化控制平面时会出错,详情见完整的安装脚本
sudo mkdir -p /var/lib/kubelet
sudo mkdir -p /etc/kubernetes/manifests
yum 自动从网络安装不会出现该问题,会自动创建。

  1. 初始化集群第一控制平面节点
安装完整的脚本
#!/bin/bash
###############################################
# QingHub K8S Install 版本: $VERSION
# 架构: $ARCH_TYPE 目前版本主要支持amd64,其他待敬请期待
# 操作系统: $os_type
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                           https://qinghub.net
###############################################
ENV_CFG=./env.cfg
if [ -f ${ENV_CFG} ] ; thenchmod 777 ${ENV_CFG}source ${ENV_CFG}
fi
os_type=$(uname -s)if [ $(arch) = "x86_64" ] || [ $(arch) = "amd64" ]; thenarch_type=amd64
elif [ $(arch) = "aarch64" ] || [ $(arch) = "arm64" ]; thenarch_type=arm64
elif [ $(arch) = "i386" ]; thenarch_type=amd64echo -e "${YELLOW}[WAIN] 检测到 i386, 我们暂时把它当做 x86_64(amd64) ${NC}"
elseecho -e "${RED}[ERROR] QingHub Studio 目前还不支持 $(arch) 架构 ${NC}"exit 1
fi###############################################
# 复制并安装cri_containerd_cni 包括:cri, containerd,cni三合一,后续会覆盖安装
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function install_cri_containerd_cni(){echo -e "${GREEN}[INFO] 下载并安装cri_containerd_cni二级制文件 ${cri_containerd_cni_name} ${NC}"if [[ -e /usr/bin/curl ]]; then# 离线下载文件请修改TODOcurl -L ${cri_containerd_cni_url} | sudo tar -C / -xz || {echo -e "${RED}[ERROR] 下载并安装cri_containerd_cni二进制文件失败 ${NC}"exit 1}elsewget -c "$cri_containerd_cni_url" | sudo tar -C / -xz || {echo -e "${RED}[ERROR] 下载cri_containerd_cni二进制文件失败 ${NC}"exit 1}fiecho -e "${GREEN}[INFO] 创建containerd.service 文件 ${NC}"sudo systemctl enable --now containerdecho -e "${GREEN}[INFO] 安装containerd成功${NC}"
}###############################################
# 描述: 初始化containerd 配置文件,添加修改仓库信息,请酌情修改
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function install_containerd_config(){mkdir -p /etc/containerdsudo /usr/local/bin/containerd config default | tee /etc/containerd/config.toml# 修改Containerd的配置文件sudo sed -i "s#SystemdCgroup\ \=\ false#SystemdCgroup\ \=\ true#g" /etc/containerd/config.tomlcat /etc/containerd/config.toml | grep SystemdCgroupsudo sed -i "s#registry.k8s.io\/pause:3.8#qinghub.net:5000\/qingcloudtech\/pause:3.9#g" /etc/containerd/config.tomlcat /etc/containerd/config.toml | grep sandbox_imagesudo sed -i "s#config_path\ \=\ \"\"#config_path\ \=\ \"/etc/containerd/certs.d\"#g" /etc/containerd/config.tomlcat /etc/containerd/config.toml | grep certs.dmkdir /etc/containerd/certs.d/qinghub.net:5000 -pvsudo bash -c 'cat > /etc/containerd/certs.d/qinghub.net:5000/hosts.toml << EOF
server = "qinghub.net:5000"
[host."qinghub.net:5000"]capabilities = ["pull", "resolve"]
EOF'mkdir /etc/containerd/certs.d/docker.io -pvsudo bash -c 'cat > /etc/containerd/certs.d/docker.io/hosts.toml << EOF
server = "https://docker.io"
[host."https://qinghub.net:5000"]capabilities = ["pull", "resolve"]
[host."https://dockerproxy.com"]capabilities = ["pull", "resolve"]
[host."https://docker.m.daocloud.io"]capabilities = ["pull", "resolve"]
[host."https://reg-mirror.qiniu.com"]capabilities = ["pull", "resolve"]
[host."http://hub-mirror.c.163.com"]capabilities = ["pull", "resolve"]
EOF'systemctl daemon-reloadsystemctl restart containerd.service
}###############################################
# 描述: 安装cni文件
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function install_cni_plugins(){DEST="/opt/cni/bin"sudo mkdir -p "$DEST"echo -e "${GREEN}[INFO] 下载并安装cni_plugins二级制文件 ${cni_plugins_name} ${NC}"if [[ -e /usr/bin/curl ]]; then# 离线下载文件请修改TODOcurl -L ${cni_plugins_url} | sudo tar -C "$DEST" -xz || {echo -e "${RED}[ERROR] 下载cni_plugins二进制文件失败 ${NC}"exit 1}elsewget -c "$cni_plugins_url" | sudo tar -C "$DEST" -xz || {echo -e "${RED}[ERROR] 下载cni_plugins二进制文件失败 ${NC}"exit 1}fiecho -e "${GREEN}[INFO] 安装cni_plugins成功${NC}"
}###############################################
# 描述: 拷贝runc文件
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function install_runc(){DEST="/usr/bin"sudo mkdir -p "$DEST"cd "$DEST"echo -e "${GREEN}[INFO] 下载并安装runc二级制文件 ${runc_name} ${NC}"if [[ -e /usr/bin/curl ]]; then# 离线下载文件请修改TODOcurl -L -O ${runc_url} || {echo -e "${RED}[ERROR] 下载并安装runc二进制文件失败 ${NC}"exit 1}elsewget -c "$runc_url" || {echo -e "${RED}[ERROR] 下载runc二进制文件失败 ${NC}"exit 1}fiif [ -f $DEST/runc.amd64 ]; thenchmod +x $DEST/runc.amd64mv $DEST/runc.amd64 $DEST/runcfiecho -e "${GREEN}[INFO] 安装runc成功${NC}"
}###############################################
# 描述: 拷贝crictl工具文件
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function install_crictl(){DEST="/usr/local/bin"sudo mkdir -p "$DEST"echo -e "${GREEN}[INFO] 下载并安装crictl二级制文件 ${crictl_name} ${NC}"if [[ -e /usr/bin/curl ]]; then# 离线下载文件请修改TODOsudo curl -L ${crictl_url} | sudo tar -C $DEST -xz || {echo -e "${RED}[ERROR] 下载crictl二进制文件失败 ${NC}"exit 1}elsesudo wget -c "$crictl_url" | sudo tar -C "$DEST" -xz || {echo -e "${RED}[ERROR] 下载crictl二进制文件失败 ${NC}"exit 1}fiecho -e "${GREEN}[INFO] 安装crictl成功${NC}"#生成配置文件sudo bash -c "cat > /etc/crictl.yaml <<EOF
runtime-endpoint: unix:///run/containerd/containerd.sock
image-endpoint: unix:///run/containerd/containerd.sock
timeout: 10
EOF"systemctl restart containerd
}###############################################
# 描述: 安装kubeadmin,kubelet,kubectl,在每个节点都需要安装kubeadmin,kubelet,
# kubectl根据情况在合适的控制平台节点安装,可以修改参数$QINGCLOUD_KUBECTL_FLAG=no关闭安装
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function install_kubeadm(){TEMP="/tmp"echo -e "${GREEN}[INFO] 下载Kubernetes二级制文件 ${KUBERNETES_VERSION} ${NC}"if [[ -e /usr/bin/curl ]]; then# 离线下载文件请修改TODOsudo curl -L "${kubernetes_server_url}" | sudo tar -C "$TEMP" -xz || {echo -e "${RED}[ERROR] 下载Kubernetes二进制文件失败 ${NC}"exit 1}elsesudo wget -c "$kubernetes_server_url" | sudo tar -C "$TEMP" -xz || {echo -e "${RED}[ERROR] 下载Kubernetes二进制文件失败 ${NC}"exit 1}fiDEST="/usr/bin"cd $DESTsudo cp $TEMP/kubernetes/server/bin/{kubeadm,kubelet} .sudo chmod +x {kubeadm,kubelet}echo -e "${GREEN}[INFO] 成功安装kubeadm,kubelet到${DEST}目录 ${NC}"echo -e "${GREEN}[INFO] 创建kubelet.service 文件 ${NC}"sudo bash -c "cat > /usr/lib/systemd/system/kubelet.service <<EOF
[Unit]
Description=kubelet: The Kubernetes Node Agent
Documentation=https://kubernetes.io/docs/
Wants=network-online.target
After=network-online.target[Service]
ExecStart=${DEST}/kubelet
Restart=always
StartLimitInterval=0
RestartSec=10[Install]
WantedBy=multi-user.target
EOF"sudo mkdir -p /usr/lib/systemd/system/kubelet.service.decho -e "${GREEN}[INFO] 创建10-kubeadm.conf 文件 ${NC}"sudo bash -c "cat > /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf <<EOF
[Service]
Environment=\"KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf\"
Environment=\"KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml\"
EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
EnvironmentFile=-/etc/sysconfig/kubelet
ExecStart=
ExecStart=$DEST/kubelet \\\$KUBELET_KUBECONFIG_ARGS \\\$KUBELET_CONFIG_ARGS \\\$KUBELET_KUBEADM_ARGS \\\$KUBELET_EXTRA_ARGS
EOF"
sudo bash -c "cat > /etc/sysconfig/kubelet <<EOF
KUBELET_EXTRA_ARGS=
EOF"#创建必须要的几个目录sudo mkdir -p /var/lib/kubeletsudo mkdir -p /etc/kubernetes/manifestssudo systemctl enable kubeletif [ "$QINGCLOUD_KUBECTL_FLAG" == "yes" ]; thencd $DESTsudo cp ${TEMP}/kubernetes/server/bin/kubectl .sudo chmod +x kubectlecho -e "${GREEN}[INFO] 成功安装kubectl到${DEST}目录 ${NC}"fiif [[ -d "${TEMP}/kubernetes" ]]; thensudo rm -rf "${TEMP}/kubernetes-server-linux-amd64"echo -e "${GREEN}[INFO] 临时安装文件${TEMP}/kubernetes-server-linux-amd64正常删除 ${NC}"fi
}###############################################
# 描述: 初始化控制平面节点。
# ${QINGCLOUD_ADVERTISE_ADDRESS}       ApiServer地址,请根据情况填写,可以是配置的高可用地址
# ${LOCAL_IMAGE_DOMAIN}               本地容器镜像仓库地址
# ${LOCAL_IMAGE_NAMESPACE}            本地容器镜像命名空间
# ${KUBERNETES_VERSION}               K8S版本
# QingHub Studio官网: https://qinghub.net
# 如过您安装遇到问题,请到官网查找官方联系方式或加支持群:
#                                https://qinghub.net
###############################################
function init_cluster(){echo -e "${GREEN}[INFO] ==========初始化第一个控制平面,请根据输出结果初始其他他节点========= ${NC}"kubeadm init \--apiserver-advertise-address="${QINGCLOUD_ADVERTISE_ADDRESS}" \--image-repository "${LOCAL_IMAGE_DOMAIN}/${LOCAL_IMAGE_NAMESPACE}" \--kubernetes-version "${KUBERNETES_VERSION}" \--cri-socket=unix:///run/containerd/containerd.sock \--service-cidr=10.96.0.0/16 \--pod-network-cidr=172.16.0.0/16
}# 主入口地址,根据实际可以手动执行相关内容
function main {echo -e "${GREEN}[INFO] ==========开始安装kubernetes========= ${NC}"#安装containerdinstall_cri_containerd_cni#安装cni plugininstall_cni_plugins#安装containerd 配置文件install_containerd_config#安装crictlinstall_crictl#安装runcinstall_runc#安装kubeadminstall_kubeadm#初始化集群master节点if [ "$QINGCLOUD_KUBECTL_FLAG" == "yes" ] ;theninit_clusterfiecho -e "${GREEN}[INFO] ==========完成安装kubernetes========= ${NC}"
}main

执行命令初始化第一个控制平面节点

在上节的安装过程中,实际以及包含了初始化第一个控制平面的脚本,由于其重要性,这里单独提出来详细说明。
通过执行kubeadm init 指令快速初始化控制平面,可以通过直接待参数的方式或通过–config加配置文件的方式实现:

配置参数形式
kubeadm init \--apiserver-advertise-address="${QINGCLOUD_ADVERTISE_ADDRESS}" \--image-repository "${LOCAL_IMAGE_DOMAIN}/${LOCAL_IMAGE_NAMESPACE}" \--kubernetes-version "${KUBERNETES_VERSION}" \--cri-socket=unix:///run/containerd/containerd.sock \--service-cidr=10.96.0.0/16 \--pod-network-cidr=172.16.0.0/16
配置文件形式

第一步:如下命令生成默认配置文件并作修改

kubeadm config print init-defaults > initConfig.yaml

第二步:执行命令

kubeadm init --config=initConfig.yaml 
准备kubectl配置文件

根据上面的指令生成的结果,拷贝如下命令后直接执行,使得kubectl后面可以直接运行

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

加入Node节点

根据执行命令生成第一个控制平面的结果,拷贝如下类似的文件到node节点。直接执行:

kubeadm join x.x.x.x:6443 --token picxyk.su53y03l1z0jh333e \--discovery-token-ca-cert-hash sha256:01fecbd4bdc0513811f7b65a43e41820d703a91c631e262b1ad4634e12cd0205 --cri-socket=unix:///run/containerd/containerd.sock

执行kubectl get nodes 查看node节点执行结果

[root@itserver-master2 kube]# kubectl get nodes
NAME               STATUS   ROLES           AGE   VERSION
itserver-master2   Ready    control-plane   2h    v1.29.4
itserver-node4     Ready    <none>          1m    v1.29.4
[root@itserver-master2 kube]# 

部署网络插件

我们采用calico作为网络插件,calico最新版建议的部署方式为两个步骤,执行两个文件即可:
tigera-operator.yaml、custom-resources.yaml

下载tigera-operator.yaml

https://github.com/projectcalico/calico/blob/v3.27.3/manifests/tigera-operator.yaml
https://github.com/projectcalico/calico/blob/v3.27.3/manifests/custom-resources.yaml

修改tigera-operator.yaml文件内容(离线版)

注意:修改镜像地址,请根据自己保存镜像的实际地址修改

[root@web02 v1.29.4]# cat tigera-operator.yaml | grep image:image:image: quay.io/tigera/operator:v1.32.7
[root@web02 v1.29.4]# 
[root@web02 v1.29.4]# sudo sed -i "s#quay.io\/tigera#qinghub.net:5000\/qingcloudtech#g" tigera-operator.yaml
[root@web02 v1.29.4]# cat tigera-operator.yaml | grep image:image:image: qinghub.net:5000/qingcloudtech/operator:v1.32.7
[root@web02 v1.29.4]# ll
执行kubectl create -f tigera-operator.yaml
[root@itserver-master2 kube]# kubectl create  -f tigera-operator.yaml 
namespace/tigera-operator created
customresourcedefinition.apiextensions.k8s.io/bgpconfigurations.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/bgpfilters.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/bgppeers.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/blockaffinities.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/caliconodestatuses.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/clusterinformations.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/felixconfigurations.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/globalnetworkpolicies.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/globalnetworksets.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/hostendpoints.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/ipamblocks.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/ipamconfigs.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/ipamhandles.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/ippools.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/ipreservations.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/kubecontrollersconfigurations.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/networkpolicies.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/networksets.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/apiservers.operator.tigera.io created
customresourcedefinition.apiextensions.k8s.io/imagesets.operator.tigera.io created
customresourcedefinition.apiextensions.k8s.io/installations.operator.tigera.io created
customresourcedefinition.apiextensions.k8s.io/tigerastatuses.operator.tigera.io created
serviceaccount/tigera-operator created
clusterrole.rbac.authorization.k8s.io/tigera-operator created
clusterrolebinding.rbac.authorization.k8s.io/tigera-operator created
deployment.apps/tigera-operator created
[root@itserver-master2 kube]# 
查看结果
[root@itserver-master2 kube]# kubectl get pods -n tigera-operator
NAME                               READY   STATUS    RESTARTS   AGE
tigera-operator-6779dc6889-zd4zt   1/1     Running   0          55s
[root@itserver-master2 kube]# 
修改custom-resources.yaml

注意: 主要修改内容:cidr: 172.16.0.0/16,需要与控制平面初始化时的地址填写的地址一直

spec:# Configures Calico networking.calicoNetwork:# Note: The ipPools section cannot be modified post-install.ipPools:- blockSize: 26cidr: 172.16.0.0/12encapsulation: VXLANCrossSubnetnatOutgoing: EnablednodeSelector: all()
执行kubectl create -f custom-resources.yaml
[root@itserver-master2 kube]# kubectl create  -f custom-resources.yaml 
installation.operator.tigera.io/default created
apiserver.operator.tigera.io/default created
[root@itserver-master2 kube]# kubectl get ns
NAME              STATUS   AGE
calico-system     Active   48s
default           Active   3h5m
kube-node-lease   Active   3h5m
kube-public       Active   3h5m
kube-system       Active   3h5m
tigera-operator   Active   6m35s
[root@itserver-master2 kube]# kubectl get pods -n calico-system
NAME                                       READY   STATUS                  RESTARTS   AGE
calico-kube-controllers-68bf945ffc-mf7t2   0/1     ContainerCreating       0          75s
calico-node-27fgm                          0/1     Init:ImagePullBackOff   0          75s
calico-typha-5886b45b65-pmsm7              0/1     ErrImagePull            0          75s
csi-node-driver-9b29j                      0/2     ContainerCreating       0          75s
[root@itserver-master2 kube]# 
calico网络安装后,检查所有空间众的pod:
[root@itserver-master2 certs.d]# kubectl get pods --all-namespaces
NAMESPACE          NAME                                       READY   STATUS    RESTARTS   AGE
calico-apiserver   calico-apiserver-864697c659-2sdhd          1/1     Running   0          4m18s
calico-apiserver   calico-apiserver-864697c659-c2vp9          1/1     Running   0          4m18s
calico-system      calico-kube-controllers-68bf945ffc-dvrlf   1/1     Running   0          63m
calico-system      calico-node-27fgm                          1/1     Running   0          18h
calico-system      calico-node-zwpls                          1/1     Running   0          17h
calico-system      calico-typha-5886b45b65-pmsm7              1/1     Running   0          18h
calico-system      csi-node-driver-9b29j                      2/2     Running   0          18h
calico-system      csi-node-driver-mrtq5                      2/2     Running   0          17h
kube-system        coredns-67bd986d4c-67fvl                   1/1     Running   0          16m
kube-system        coredns-67bd986d4c-x7vk7                   1/1     Running   0          56m
kube-system        etcd-itserver-master2                      1/1     Running   1          21h
kube-system        kube-apiserver-itserver-master2            1/1     Running   1          21h
kube-system        kube-controller-manager-itserver-master2   1/1     Running   1          21h
kube-system        kube-proxy-9rv85                           1/1     Running   0          21h
kube-system        kube-proxy-l9rht                           1/1     Running   1          17h
kube-system        kube-scheduler-itserver-master2            1/1     Running   1          21h
tigera-operator    tigera-operator-6779dc6889-zd4zt           1/1     Running   0          18h
[root@itserver-master2 certs.d]# 

看到如上几个空间中的状态都变为runging时,网络部署成功

测试验证

部署nginx

第一步、部署文件准备nginx.yaml

apiVersion: v1
kind: Service
metadata:name: nginxlabels:app: nginx
spec:ports:- port: 80name: webselector:app: nginx---
apiVersion: apps/v1
kind: Deployment
metadata:name: nginx-deployment
spec:replicas: 1selector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec:containers:- name: nginximage: qingcloudtech/nginx:1.25.4ports:- containerPort: 80name: web

第二部、执行命令

kubectl apply -f nginx.yaml 

第三步、检查service及deployment

[root@itserver-master2 kube]# kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP   22h
nginx        ClusterIP   10.101.221.253   <none>        80/TCP    17s
[root@itserver-master2 kube]# kubectl get deploy -o wide
NAME               READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES                       SELECTOR
nginx-deployment   1/1     1            1           35s   nginx        qingcloudtech/nginx:1.25.4   app=nginx
[root@itserver-master2 kube]# 
[root@itserver-master2 kube]# curl http://172.24.128.130
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p><p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@itserver-master2 kube]# 

至此,完成整个部署过程


你可以通过【QingHub Studio】) 套件直接安装部署,也可以手动按如下文档操作,该项目已经全面开源,完整的脚本可以从如下开源地址获取:
开源地址: https://gitee.com/qingplus/qingcloud-platform
【QingHub Studio集成开发套件】

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/2767.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

掌握Linux Shell脚本函数:提高脚本效率与可维护性

目录标题 1、什么是Shell函数&#xff1f;2、如何定义Shell函数&#xff1f;3、Shell函数参数4、返回值5、实例&#xff1a;使用函数进行文件备份6、为什么使用函数&#xff1f;7、最佳实践 在编写Linux shell脚本时&#xff0c;函数是组织和重用代码的重要手段。本文将介绍如何…

现货白银价格走势分析别走弯路!

参与现货白银投资离不开对其价格走势的分析&#xff0c;虽然相关的分析方法有很多种&#xff0c;但说到直观高效的方法&#xff0c;技术分析就是很多专业投资者所钟爱的选择。投资者可以通过平台交易软件所自带的技术指标和画线工具&#xff0c;来辅助自己的分析&#xff0c;实…

前缀和 求数列的子序列的K倍区间

(直接截图比复制文字要好多了) 不会做的时候我去看了之前做的关于这道题目的笔记&#xff0c; &#xff08;Ak 1&#xff09;% k 1 &#xff08;Ak 1 Ak&#xff09;% k 1 只要发现了同余数的情况就说明有一个区间满足了题目的要求。 这个方法的精妙之处就在于前缀和包括了…

嵌入式Linux driver开发实操(二十一):linux device driver basic设备驱动程序基础

linux的架构框图: 内核空间是内核(即操作系统的核心)执行(即运行)并提供其服务的地方。 用户空间是执行用户应用程序的地方。 内核模块是可以根据需要加载和卸载到内核中的代码片段。它们扩展了内核的功能,而无需重新启动系统。自定义代码可以通过两种方法添加到Linux内…

C++ —— 继承

什么是继承&#xff1f; 继承是指一种代码可以被复用的机制&#xff0c;在一个类的基础上进行扩展&#xff0c;产生的新类叫做派生类&#xff0c;被继承的类叫基类。&#xff08;也可称为子类和父类&#xff09; 继承的写法&#xff1a; class B : 继承方式 A (…

Java高级阶段面试题库(Redis数据库、MQ消息队列、kafka、SpringBoot + SpringCloud、MySQL、JVMJUC、其它)

文章目录 1. Redis数据库篇(忽略)1.1 简单介绍一下redis1.2 单线程的redis为什么读写速度快?1.3 redis为什么是单线程的?1.4 redis服务器的的内存是多大?1.5 为什么Redis的操作是原子性的&#xff0c;怎么保证原子性的&#xff1f;1.6 你还用过其他的缓存吗&#xff1f;这些…

学习Django

1.python安装是会有几个主要目录&#xff1a; 2.如果某个路径加入了环境变量&#xff0c;那么在命令行直接输入他下面的文件就能找到&#xff0c;不用输入完整路径 2.过程 &#xff08;1&#xff09;安装 &#xff08;2&#xff09;建项目 在终端&#xff1a; &#xff08;…

快速回复app是什么样

在电商领域&#xff0c;掌握一些必备的软件工具是提高工作效率、优化运营流程以及提升用户体验的关键。本文将为您介绍做电商必备的几个软件&#xff0c;帮助您更好地开展电商业务。 ​ 快速回复APP&#xff1a;重新定义沟通效率 在快节奏的现代社会中&#xff0c;人们对于沟通…

ZeRO论文阅读

一.前情提要 1.本文理论为主&#xff0c;并且仅为个人理解&#xff0c;能力一般&#xff0c;不喜勿喷 2.本文理论知识较为成体系 3.如有需要&#xff0c;以下是原文&#xff0c;更为完备 Zero 论文精读【论文精读】_哔哩哔哩_bilibili 二.正文 1.前言 ①为什么用该技术&…

Linux网络设置

将Linux主机接入到网络&#xff0c;需要配置网络相关设置 一般包括&#xff1a;主机名&#xff1b;IP/netmask&#xff1b;路由&#xff1a;默认网关&#xff1b;DNS服务器&#xff1a;主DNS服务器&#xff0c;次DNS服务器&#xff0c;第三个DNS服务器 网卡的配置文件在&…

java:观察者模式

java&#xff1a;观察者模式 1 前言 观察者模式&#xff0c;又被称为发布-订阅&#xff08;Publish/Subscribe&#xff09;模式&#xff0c;他定义了一种一对多的依赖关系&#xff0c;让多个观察者对象同时监听某一个主题对象。这个主题对象在状态变化时&#xff0c;会通知所…

百面算法工程师 | 卷积基础知识——Convolution

目录 8.1 图像卷积过程 8.2 卷积层基本参数 8.3 卷积后图像的长和宽大小的计算方式 8.4 卷积神经网络中的权重共享 8.5 上采样中的反卷积 8.6 空洞卷积 8.7 深度可分离卷积 8.8 为什么可分离卷积中Depthwise卷积后还要进行pointwise卷积 8.9 分组卷积 Group Conv 8.1…

AI视频教程下载:ChatGPT个人生产力提升指南

在本课程中&#xff0c;您将学习如何成功地将ChatGPT融入您的工作和生活&#xff0c;以优化您的社交媒体内容并扩展您的业务。 您将学习如何使用ChatGPT自动创建、校对、总结和翻译文本&#xff0c;以及如何与机器人沟通以实现您的目标。 您还将学习如何创建jQuery代码、编程…

倪海厦是怎么去思考问题的(一)下

1《天纪》是自然法则 2自然法则是个《真理》 3《真理》不需要再证实 4《真理》没有二元对立 紧接着第三点&#xff1a;真理不需要再去证实。现在有很多的人呢&#xff0c;看书学习&#xff0c;自认为自己很聪明&#xff0c;总要去证实一些东西。证明谁的说法是错的&#xff…

麒麟龙芯loongarch64 electron 打包deb包

在麒麟龙芯&#xff08;loongarch64&#xff09;电脑上 使用electron 开发桌面应用。之前用electron-packager 打包出来的是文件夹 是 unpack 包。现在需要打包deb包&#xff0c;依据开发指南开始打包。 在项目文件夹下 打开终端 输入 npm run packager 先打包unpack包 然后…

ATFX汇市:澳大利亚一季度CPI年率大降,澳元升值态势延续

▲ATFX图 据澳大利亚统计局数据&#xff0c;第一季度CPI年率最新值3.6%&#xff0c;相比前值4.1%大降0.5个百分点&#xff0c;但仍高于3.5%的预期值。历史数据看&#xff0c;自从2022年四季度创出7.8%阶段性高点之后&#xff0c;澳大利亚的季度CPI年率就保持着稳定的下降态势。…

翻译《The Old New Thing》 - Why are HANDLE return values so inconsistent?

Why are HANDLE return values so inconsistent? - The Old New Thing (microsoft.com)https://devblogs.microsoft.com/oldnewthing/20040302-00/?p40443 Raymond Chen 2004年01月27日 简介 在处理 Windows 编程中的句柄时&#xff0c;开发者需要面对的一个挑战是不同函数可…

SWCTF

easy_php 源码 <?php// flag is in flag.php highlight_file(__FILE__); ini_set(display_errors, 0); error_reporting(0);if (isset($_GET[myon1]) && isset($_GET[myon2]) && isset($_GET[myon3])) {$myon1 $_GET[myon1];$myon2 $_GET[myon2];$myon…

苍穹外卖day12 (Apache POI) 数据统计-Excel报表

文章目录 前言一、工作台1.1 今日数据1.1.1 接口设计1.1.2 代码实现 1.2 订单管理接口1.3菜品总览接口1.4 套餐总览接口1.5 订单搜索&#xff08;已完成&#xff09;1.6 各个状态的订单数量统计&#xff08;已完成&#xff09; 二、Apache POI2.1 概述2.2 效果展示 三、导出运营…

vue中web端播放rtsp视频流(摄像头监控视频)(海康威视录像机)

一、ffmpeg安装​​​​​​ ffmpeg下载 https://ffmpeg.org/download.html找ffmpeg-release-essentials.zip点击下载&#xff0c;下载完解压ffmpeg.exe 程序运行 二、配置ffmpeg环境变量 添加成功后验证是否生效任意地方打开cmd窗口输入 ffmpeg 打印如下表示成功 三、node…