본문 바로가기

Docker & Kubenetes

Kubernetes Highly Available Clusters - 고가용성(HA) 클러스터 구축

고가용성(HA) 클러스터

  • 컨트롤러와 스케쥴러, DNS는 대표 하나만 동작
  • API는 병렬 처리
  • etcd는 어느 한쪽에서 데이터 수정이 발생하면 동기화

고가용성 기본 구성은 마스터 노드 3개이며, 홀수 단위로 구성한다.

3개의 마스터 중 하나가 중지되면 총 약 66.6% 가 구동 중이기 때문에 서비스를 계속 지원하지만 2개가 중지되어 약 33.3%가 되면 남은 마스터 노드도 중지하여 서비스를 중단시킨다. 과반수 이상의 마스터 리소스가 활용가능해야 서비스를 지원한다

⇒ 하나의 마스터를 구동하는 것 처럼 활용 가능

고가용성 클러스터 구성 순서

1. Runtime Install ( All Nodes )

2. Control plane Install ( All Nodes )

3. LB Setting

4. kubeamd로 HA Cluster Setting

1. Runtime Install

CRI(Container Runtime Interface)는 컨테이너 실행을 담당하며 여러종류가 있다. Docker, containerd, CRI-O 등, 본 포스팅에서는 Docker를 사용함

Docker Install

2. Control plane Install

kubeadm을 설치 할 예정

Install kubeamd

 

Installing kubeadm

This page shows how to install the kubeadm toolbox. For information on how to create a cluster with kubeadm once you have performed this installation process, see the Creating a cluster with kubeadm page. This installation guide is for Kubernetes v1.28. If

kubernetes.io

 

swap OF, 방화벽, SELinux 해제 등 몇가지 필요한 설정이 있음

  • kubeadm: 클러스터를 부트스트랩하는 명령
  • kubelet: 클러스터의 모든 머신에서 실행되고 포드 및 컨테이너 시작과 같은 작업을 수행하는 구성 요소
  • kubectl: 클러스터와 통신하기 위한 명령줄 유틸리티

3. LB Setting

본 게시글에서는 Nginx 를 설치하여 LB를 구축했지만 AWS나 다른 CSP의 LB 서비스를 이용하는것을 추천합니다.

/etc/nginx/nginx.conf 에서 LB를 구성하는 구성파일을 생성하면 됨

LB : 172.31.46.27:6443 생성 후

#Docker 컨테이너로 Nginx를 실행하면서 LB 운영
docker run --name proxy -v /etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro --restart=always -p 6443:6443 -d nginx

 

 

4. kubeamd로 HA Cluster Setting

Master Node 중 한 곳에서 수행하며 초기화 작업부터 한 후 다른 Moster Node를 Join 시켜 구성해야 함

HA Cluster docs

 

Creating Highly Available Clusters with kubeadm

This page explains two different approaches to setting up a highly available Kubernetes cluster using kubeadm: With stacked control plane nodes. This approach requires less infrastructure. The etcd members and control plane nodes are co-located. With an ex

kubernetes.io

Master Node 1 에 init 명령으로 LB 등록 및 초기화 작업

#--control-plane-endpoint "LOAD_BALANCER_DNS:LOAD_BALANCER_PORT" => LB연동
#--upload-certs => 초기화
sudo kubeadm init --control-plane-endpoint "LOAD_BALANCER_DNS:LOAD_BALANCER_PORT" --upload-certs

실행 후 다른 Master Node 들을 Master Node 1 에 Join

#docs에 있는 출력부 예시 구문
...
You can now join any number of control-plane node by running the following command on each as a root:
    kubeadm join 192.168.0.200:6443 --token 9vr73a.a8uxyaju799qwdjv --discovery-token-ca-cert-hash sha256:7c2e69131a36ae2a042a339b33381c6d0d43887e2de83720eff5359e26aec866 
--control-plane --certificate-key f8902e114ef118304e561c3ecd4d0b543adc226b7a07f675f56564185ffe0c07

