kubespray는 k8s 클러스터를 중앙에서 ansible을 이용해서 진행할 수 있도록 지원하는 오픈 소스 도구다. 코드를 이용해서 전체 클러스터를 컨트롤할 수 있기 때문에 규모가 큰 환경에서 사용하기 적합하다. 설정에 따라서 운영에 필요한 애드온을 자동으로 설치할 수 있고, 폐쇠망 환경에서도 설치가 가능하도록 지원한다.
VM 서버 구성
- Master Node: 3대
- Worker Node: 2대
- OS : Ubuntu 24.04 LTS
- Storage: 50GB
대표 Master 노드 설정
- hosts 파일 설정
# vim /etc/hosts
master1 10.0.0.168
master2 10.0.0.207
master3 10.0.0.53
worker1 10.0.0.149
worker2 10.0.0.245
- pem key 파일 설정 (~/.ssh/KEY_NAME.pem 경로에 배치)
chmod 600 ~/.ssh/KEY_NAME.pem
export ANSIBLE_PRIVATE_KEY_FILE=~/.ssh/ec2.pem
python & pip 설치
sudo apt update -y
sudo apt install python3-pip -y
python3 -m pip install --upgrade pip --break-system-packages --force-reinstall
kubespray 소스 코드 clone
git clone https://github.com/kubernetes-sigs/kubespray.git
cd kubespray
git checkout -b v2.26
kubespray 관련 패키지 설치
sudo pip install -r requirements.txt --break-system-packages --ignore-installed
k8s cluster 설정 샘플 파일 복사
cp -rfp inventory/sample/ inventory/cluster
클러스터 노드 정보 입력
inventory.ini 파일을 열어 클러스터에 포함될 각 노드의 정보를 입력한다.
# inventory/cluster/inventory.ini
[all]
master1 ansible_host=10.0.40.62 ip=10.0.40.62 etcd_member_name=etcd1
master2 ansible_host=10.0.41.166 ip=10.0.41.166 etcd_member_name=etcd2
master3 ansible_host=10.0.40.179 ip=10.0.40.179 etcd_member_name=etcd3
worker1 ansible_host=10.0.40.212 ip=10.0.40.212
worker2 ansible_host=10.0.41.217 ip=10.0.41.217
[kube_control_plane]
master1
master2
master3
[etcd]
master1
master2
master3
[kube_node]
worker1
worker2
[calico_crr]
[k8s_cluster:children]
kube-master
kube-node
calico-rr
k8s cluster 버전 지정
# inventory/cluster/group_vars/k8s_cluster/k8s-cluster.yml
kube_version: 1.30.4
etcd 버전 지정
# inventory/cluster/group_vars/etcd.yml
etcd_version: 3.5.12
ansible 실행
ansible-playbook 명령어를 이용해 클러스터를 설치한다. -v 옵션을 통해 디버깅을 위한 로그를 설정할 수 있고, 좀 더 자세한 로그를 보기 원할 경우 -vvv까지 설정할 수 있다.
ansible-playbook -i inventory/cluster/inventory.ini -v --become --become-user=root cluster.yml
설치 결과 확인
sudo su -
kubectl get node -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
master1 Ready control-plane 4m29s v1.30.4 10.0.0.168 <none> Ubuntu 24.04.2 LTS 6.8.0-1024-aws containerd://2.0.3
master2 Ready control-plane 4m13s v1.30.4 10.0.0.207 <none> Ubuntu 24.04.2 LTS 6.8.0-1024-aws containerd://2.0.3
master3 Ready control-plane 4m10s v1.30.4 10.0.0.53 <none> Ubuntu 24.04.2 LTS 6.8.0-1024-aws containerd://2.0.3
worker1 Ready <none> 3m27s v1.30.4 10.0.0.149 <none> Ubuntu 24.04.2 LTS 6.8.0-1024-aws containerd://2.0.3
worker2 Ready <none> 3m27s v1.30.4 10.0.0.245 <none> Ubuntu 24.04.2 LTS 6.8.0-1024-aws containerd://2.0.3
'Infrastructure & Systems > Kubernetes' 카테고리의 다른 글
[Kubernetes] Secret 이용 Private Registry 인증정보 설정 (0) | 2025.04.02 |
---|---|
[Kubernetes] StatefulSets and PersistentVolume YAML Sample (0) | 2025.03.24 |
[Kubernetes] DaemonSet YAML Sample (0) | 2025.03.24 |
[Kubernetes] Deployments YAML Sample (0) | 2025.03.24 |
[Kubernetes] Multi-Cluster 환경에서 kubectl (0) | 2024.11.29 |