HAProxy 로드밸런서 설정
목차
######################################
# 1️⃣ HAProxy + Keepalived 설치
######################################
sudo apt update
sudo apt install -y haproxy keepalived
######################################
# 2️⃣ HAProxy 설정 (공통)
######################################
cat <<EOF | sudo tee /etc/haproxy/haproxy.cfg
global
log /dev/log local0
maxconn 2000
user haproxy
group haproxy
defaults
log global
mode tcp
option tcplog
timeout connect 10s
timeout client 1m
timeout server 1m
frontend k8s_apiserver
bind *:6443
default_backend k8s_masters
backend k8s_masters
balance roundrobin
option tcp-check
server master1 10.10.10.21:6443 check
server master2 10.10.10.22:6443 check
server master3 10.10.10.23:6443 check
EOF
sudo systemctl restart haproxy
sudo systemctl enable haproxy
######################################
# 3️⃣ Keepalived 설정 - master1 전용
######################################
ip link show
# ❗ NIC_NAME 변수는 실제 인터페이스 이름으로 교체 필요 (예: eth0, ens33)
NIC_NAME=\"eth0\"
cat <<EOF | sudo tee /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state MASTER
interface ${NIC_NAME}
virtual_router_id 51
priority 120
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
virtual_ipaddress {
10.10.10.100
}
}
EOF
sudo systemctl restart keepalived
sudo systemctl enable keepalived
######################################
# 4️⃣ Keepalived 설정 - master2 전용
######################################
# ❗ NIC_NAME 변수는 실제 인터페이스 이름으로 교체 필요 (예: eth0, ens33)
NIC_NAME=\"enp2s0\"
cat <<EOF | sudo tee /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state BACKUP
interface ${NIC_NAME}
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
virtual_ipaddress {
10.10.10.100
}
}
EOF
sudo systemctl restart keepalived
sudo systemctl enable keepalived
######################################
# ✅ VIP / 포트 / 헬스체크 확인
######################################
# VIP 확인
ip addr | grep 10.10.10.100
# 6443 포트 리슨 중인지 확인
sudo ss -ntlp | grep 6443
# API 서버 응답 확인 (API가 열려 있다면)
curl -k <https://10.10.10.100:6443/livez>
######################################
# 🚀 Kubernetes 마스터 초기화 명령어
######################################
sudo kubeadm init \\\\
--control-plane-endpoint=\"10.10.10.100:6443\" \\\\
--upload-certs \\\\
--pod-network-cidr=10.244.0.0/16