참고자료
https://kubernetes.io/docs/setup/independent/high-availability/#first-steps-for-both-methods
고가용성 Kubernetes 클러스터를 설정하는 두 가지 접근 방식이 존재한다.
내부 클러스터 : 추가적 마스터 인프라 필요, etcd 구성과 플레인 노드가 같은 위치에 존재해야 한다.
외부 etcd 클러스터 : 추가적 인프라가 필요, 수평적 노드구성과 etcd 가 분리되어 있어야 한다.
클러스터는 Kubernetes 버전 1.11 이상을 실행해야 한다.
두 가지 방법에 대한 다음 인프라 환경 구성이 필요하다.
Kubeadm의 최소 요구 사항을 충족시키는 3대의 마스터.
Kubeadm의 최소 요구사항을 충족시키는 3대의 노드.
클러스터간 전체 네트워크 연결.
클러스터간 모든 SSH 액세스.
클러스트간 SUDU 권한.
외부 Etcd 클러스터 구성은 별도 3대의 서버가 추가로 필요하다.
메인 장치에서 시스템의 다른 모든 노드에 액세스 할 수있는 ssh-agent를 활성화
# eval $(ssh-agent) |
SSH ID를 세션에 추가.
# ssh-add ~/.ssh/path_to_private_key |
노드 간 SSH를 사용하여 연결이 올바르게 작동하는지 체크
어떤 노드로 SSH 할 때 -A 플래그를 추가해야함
# ssh -A 10.0.0.7 |
모든 노드에서 sudo를 사용할 때 SSH 전달이 작동하도록 환경을 보존.
# sudo -E -s |
ssh-keygen 사용하기
아래와 같이 입력한다. -t rsa는 rsa라는 암호화 방식으로 키를 생성한다는 의미다.
$ ssh-keygen -t rsa Generating public/private rsa key pair |
ssh 확인
ls -al ~/.ssh/ |
authorized_keys 파일은 없을수도 있다.
각 파일에 대한 설명은 아래와 같다.
| id_rsa | private key, 절대로 타인에게 노출되면 안된다. |
| id_rsa.pub | public key, 접속하려는 리모트 머신의 authorized_keys에 입력한다. |
| authorized_keys | 리모트 머신의 .ssh 디렉토리 아래에 위치하면서 id_rsa.pub 키의 값을 저장한다. 자세한 내용은 다음 단락을 참조 |
.ssh 디렉토리는 중요한 정보가 담겨있으므로 퍼미션 설정이 필요하다.
chmod 700 ~/.ssh chmod 600 ~/.ssh/id_rsa chmod 644 ~/.ssh/id_rsa.pub chmod 644 ~/.ssh/authorized_keys chmod 644 ~/.ssh/known_hosts |
SSH Server의 authorized_keys 의 내용이 SSH Client의 id_rsa.pub 파일과 같아야 한다.
그래서 ssh 접속을 할 때 id_rsa 파일과 authorized_keys 파일의 내용을 비교 할 수 있다. 일반적으로 SCP를 사용한다
일반적으로 SCP를 사용한다. SCP는 파일을 전송하는 프로그램인데, 아래와 같은 형식을 갖는다.
scp $HOME/.ssh/id_rsa 리모트 머신의 아이디@리모트 머신의 호스트 주소:저장할 파일
위의 형식에 따라서 로컬 머신의 id_rsa.pub 파일을 리모트 머신의 홈디렉토리로 전송해보자. 아래는 SSH Client가 설치된 로컬 머신에서 실행하는 명령이다.
scp $HOME/.ssh/id_rsa.pub egoing@egoing.net:id_rsa.pub |
이제 원격 머신에서 전송한 id_rsa.pub 파일을 authorized_keys 파일에 추가해보자.
아래의 명령에서 cat는 뒤에 따라오는 파일의 내용을 화면에 출력하는 것이고, >> 는 cat이 출력한 내용을 authorized_keys 파일에 추가하는 것이다.
내용을 교체하는 것이 아니라 추가하는 것이라는 점에 주의하자.
만약 리모트 머신으로 접속하는 여러개의 로컬 머신이 있다면 각각의 로컬 머신의 id_ras.pub 파일을 authorized_keys에 추가해주면 된다.
cat $HOME/id_rsa.pub >> $HOME/.ssh/authorized_keys |
로드 밸런서에는 많은 구성이 있으며, 다음은 그중 하나의 옵션사항이다.
DNS로 해석되는 이름을 가진 kube-apiserver로드 밸런서 생성.
(클라우드 환경에서는 TCP forwarding로드 밸런서 뒤에 컨트롤 플레인 노드를 배치)
로드 밸런서는 트래픽을 대상 목록의 정상적인 모든 컨트롤 플레인 노드에 배포.
apiserver의 상태 검사는 kube-apiserver가 수신하는 포트의 TCP 검사 (기본값 : 6443).
로드 밸런서는 apiserver 포트의 모든 제어 플레인 노드와 통신 할 수 있어야 하며,
수신 포트에서 들어오는 트래픽을 허용해야한다.
SSH 간편 설정
$ rm -rf /root/.ssh/* $ ssh <master ip 1> pwd $ ssh <master ip 2> rm -rf /root/.ssh/* $ ssh <master ip 3> rm -rf /root/.ssh/* $ ssh <master ip 2> mkdir -p /root/.ssh/ $ ssh <master ip 3> mkdir -p /root/.ssh/ $ scp /root/.ssh/known_hosts root@<master ip 2>:/root/.ssh/ $ scp /root/.ssh/known_hosts root@<master ip 3>:/root/.ssh/ $ ssh-keygen -t rsa -P '' -f /root/.ssh/id_rsa $ cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys $ scp /root/.ssh/authorized_keys root@<master ip 2>:/root/.ssh/ Master 2 $ ssh-keygen -t rsa -P '' -f /root/.ssh/id_rsa $ cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys $ scp /root/.ssh/authorized_keys root@<master ip 3>:/root/.ssh/ Master 3 $ ssh-keygen -t rsa -P '' -f /root/.ssh/id_rsa $ cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys $ scp /root/.ssh/authorized_keys root@<master ip 1>:/root/.ssh/ $ scp /root/.ssh/authorized_keys root@<master ip 2>:/root/.ssh/ # ssh -A <master ip 1> # ssh -A <master ip 2> # ssh -A <master ip 3> |
결과)
Last login: Mon Oct 1 12:35:56 2018
모든 master node에 haproxy 와 keepalived 설치 (haproxy는 1.5 버전 이상부터 SSL 지원)
# yum install haproxy # haproxy -v # yum install keepalived |
모든 master node에 chkconfig 설정 진행 (부팅시 자동 실행 on 설정)
아래 명령어는 구버전 명령어이며 실행은 되지만 최근 명령어 갱신이 필요하다.
# chkconfig haproxy on && chkconfig keepalived on && chkconfig | egrep 'haproxy|keepalived' |
모든 master ndoe에 non-local Virtual IPs binding
# echo "net.ipv4.ip_nonlocal_bind = 1" >> /etc/sysctl.conf && sysctl -p |
결과)
net.ipv4.tcp_max_syn_backlog = 4096
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.all.forwarding = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.ip_nonlocal_bind = 1
# cd /etc/keepalived //원본 백업 # mv keepalived.conf keepalived.conf.org |
Master Node 1 설정
# vi /etc/keepalived/keepalived.conf
global_defs {
notification_email {
test@test.com
test2 @test.com
}
notification_email_from lb1@test.com
smtp_server localhost
smtp_connect_timeout 30
}
# haproxy 활성화 체크
vrrp_script chk_haproxy {
script "killall -0 haproxy"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER
interface eth0 # 사용할 인터페이스 설정 (ifconfig 로확인 가능)
virtual_router_id 51 # Master Node 3대가 모두 같은 값이어야 한다. (최대 255까지설정가능)
priority 101 # 우선순위 설정 (최대 255까지 설정가능)
advert_int 1 # VRRP패킷 송신 간격 설정 (초단위로 지정)
authentication {
auth_type PASS # 평문 인증 설정
auth_pass 1111 # 인증을 위한 키 (All Master 동일값 설정)
}
virtual_ipaddress {
000.000.000.000 # VIP설정
}
track_script {
chk_haproxy
}
} |
Master Node 2 설정
※ Master Node 2 에서는 Master Node 1 과 동일하게 구성하되 priority와 라우터 아이디만 다르게 설정 한다.
# vi /etc/keepalived/keepalived.conf
global_defs {
notification_email {
test@test.com
test2 @test.com
}
notification_email_from lb1@test.com
smtp_server localhost
smtp_connect_timeout 30
}
# haproxy 활성화 체크
vrrp_script chk_haproxy {
script "killall -0 haproxy"
interval 2
weight 2
}
vrrp_instance VI_2 {
state BACKUP
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
000.000.000.000
}
track_script {
chk_haproxy
}
} |
Master Node 3 설정
※ Master Node 3 에서는 Master Node 1,2 와 동일하게 구성하되 priority와 라우터 아이디만 다르게 설정 한다.
# vi /etc/keepalived/keepalived.conf
global_defs {
notification_email {
test@test.com
test2 @test.com
}
notification_email_from lb1@test.com
smtp_server localhost
smtp_connect_timeout 30
}
# haproxy 활성화 체크
vrrp_script chk_haproxy {
script "killall -0 haproxy"
interval 2
weight 2
}
vrrp_instance VI_3 {
state BACKUP
interface eth0
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
000.000.000.000
}
track_script {
chk_haproxy
}
} |
# systemctl enable keepalived # systemctl start keepalived |
결과)
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; enabled; vendor preset: disabled)
Active: active (running) since 월 2018-10-01 14:11:44 KST; 7s ago
Process: 26099 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 26100 (keepalived)
Tasks: 3
Memory: 1.6M
CGroup: /system.slice/keepalived.service
├─26100 /usr/sbin/keepalived -D
├─26101 /usr/sbin/keepalived -D
└─26102 /usr/sbin/keepalived -D
10월 01 14:11:46 sb-k8s-MASTER-STBY77 Keepalived_vrrp[26102]: Sending gratuitous ARP on eth0 for 222.231.50.9
10월 01 14:11:46 sb-k8s-MASTER-STBY77 Keepalived_vrrp[26102]: /usr/bin/killall -0 haproxy exited with status 1
10월 01 14:11:48 sb-k8s-MASTER-STBY77 Keepalived_vrrp[26102]: /usr/bin/killall -0 haproxy exited with status 1
10월 01 14:11:50 sb-k8s-MASTER-STBY77 Keepalived_vrrp[26102]: /usr/bin/killall -0 haproxy exited with status 1
10월 01 14:11:51 sb-k8s-MASTER-STBY77 Keepalived_vrrp[26102]: Sending gratuitous ARP on eth0 for 222.231.50.9
10월 01 14:11:51 sb-k8s-MASTER-STBY77 Keepalived_vrrp[26102]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 22....50.9
10월 01 14:11:51 sb-k8s-MASTER-STBY77 Keepalived_vrrp[26102]: Sending gratuitous ARP on eth0 for 222.231.50.9
10월 01 14:11:51 sb-k8s-MASTER-STBY77 Keepalived_vrrp[26102]: Sending gratuitous ARP on eth0 for 222.231.50.9
10월 01 14:11:51 sb-k8s-MASTER-STBY77 Keepalived_vrrp[26102]: Sending gratuitous ARP on eth0 for 222.231.50.9
10월 01 14:11:51 sb-k8s-MASTER-STBY77 Keepalived_vrrp[26102]: Sending gratuitous ARP on eth0 for 222.231.50.9
Hint: Some lines were ellipsized, use -l to show in full.