하드웨어 준비 사항
virt-manager로 아래와 같은 시스템 5개를 만든다.
- ubuntu22.04-71 / ubuntu 22.04 LTS / 192.168.122.71 / ssh 키 등록 / control plan
- ubuntu22.04-72 / ubuntu 22.04 LTS / 192.168.122.72 / ssh 키 등록 / node1
- ubuntu22.04-73 / ubuntu 22.04 LTS / 192.168.122.73 / ssh 키 등록 / node2
- ubuntu22.04-74 / ubuntu 22.04 LTS / 192.168.122.74 / ssh 키 등록 / node3
- ubuntu22.04-75 / ubuntu 22.04 LTS / 192.168.122.75 / ssh 키 등록 / node4
Kubespray 다운로드
https://github.com/kubernetes-sigs/kubespray/releases
release에서 최신 버전을 다운받는다.
2024/11/11일 v2.25.1이 최신 버전으로 kubernetes v1.29.10이 default로 설치된다.
# wget https://github.com/kubernetes-sigs/kubespray/archive/refs/tags/v2.25.1.tar.gz
# tar xvzf v2.25.1.tar.gz
# cd kubespray-2.25.1
Kubespray 배포 환경 구성
Python으로 배포할 패키지 환경이 "requirements.txt"에 설정되어 있다. 이를 통해서 관련 모듈을 설치한다.
# pip install -r requirements.txt
ansible이 올바로 설치되어 있는지 아래와 같이 확인해본다.
# ansible --version
ansible [core 2.16.13]
config file = /root/kubespray-2.25.1/ansible.cfg
configured module search path = ['/root/kubespray-2.25.1/library']
ansible python module location = /root/kubespray-2.25.1/lib/python3.10/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /root/kubespray-2.25.1/bin/ansible
python version = 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] (/root/kubespray-2.25.1/bin/python3)
jinja version = 3.1.4
libyaml = True
kubespray 배포용 inventory 구성
보통 가이드나 블로그를 보면 inventory/sample를 복사해서 적절하게 구성하는 경우가 많은데, 심플하게 비어 있는 구성으로 진행해본다.
# mkdir inventory/encicle-cluster
# touch inventory/encicle-cluster/inventory.ini
# touch inventory/encicle-cluster/vars.yaml
inventory.ini
파일 구성 - 위에 설정된 하드웨어 구성을 정리해서 입력한다.
[all]
control-plane ansible_host=192.168.122.71
node1 ansible_host=192.168.122.72
node2 ansible_host=192.168.122.73
node3 ansible_host=192.168.122.74
node4 ansible_host=192.168.122.75
[kube_control_plane]
control-plane
[etcd]
control-plane
[kube_node]
node1
node2
node3
node4
[calico_rr]
[k8s_cluster:children]
kube_control_plane
kube_node
calico_rr
vars.yaml
구성
설치될 kubenetes에 대한 세부 설정을 정의하는 파일로 최대한 vanila kubernetes 구성에 맞게 2가지 구성 요소를 설치하지 않도록 정의했다.
필요에 따라 설정을 변경하면 된다.
- kubespray는 dns 효율을 높이이 위해서 nodelocaldns를 기본으로 설치하나 아래와 같이 설정해서 설치하지 않는다.
- kubespray는 api proxy를 nginx-proxy를 설치하는데, 이 또한 설정하지 않도록 구성한다.
운영 환경 상이라면 2가지 옵션이 유효할 수 있다. 그러나 스터디용으로 구성한 환경이라 최대한 바닐라 kubernetes에 맞도록 구성하기 위해서
2가지 모듈을 설치하지 않도록 구성
---
# not install nodelocaldns
enable_nodelocaldns: false
# not install nginx-proxy for api proxy
loadbalancer_apiserver_localhost: false
kubespray로 kubernetes 구성
아래와 같은 명령어를 사용해서 kubernernetes를 구성한다.
# ansible-playbook cluster.yml \
-i inventory/encicle-cluster/inventory.ini \
-e "@inventory/encicle-cluster/vars.yaml" \
-b --become-user=root
아래와 같이 failed가 없다면 정상적으로 설치된 것이다.
PLAY RECAP ****************************************************************************************************************************
control-plane : ok=613 changed=135 unreachable=0 failed=0 skipped=1107 rescued=0 ignored=6
node1 : ok=376 changed=78 unreachable=0 failed=0 skipped=660 rescued=0 ignored=1
node2 : ok=376 changed=78 unreachable=0 failed=0 skipped=657 rescued=0 ignored=1
node3 : ok=376 changed=78 unreachable=0 failed=0 skipped=657 rescued=0 ignored=1
node4 : ok=376 changed=78 unreachable=0 failed=0 skipped=657 rescued=0 ignored=1
Monday 11 November 2024 10:46:04 +0900 (0:00:00.072) 0:07:25.623 *******
===============================================================================
kubernetes/control-plane : Kubeadm | Initialize first master ------------------------------------------------------------------ 27.80s
kubernetes/kubeadm : Join to cluster ------------------------------------------------------------------------------------------ 20.77s
download : Download_container | Download image if required -------------------------------------------------------------------- 17.22s
download : Download_container | Download image if required -------------------------------------------------------------------- 14.21s
download : Download_container | Download image if required -------------------------------------------------------------------- 11.31s
download : Download_file | Download item -------------------------------------------------------------------------------------- 10.69s
download : Download_container | Download image if required -------------------------------------------------------------------- 10.45s
download : Download_container | Download image if required --------------------------------------------------------------------- 9.97s
kubernetes/preinstall : Install packages requirements -------------------------------------------------------------------------- 9.72s
etcd : Reload etcd ------------------------------------------------------------------------------------------------------------- 8.90s
container-engine/containerd : Download_file | Download item -------------------------------------------------------------------- 8.48s
download : Download_file | Download item --------------------------------------------------------------------------------------- 6.99s
container-engine/crictl : Download_file | Download item ------------------------------------------------------------------------ 6.40s
container-engine/nerdctl : Download_file | Download item ----------------------------------------------------------------------- 5.51s
container-engine/runc : Download_file | Download item -------------------------------------------------------------------------- 5.36s
download : Download_file | Download item --------------------------------------------------------------------------------------- 5.30s
etcd : Configure | Check if etcd cluster is healthy ---------------------------------------------------------------------------- 5.17s
download : Download_file | Download item --------------------------------------------------------------------------------------- 5.04s
download : Download_file | Download item --------------------------------------------------------------------------------------- 4.33s
download : Download_container | Download image if required --------------------------------------------------------------------- 4.29s
kubernetes 구축 확인
kubectl에 사용하는 config 파일은 control-plane인 "192.168.122.71" 서버의 "/root/.kube/config"에 저정되어 있다.
kubectl를 통해서 구성된 시스템 정보를 확인하여 정상적으로 구성되었는지 확인해본다.
# kubectl get node -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
control-plane Ready control-plane 6m2s v1.29.10 192.168.122.71 <none> Ubuntu 22.04.5 LTS 5.15.0-124-generic containerd://1.7.22
node1 Ready <none> 5m27s v1.29.10 192.168.122.72 <none> Ubuntu 22.04.5 LTS 5.15.0-124-generic containerd://1.7.22
node2 Ready <none> 5m28s v1.29.10 192.168.122.73 <none> Ubuntu 22.04.5 LTS 5.15.0-124-generic containerd://1.7.22
node3 Ready <none> 5m29s v1.29.10 192.168.122.74 <none> Ubuntu 22.04.5 LTS 5.15.0-124-generic containerd://1.7.22
node4 Ready <none> 5m29s v1.29.10 192.168.122.75 <none> Ubuntu 22.04.5 LTS 5.15.0-124-generic containerd://1.7.22