sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config && systemctl stop firewalld && systemctl disable firewalld
### Cấu hình file hosts
cat <<EOF > /etc/hosts
172.16.1.240 node1
172.16.1.241 node2
172.16.1.242 node3
172.16.1.243 node4
172.16.1.244 node5
EOF
### Vô hiệu hóa swap
swapoff -a && sed -i '/swap/d' /etc/fstab
### Cài đặt Docker
#### Bước 1: Cài đặt công cụ hỗ trợ
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
#### Bước 2: Thêm nguồn cài đặt
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#### Bước 3: Cấu hình mirror
sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
#### Bước 4: Cập nhật và cài đặt
sudo yum makecache fast
sudo yum -y install docker-ce
#### Bước 5: Khởi động dịch vụ
systemctl restart docker
systemctl enable docker --now
### Cấu hình mirror Docker
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://frz7i079.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
### Cấu hình kernel
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
### Cài đặt Kubernetes
#### Kiểm tra phiên bản
yum list --showduplicates kubeadm --disableexcludes=kubernetes
#### Cấu hình kho lưu trữ
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=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
#### Cài đặt thành phần
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet --now && systemctl start kubelet
### Chuẩn bị môi trường
docker pull registry.aliyuncs.com/google_containers/coredns:1.8.4
docker tag registry.aliyuncs.com/google_containers/coredns:1.8.4 registry.aliyuncs.com/google_containers/coredns:v1.8.4
docker rmi registry.aliyuncs.com/google_containers/coredns:1.8.4
### Khởi tạo cụm
kubeadm init --image-repository registry.aliyuncs.com/google_containers --kubernetes-version=v1.22.0 --pod-network-cidr=10.244.0.0/16
### Cài đặt mạng
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
### Kiểm tra trạng thái
kubectl get nodes
### Thêm node vào cụm
kubeadm token create --print-join-command