亲测有效-需要centos7.8以上,全程五分钟
话不多说,直接上脚本
一、脚本说明
二、后续操作
脚本运行完后,将生成的key粘贴到node加入集群
查看容器启动状态
最后附上脚本和安装包链接
链接:https://pan.baidu.com/s/18WAEzLTebJ74yqrLecPfIA
提取码:fo9x
--来自百度网盘超级会员V4的分享
install_master_k8s-v1.23.6.sh
[root@bogon k8starget]# cat install_master_k8s-v1.23.6.sh
#!/bin/bash
##############################################################
# File Name: install_k8s-v1.23.6.sh
# Version: V1.0
# Author: junwang
# Organization:
# Created Time : 2023-04-4 17:12:54
# Description:
##############################################################
masterip=10.130.212.203
DockerDriver(){
mkdir -p /etc/docker/
cat >/etc/docker/daemon.json<<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
}
LoadImages(){
# load k8s all images
for i in `ls -l ./k8simages|awk 'NR == 1 {next} {print $NF}'` ;do docker load -i ./k8simages/$i ;done
}
InstallDocker(){
# install docker 20.10.11
version_num=`docker version|egrep "Version"|head -n 1|awk '{print $NF}'`
if [ $version_num != '20.10.11' ]
then
echo "######## 已安装其他版本docker 请先卸载 #########"
return 1
elif [ $version_num = '20.10.11' ]
then
#echo "######## 已安装docker 20.10.11 ################"
DockerDriver
systemctl daemon-reload
systemctl restart docker
else
echo "############ 开始安装docker 20.10.11 ################"
cp ./docker/* /usr/bin/
cat >>/etc/systemd/system/docker.service<<EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --selinux-enabled=false
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
EOF
chmod +x /etc/systemd/system/docker.service
DockerDriver
systemctl daemon-reload
systemctl start docker
fi
if [ `systemctl status docker|grep running|wc -l` -ge 1 ]
then
systemctl enable docker
echo "############## Docker installation successful ###################"
LoadImages
return 0
else
echo "################ Docker startup or installation failure ################"
return 3
fi
}
InitEnv(){
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab
cat <<EOF | tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
modprobe br_netfilter
modprobe overlay
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
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
/bin/bash /etc/sysconfig/modules/ipvs.modules
}
#InstallDocker
InstallKube(){
yum install -y ./k8srpm/*.rpm
if [ $? -ne 0 ]
then
echo "############## kube installation failurfe ################"
return 0
else
InitEnv
systemctl enable kubelet --now
echo "########### kube installation successful ################"
return 0
fi
}
InitK8s(){
sed -i 's#10.130.212.205#'$masterip'#g' ./kubeadm-config.yaml
kubeadm init --config=./kubeadm-config.yaml --upload-certs
if [ $? -eq 0 ]
then
rm -rf /root/.kube/
mkdir /root/.kube/
cp -i /etc/kubernetes/admin.conf /root/.kube/config
echo "############# k8s Cluster installation successful ###################"
return 0
else
echo "############# k8s Cluster installation failurfe ####################"
return 1
fi
}
Installcalico(){
kubectl create -f ./calico/tigera-operator.yaml
sleep 3
kubectl create -f ./calico/calico-custom-resources.yaml
sleep 3
kubectl create -f ./kuboard-v3.yaml
}
main(){
InstallDocker
if [ $? -eq 0 ]
then
InstallKube && InitK8s && Installcalico
echo "http://your-node-ip-address:30080 admin/Kuboard123"
fi
}
main
install_node_k8s-v1.23.6.sh
[root@bogon k8starget]# cat install_node_k8s-v1.23.6.sh
#!/bin/bash
##############################################################
# File Name: install_k8s-v1.23.6.sh
# Version: V1.0
# Author: junwang
# Organization:
# Created Time : 2023-04-4 17:12:54
# Description:
##############################################################
DockerDriver(){
mkdir -p /etc/docker/
cat >/etc/docker/daemon.json<<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
}
LoadImages(){
# load k8s all images
for i in `ls -l ./k8simages|awk 'NR == 1 {next} {print $NF}'` ;do docker load -i ./k8simages/$i ;done
}
InstallDocker(){
# install docker 20.10.11
version_num=`docker version|egrep "Version"|head -n 1|awk '{print $NF}'`
if [ $version_num != '20.10.11' ]
then
echo "######## 已安装其他版本docker 请先卸载 #########"
return 1
elif [ $version_num = '20.10.11' ]
then
#echo "######## 已安装docker 20.10.11 ################"
DockerDriver
systemctl daemon-reload
systemctl restart docker
else
echo "############ 开始安装docker 20.10.11 ################"
cp ./docker/* /usr/bin/
cat >>/etc/systemd/system/docker.service<<EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --selinux-enabled=false
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
EOF
chmod +x /etc/systemd/system/docker.service
DockerDriver
systemctl daemon-reload
systemctl start docker
fi
if [ `systemctl status docker|grep running|wc -l` -ge 1 ]
then
systemctl enable docker
echo "############## Docker installation successful ###################"
LoadImages
return 0
else
echo "################ Docker startup or installation failure ################"
return 3
fi
}
InitEnv(){
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab
cat <<EOF | tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
modprobe br_netfilter
modprobe overlay
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
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
/bin/bash /etc/sysconfig/modules/ipvs.modules
}
InstallKube(){
yum install -y ./k8srpm/*.rpm
if [ $? -ne 0 ]
then
echo "############## kube installation failurfe ################"
return 0
else
InitEnv
systemctl enable kubelet --now
echo "########### kube installation successful ################"
return 0
fi
}
main(){
InstallDocker
if [ $? -eq 0 ]
then
InstallKube
fi
}
main