K3s cluster 구축하기(1)

·2025년 4월 19일

내가 운영하는 서비스에 비해 과한 CPU(Ryzen 7 7700)를 사용하고 있어 VM을 여러 개 생성하여 cluster를 구축할 수 있었다.
하지만 마음이 물리 서버 3대로 구축하라고 해서 어쩔 수 없이 2대의 미니 PC를 추가로 구매했다.

# ASUS NUC 14 Essential
  Intel N150 + 16GB
# ASUS NUC 14 Essential
  Intel N150 + 16GB
# NCASE M2
  Ryzen 7 7700 + 64GB ECC - Proxmox를 사용하여 VM 생성

Cluster를 구축하기 위해 사용한 서버는 위와 같다.

참고로 ASUS NUC에서 32GB를 사용하고 싶었지만 최대 16GB 밖에 인식을 못한다;

그리고 고가용성을 위해 각각의 서버를 Master node로 설정할 것이다.

Cluster Load Balancer

K3s Cluster의 서버 노드 앞에 외부 로드 밸런서를 설치

각 k3s 서버는 다음으로 구성

# /etc/rancher/k3s/config.yaml
token: lb-cluster-gd
tls-san: 10.0.0.10

3개의 Server 노드

  • 서버-1: 10.0.0.3
  • 서버-2: 10.0.0.4
  • 서버-3(VM): 10.0.0.5

2개의 LB 노드(Server 노드에서 설정)

  • 서버-1: 10.0.0.3
  • 서버-2: 10.0.0.4

3개의 Agent 노드

  • agent-1(VM): 10.0.0.7
  • agent-2(VM): 10.0.0.8
  • agent-3(VM): 10.0.0.9

서버-1, 서버-2에서 LB를 설정하기 위해 haproxy와 keepalived 설치

sudo apt update
sudo apt install -y haproxy keepalived

Server와 LB를 같은 노드에서 설정하다 보니 네트워크 이름을 알아야 함.

ip a

# 2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000

haproxy 설정

# /etc/haproxy/haproxy.cfg

frontend k3s-frontend
    bind *:6443 interface enp1s0
    mode tcp
    option tcplog
    default_backend k3s-backend

backend k3s-backend
    mode tcp
    option tcp-check
    balance roundrobin
    default-server inter 10s downinter 5s
    server server-1 10.0.0.3:6443 check
    server server-2 10.0.0.4:6443 check
    server server-3 10.0.0.5:6443 check

keepalived 설정

global_defs {
  enable_script_security
  script_user root
}

vrrp_script chk_haproxy {
    script 'killall -0 haproxy' # faster than pidof
    interval 2
}

vrrp_instance haproxy-vip {
    interface eth1
    state <STATE> # 서버-1 MASTER, 서버-2 BACKUP
    priority <PRIORITY> # 서버-1 200, 서버-2 100

    virtual_router_id 51

    virtual_ipaddress {
        10.0.0.10/24
    }

    track_script {
        chk_haproxy
    }
}

haproxy와 keepalived 다시 시작

systemctl restart haproxy
systemctl restart keepalived

Agent 노드에서 다음 명령을 실행하여 k3s를 설치하고 cluster에 가입

curl -sfL https://get.k3s.io | K3S_TOKEN=lb-cluster-gd sh -s - agent --server https://10.0.0.10:6443
profile

0개의 댓글