首页 > 系统相关 >centos7.9安装kubernetes1.27.4版本

centos7.9安装kubernetes1.27.4版本

时间:2023-11-09 22:15:32浏览次数:34  
标签:etc -- 32m echo centos7.9 版本 kubernetes1.27 cri 0m

. /etc/os-release

color () {
    RES_COL=60
    MOVE_TO_COL="echo -en \\033[${RES_COL}G"
    SETCOLOR_SUCCESS="echo -en \\033[1;32m"
    SETCOLOR_FAILURE="echo -en \\033[1;31m"
    SETCOLOR_WARNING="echo -en \\033[1;33m"
    SETCOLOR_NORMAL="echo -en \E[0m"
    echo -n "$1" && $MOVE_TO_COL
    echo -n "["
    if [ $2 = "success" -o $2 = "0" ] ;then
        ${SETCOLOR_SUCCESS}
        echo -n $"  OK  "
    elif [ $2 = "failure" -o $2 = "1"  ] ;then
        ${SETCOLOR_FAILURE}
        echo -n $"FAILED"
    else
        ${SETCOLOR_WARNING}
        echo -n $"WARNING"
    fi
    ${SETCOLOR_NORMAL}
    echo -n "]"
    echo
}

echo -e "\e[1;32m安装kubernetes1.27.4版本\e[0m"
#echo -e "\e[1;32m配置yum源\e[0m"
#[ ! -d /data/bak ] && mkdir -p /data/bak

#判断文件夹是否有文件
#    if [ "`ls -A /etc/yum.repos.d/`" != "" ];then
#        mv /etc/yum.repos.d/*  /data/bak
#    else
#        echo ""
#    fi

#[ -d /mnt/cdrom ] || mkdir /mnt/cdrom
#mount /dev/sr0 /mnt/cdrom
    

#cat > /etc/yum.repos.d/base.repo <<EOF
#[base]
#name=CentOS
#baseurl=file:///mnt/cdrom/BaseOS
#        https://mirror.tuna.tsinghua.edu.cn/centos/\$releasever/os/\$basearch/
#        https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch/
#        https://mirrors.cloud.tencent.com/centos/\$releasever/os/\$basearch/
#        https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
#gpgcheck=0

#[extras]
#name=extras
#baseurl=https://mirror.tuna.tsinghua.edu.cn/centos/\$releasever/extras/\$basearch
#        https://mirrors.huaweicloud.com/centos/\$releasever/extras/\$basearch
#        https://mirrors.cloud.tencent.com/centos/\$releasever/extras/\$basearch
#        https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch
#       
#gpgcheck=0
#enabled=1


#[epel]
#name=EPEL
#baseurl=https://mirror.tuna.tsinghua.edu.cn/epel/\$releasever/\$basearch
#        https://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch/
#        https://mirrors.huaweicloud.com/epel/\$releasever/\$basearch
#        https://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch
#        http://mirrors.aliyun.com/epel/\$releasever/\$basearch
#gpgcheck=0
#enabled=1
#EOF
#    yum clean all
#    yum makecache
#    yum repolist



#cat >> /etc/fstab << EOF
#/dev/sr0               /mnt/cdrom              iso9660  defaults        0 0
#EOF

#[ $? -eq 0 ] && color 已配置 0 || { color 写入失败 1;exit; }

