ubuntu2004一键部署kubernetes1.22.7

. /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
}
install_kubernetes_ubuntu_master1(){

echo -e "\e[1;32m更换apt源\e[0m"
cat > /etc/apt/sources.list <<EOF
deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

EOF


echo -e "\e[1;32m关闭swap\e[0m"
swapoff -a
echo -e "\e[1;32m关闭防火墙\e[0m"
ufw disable
sudo apt-get update


echo -e "\e[1;32m安装必要的一些系统工具\e[0m"

sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common


echo -e "\e[1;32m更新并安装Docker-io\e[0m"

apt update && apt -y install docker.io
[ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1



echo -e "\e[1;32m配置docker镜像加速\e[0m"

cat >  /etc/docker/daemon.json <<EOF
{
"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
[ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1

echo -e "\e[1;32m加载docker配置并重启服务\e[0m"
systemctl daemon-reload && systemctl restart docker.service



echo -e "\e[1;32m在各个节点安装工具kubelet、kubeadm和kubectl\e[0m"

curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -

cat  >/etc/apt/sources.list.d/kubernetes.list <<EOF
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF


apt-get update && apt install -y  kubeadm=1.22.7-00 kubelet=1.22.7-00 kubectl=1.22.7-00

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

cat > /etc/default/kubelet <<EOF
KUBELET_EXTRA_ARGS="--fail-swap-on=false"
EOF

systemctl daemon-reload && systemctl restart kubelet





echo -e "\e[1;32m master节点执行\e[0m\n"
echo -e "\e[1;31mkubeadm init --kubernetes-version=v1.22.7 --image-repository=registry.aliyuncs.com/google_containers --pod-network-cidr=10.24.0.0/16 --ignore-preflight-errors=Swap\e[0m"

echo -e "\e[1;32mcurl https://projectcalico.docs.tigera.io/archive/v3.24/manifests/calico.yaml -O\e[0m"
echo -e "\e[1;31mkubectl apply -f calico.yaml\e[0m"


}



reset_kubenetes(){
    kubeadm reset
    rm -rf /etc/kubernetes/  /var/lib/kubelet/
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值