#!/bin/bash
systemctl stop firewalld && systemctl disable firewalld
setenforce 0
sed -ri 's#(SELINUX=).*#\1disabled#' /etc/selinux/config
swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

cat <<EOF >> /etc/hosts
10.10.10.180 master
10.10.10.181 node1
10.10.10.182 node2
EOF

yum install ntpdate -y && ntpdate ntp.aliyun.com
iptables -F && iptables -X && iptables -F -t nat && iptables -X -t nat && iptables -P FORWARD ACCEPT

cat <<EOF > /etc/sysctl.d/k8s.conf 
net.bridge.bridge-nf-call-ip6tables = 1 
net.bridge.bridge-nf-call-iptables = 1 
EOF

sysctl --system

yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum install -y docker-ce-3:24.0.2-1.el7.x86_64

cat <<EOF > /etc/docker/daemon.json
{
     "registry-mirrors": ["https://jbw52uwf.mirror.aliyuncs.com"],
    "exec-opts": ["native.cgroupdriver=systemd"]
} 
EOF

systemctl restart docker && systemctl enable docker

rpm -ivh cri-dockerd-0.3.1-3.el7.x86_64.rpm

sed -i 's|^ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd://|ExecStart=/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 enable --now cri-docker

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
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

yum install -y kubelet-1.27.1 kubeadm-1.27.1 kubectl-1.27.1

systemctl enable --now kubelet

crictl config runtime-endpoint /run/containerd/containerd.sock
kubeadm version 
echo "You did it !"
echo "You win !"