echo -e "\e[1;35m==========================================================================================================================================================================================================================================\e[0m"
echo -e "\e[1;32m关闭swap\e[0m"
swapoff -a
sed -i '/swap/s/^/#/' /etc/fstab
[ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1



#echo -e "\e[1;32m关闭防火墙\e[0m"
#systemctl disable --now firewalld

#echo -e "\e[1;32m时间同步\e[0m"
#yum -y install ntpdate
#ntpdate time2.aliyun.com
# 加入到crontab
#*/5 * * * * /usr/sbin/ntpdate time2.aliyun.com

echo -e "\e[1;35m==========================================================================================================================================================================================================================================\e[0m"
echo -e "\e[1;32m修改主机名\e[0m"
hostnamectl set-hostname k8s-master01



cat <<EOF >> /etc/hosts
10.0.0.21 k8s-master01
10.0.0.22 k8s-node01
EOF

echo -e "\e[1;35m==========================================================================================================================================================================================================================================\e[0m"
echo -e "\e[1;32m修改Linux内核参数,添加网桥过滤器和地址转发功能\e[0m"
cat >> /etc/sysctl.d/kubernetes.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF


modprobe br_netfilter
sysctl -p /etc/sysctl.d/kubernetes.conf
[ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1



echo -e "\e[1;35m==========================================================================================================================================================================================================================================\e[0m"
echo -e "\e[1;32m配置ipvs功能\e[0m"
yum -y install ipset ipvsadm
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4  
EOF
chmod +x /etc/sysconfig/modules/ipvs.modules
/etc/sysconfig/modules/ipvs.modules

[ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1


echo -e "\e[1;35m==========================================================================================================================================================================================================================================\e[0m"
echo -e "\e[1;32m安装Docker容器\e[0m"
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache
yum install -y yum-utils


yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce-20.10.6 docker-ce-cli-20.10.6 -y
mkdir /etc/docker

cat <<EOF > /etc/docker/daemon.json
{
"registry-mirrors": [
 "https://docker.mirrors.ustc.edu.cn",
 "https://hub-mirror.c.163.com",
 "https://reg-mirror.qiniu.com",
 "https://registry.docker-cn.com"
],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "200m"
},
"storage-driver": "overlay2"
}
EOF
systemctl enable --now docker
[ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1


echo -e "\e[1;35m==========================================================================================================================================================================================================================================\e[0m"
echo -e "\e[1;32m安装cri-dockerd-0.3.1插件\e[0m"

if [ -e cri-dockerd-0.3.1-3.el7.x86_64.rpm ];then
    echo -e "\e[1;35m 文件已存在,开始安装\e[0m"
else
    echo -e "\e[1;31m开始下载\e[0m"
    wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.1/cri-dockerd-0.3.1-3.el7.x86_64.rpm
    if [ $? -eq 0 ];then
        echo -e "\e[1;32m下载成功\e[0m"
    else
        echo -e "\e[1;32m下载失败,检查下载链接\e[0m"
        exit
    fi
fi
#wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.1/cri-dockerd-0.3.1-3.el7.x86_64.rpm
rpm -ivh cri-dockerd-0.3.1-3.el7.x86_64.rpm
sed -i "s/^ExecStart/#&/" /usr/lib/systemd/system/cri-docker.service
sed -i '10iExecStart=/usr/bin/cri-dockerd --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.7' /usr/lib/systemd/system/cri-docker.service
systemctl daemon-reload && systemctl restart docker cri-docker.socket cri-docker

[ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1



echo -e "\e[1;35m==========================================================================================================================================================================================================================================\e[0m"
echo -e "\e[1;32m配置国内yum源,安装 kubeadm、kubelet、kubectl\e[0m"


cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
EOF


yum install -y kubelet-1.27.4 kubeadm-1.27.4 kubectl-1.27.4
systemctl enable kubelet.service --now

[ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1


echo -e "\e[1;35m==========================================================================================================================================================================================================================================\e[0m"
echo -e "\e[1;32m安装runc-1.1.10\e[0m"


if [ -e runc.amd64 ];then
    echo -e "\e[1;35m 文件已存在,开始安装\e[0m"
else
    echo -e "\e[1;31m开始下载\e[0m"
    wget https://github.com/opencontainers/runc/releases/download/v1.1.10/runc.amd64
    if [ $? -eq 0 ];then
        echo -e "\e[1;32m下载成功\e[0m"
    else
        echo -e "\e[1;32m下载失败,检查下载链接\e[0m"
        exit
    fi
fi

sudo install -m 755 runc.amd64  /usr/local/bin/runc
[ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
runc -v

echo -e "\e[1;35m==========================================================================================================================================================================================================================================\e[0m"
echo -e "\e[1;32m初始化\e[0m"
kubeadm init --node-name=k8s-master01 --image-repository=registry.aliyuncs.com/google_containers --cri-socket=unix:///var/run/cri-dockerd.sock --apiserver-advertise-address=10.0.0.21 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12

exec bash

}
https://github.com/flannel-io/flannel/releases/download/v0.22.0/kube-flannel.yml
[root@localhost~]#vim kube-flannel.yml
- args:
        - --ip-masq
        - --kube-subnet-mgr
        - --iface=ens33 #添加
[root@localhost~]#kubectl apply -f kube-flannel.yml
node节点加入
echo -e "\e[1;32mkubeadm join 结尾加上一下命令\e[0m"
echo "--cri-socket unix:///var/run/cri-dockerd.sock"
scp /etc/kubernetes/admin.conf 10.0.0.22:/etc/kubernetes/
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >>  ~/.bash_profile # 不要忘记将admin.conf加入环境变量,这里直接使用永久生效。
source ~/.bash_profile

 

标签:etc,--,32m,echo,centos7.9,版本,kubernetes1.27,cri,0m
From: https://www.cnblogs.com/smlience/p/17822979.html

相关文章

  • python升级到3.12版本, 开发模式安装包, 在vscode下Pylance无法解析的问题处理
    问题描述在python3.11版本下开发python库,为方便调测,使用开发模式安装包.使用如下命令:pipinstall-e.其中-e参数表示开发模式下安装python包,它并没有把包相关文件拷贝到site-packages目录,而是创建一个链接指向当前的开发库.这样,当自己开发的包修改后会立即生效,......
  • Glibc高版本堆利用方法总结
    截止到目前,主要总结在2.35~2.37之间仍然残存的堆利用手法。可以在Bilibili上观看视频进行学习,或者在Youtube上观看视频进行学习。进入到glibc-2.31之后,很多原有的堆利用方法就失效,因此glibc给堆分配机制陆陆续续打上了很多patch,目前来看,与堆利用有关的patch有:tcachebin堆指......
  • win版本 mysql5.7 解压安装流程
    win版本mysql5.7解压安装流程https://dev.mysql.com/downloads/mysql/5.7.html#downloads1、添加系统变量变量名:MYSQL_HOME变量值:D:\ProgramData\mysql-5.7.44-winx642、编辑my.inimy.ini[mysqld]basedir=D:\ProgramData\mysql-5.7.44-winx64datadir=D:\ProgramData\mysql-5.7.......
  • PostgreSQL DLL更新版本
    1.材料PostgreSQL10.23x86-32https://www.postgresql.org/download/windows/ 2.基本操作替换程序里的pgsql/include,lib文件,更换可执行程序路径下的libpq.dll3.问题复制该dll进去后,继续报错4.解决方案将pgsql/bin文件下的dll文件复制进去后发现可以运行,排查后发现缺少libico......
  • C# 程序兼容同一个dll的不同版本
    当程序多个dll引用同一个dll的不同版本时,程序启动会报错,此时需要在启动程序集的App.config下增加以下配置以log4为例子<configuration><startup><supportedRuntimeversion="v4.0"sku=".NETFramework,Version=v4.5"/></startup><runtime>......
  • 用 arpl-i18n安装群晖系统 ,DSM 7.0版本不能降级到6.2版本
    说一个案例:值得借鉴(以网友测试的机器机型为案例),希望大家不要走弯路我的VM虚拟机用多种型号安装了DSM7.0,然后在arpl-i18n配置中设置了降级,并且选择6.2版本编译,重启以后SynologyAssistant搜索显示可转移,安装DSM_DS1621xs+_25556.pat重启以后,SynologyAssistant搜索仍然是可转......
  • 高版本SqlServer数据库还原到低版本数据库
    需求:SqlServer2017还原到SqlServer2008数据库直接备份还原与拷贝文件还原均无法成功解决方案:1、修改兼容性,再备份数据库,还原(推荐)2、导出脚本、导入(即数据同步),大数据量不建议使用该方法......
  • openEuler22.03操作系统 Linux内核Kernel 5.10 应该选择哪个版本的mysql安装包下载?
    对于openEuler22.03操作系统和Linux内核Kernel5.10,你应该选择与该操作系统和内核版本兼容的MySQL安装包进行安装。在确定适合的MySQL版本时,你可以考虑以下几点:MySQL官方支持:查看MySQL官方网站中的文档或支持页面,确认其是否支持openEuler22.03操作系统和Kernel5.......
  • 升级k8s版本废弃docker引擎
    1、废弃docker引擎systemctlenablekubeletsystemctlenablecontainerdcat<<EOF|sudotee/etc/modules-load.d/k8s.confoverlaybr_netfilterEOFcat/etc/modules-load.d/k8s.confmodprobeoverlaymodprobebr_netfiltermv/etc/sysctl.d/k8s.conf/etc......
  • 软件测试|Chrome 115之后的版本,如何更新driver?
    问题描述前两天在运行一个web自动化测试脚本时,报了如下的错误,ThisversionofChromeDriveronlysupportsChromeversion113Currentbrowserversionis115.0.5790.110withbinary,如下图所示:该报错提示我,当前的driver只支持113版本的Chrome浏览器,但是我的Chrome已经自动......