Please note that the certificate-key gives access to cluster sensitive data, keep it secret!
As a safeguard, uploaded-certs will be deleted in two hours; If necessary, you can use kubeadm init phase upload-certs to reload certs afterward.

Then you can join any number of worker nodes by running the following on each as root:
    kubeadm join 192.168.0.200:6443 --token 9vr73a.a8uxyaju799qwdjv --discovery-token-ca-cert-hash sha256:7c2e69131a36ae2a042a339b33381c6d0d43887e2de83720eff5359e26aec866

kubeamd join ~~ --control-plane ~  구문이 Master Node를 Join 하는 명령이고

아래에 있는 kubeamd join ~ 명령이 Worker Node를 Join하는 명령이다. 

이 명령들은 따로 메모하거나 파일을 생성해 보관해 두자..

 

Master Node Join

저장해 뒀던 Master Node를 Join 하는 명령을 다른 Master Node에 명령을 실행 시켜서 Join 후 동기화 하여 클러스터링 되도록 구성한다.

환경 구성이 완료되면 k get nodes 명령을 통해 채ㅜㅅ개ㅣㄷ-ㅔㅣ묻연결 된 것을 확인할 수 있다.

Master Node 2, 3 에서도 kubectl 명령을 사용하려면 아래 명령을 실행하면 된다.

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube
sudo chown $(id -u):$(id -g) $HOME/.kube/config

하지만 이때 NotReady 상태일 텐데, CNI가 설치되지 않아 아직 NotReady인 상태임

CNI Install

CNI는 여러 종류가 있으니까 맘에 드는거 골라서 설치하면 된다. 개인적으로 Weavworks 추천 (설치하기 편함)

데몬 형식으로 설치 되기 때문에 다른 노드에 자동으로 구성된다. 

Calico : https://docs.tigera.io/calico/latest/getting-started/kubernetes/quickstart

 

Quickstart for Calico on Kubernetes | Calico Documentation

Install Calico on a single-host Kubernetes cluster for testing or development in under 15 minutes.

docs.tigera.io

Weavworks : https://www.weave.works/docs/net/latest/kubernetes/kube-addon/

 

Integrating Kubernetes via the Addon

The following topics are discussed: Installation Before installing Weave Net, you should make sure the following ports are not blocked by your firewall: TCP 6783 and UDP 6783/6784. For more details, see the FAQ. Weave Net can be installed onto your CNI-ena

www.weave.works

설치 후 k get nodes 명령으로 보면 Ready 상태가 된 것을 확인 할 수 있다.

Worker Node Join

저장해뒀던 Worker Node를 Join하는 명령을 Worker Node들에서 실행하면 된다.

이후 기본 구성

  • kubectl 명령어 자동 완성 설정

docs

source <(kubectl completion bash) 
echo "source <(kubectl completion bash)" >> ~/.bashrc
  • ubuntu 사용자가 kubectl 명령 실행 가능하도록 설정 (Jump Box 에서 구성)
mkdir -p ~ubuntu/.kube
cp -i /etc/kubernetes/admin.conf ~ubuntu/.kube/config
chown -R ubuntu:ubuntu ~ubuntu/.kube

Highly Available Clusters 구성 장점

  • API를 병렬 처리하기 때문에 Single Cluster 보다 빠르다.
  • Master Node가 여러개라 Master Node에 장애가 발생해도 비교적 안정적인 운영 환경을 구축할 수 있다.

 

 

 

출처 : 따배쿠 및 교육 중 메모한 자료

'Docker & Kubenetes' 카테고리의 다른 글

Kubernetes - Static Pod  (0) 2024.01.12
Kubernetes - init container  (0) 2024.01.11
EKS - EFS CSI driver  (0) 2023.11.03
Helm Operator (Helm Controller)에 대하여  (0) 2023.10.13
쿠버네티스 Pod 배포 및 Upgrade 전략  (0) 2023.10.04