Để cài đặt một cụm Kubernetes v1.30 có khả năng sẵn sàng cao, hãy làm theo các bước sau:
Bước 1: Thay đổi tên máy chủ trên tất cả các nút
Sử dụng lệnh sau để thay đổi tên máy chủ:
hostnamectl set-hostname [tên-máy-chủ]
Bước 2: Cấu hình tệp hosts trên tất cả các nút
Thêm các mục sau vào tệp /etc/hosts:
192.168.88.5 master1
192.168.88.6 master2
192.168.88.7 master3
192.168.88.8 node1
Bước 3: Tắt tường lửa trên tất cả các nút
Tắt và vô hiệu hóa dịch vụ firewalld:
systemctl stop firewalld && systemctl disable firewalld
Bước 4: Tắt SELinux trên tất cả các nút
Sửa đổi tập tin cấu hình SELINUX:
sed -i 's/^ *SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
Bước 5: Tắt phân vùng swap và khởi động lại máy chủ
Sửa đổi tệp /etc/fstab để bình luận các dòng liên quan đến swap:
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
Bước 6: Đồng bộ thời gian trên tất cả các nút
Cài đặt và cấu hình dịch vụ chrony:
yum -y install chrony && systemctl enable chronyd && systemctl start chronyd
timedatectl set-timezone Asia/Ho_Chi_Minh && chronyc -a makestep
Bước 7: Cài đặt dịch vụ ipset trên tất cả các nút
Cài đặt các gói cần thiết:
yum -y install ipvsadm ipset sysstat conntrack libseccomp
Bước 8: Điều chỉnh kernel cho phép chuyển tiếp lưu lượng IPv4 qua bridge
Tạo tệp /etc/sysctl.d/k8s.conf với nội dung sau:
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1
Làm cho các thay đổi có hiệu lực ngay lập tức:
sysctl -p /etc/sysctl.d/k8s.conf
Bước 9: Kích hoạt các mô-đun ipvs
Tạo tệp /etc/sysconfig/modules/ipvs.modules với nội dung sau:
#!/bin/sh
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
Chạy script để áp dụng thay đổi:
chmod +x /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4
Bước 10: Cài đặt HAProxy và Keepalived trên các nút master
Cài đặt các gói cần thiết:
yum -y install keepalived haproxy
Bước 11: Cấu hình Keepalived trên các nút master
Ví dụ cấu hình tệp /etc/keepalived/keepalived.conf cho master1 (trạng thái MASTER):
global_defs {
router_id LVS_DEVEL
script_user root
enable_script_security
}
vrrp_script check_apiserver {
script "/etc/keepalived/check_apiserver.sh"
interval 3
weight -2
fall 10
rise 2
}
vrrp_instance VI_1 {
state MASTER
interface eno16777736
virtual_router_id 51
priority 100
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.88.3
}
track_script {
check_apiserver
}
}
Ví dụ cấu hình tệp /etc/keepalived/keepalived.conf cho master2 (trạng thái BACKUP):
global_defs {
router_id LVS_DEVEL
script_user root
enable_script_security
}
vrrp_script check_apiserver {
script "/etc/keepalived/check_apiserver.sh"
interval 3
weight -2
fall 10
rise 2
}
vrrp_instance VI_1 {
state BACKUP
interface eno16777736
virtual_router_id 51
priority 90
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.88.3
}
track_script {
check_apiserver
}
}
Lặp lại quá trình tương tự cho master3.