on
Kubespray 이용하여 Kubernetes 설치
Kubespray 이용하여 Kubernetes 설치
Kubespray 는 쿠버네티스를 쉽게 설치하며 클러스터링까지 간편히 해주는 자동화 도구입니다.
자동화 도구는 Kubespray 뿐만 아니라, kubeadm 등 더 있습니다.
이번 포스팅은 Kubespray 를 이용하여 설치해줄 것이고, adm 또한 포스팅 예정이니 참고해주세요.
<아래 사진은 쿠버네티스를 공부하는데 많은 도움이 된 도서이니 참고해주시면 좋을 것 같습니다.>
실습을 하기 전에 쿠버네티스 클러스터를 자동으로 구성해주는 솔루션에 대한 간략한 설명으로 시작하겠습니다.
표는 위 도서 내용 중 p.84 를 참고하였습니다.
구분 KRIB kops kubespray kubeadm 정보량 적음 많음 많음 매우 많음 세부 설정 변경 가능함 가능함 제한적으로 가능함 다양함 사전 요구 조건 적음 적음 적음 매우 적음 온프레미스 지원 매우 좋음 안 됨 좋음 매우 좋음 클라우드 지원 안 됨 매우 좋음 좋음 좋음 학습 곡선 매우 어려움 어려움 쉬움 어려움 자동화 기능 제공됨 제공됨 쉽게 제공됨 제한적으로 제공됨
위의 네 가지 솔루션 중 가장 많이 사용되는건 kubespray, kubeadm 두 가지인 것 같습니다.
아직 솔루션들을 비교해보지 못 해서 정확하게 말씀드리긴 어렵고, 구글링을 해도 마땅한 정보는 크게 안나오네요.
추후, 모두 이용해보면서 습득하는 지식이 있으면 내용을 업데이트 해두도록 하겠습니다.
제 글에서 피드백이 필요하다면 댓글 달아주시면 너무 감사하겠습니다.
우선 제가 다니는 곳에선 kubespray 를 이용하여 설치를 진행했고 이유이자 장점을 간단히 요약하자면
1. 간단하고 빠르게 설치 진행이 가능하고, 편리하게 클러스터를 자동으로 배포할 수 있습니다.
2. 에이전트를 따로 설치하지 않고 중앙서버에서 모든 관리가 가능합니다.
3. 지원하는 app이 많아서 강력합니다.
참고로 ansible 자체가 python 기반이므로 코딩을 어느 정도 할 줄 아신다면 모듈을 만드실 수도 있고,
여러모로 더 좋은 기반이 될거라 판단됩니다.
(저는 서버, 네트워크 엔지니어라 개발과는 전혀 거리가 멀어 공부해야 합니다 ㅠㅠ..)
+ virtualbox로 환경을 구성했지만, 나중에 cluster 지웠다 만들었다 등 여러 반복작업들을 위하여
편리성을 위해 'WSL' 설치 후 진행했으니 참고하시면 좋을 것 같습니다. (필수는 아닙니다.)
설치는 Microsoft Store 에서 'Windows Terminal' 입력하여 설치해주시면 됩니다.
> 설치시 Tip : 화면 가로, 세로 분할 (Shift + Alt + ‘+’ 세로 분할, + ‘-’ 가로 분할) / Ctrl + Shift + w (탭 닫기)
++ Node를 2개로 설치할 경우, 성공할 수도 있지만 실패된다면 Split Brain 현상으로 판단됩니다.
짝수개의 노드일 경우 발생하는 것이며, 예를 들자면 다수결을 해야 하는데 짝수면 안되니까 발생한다보면 됩니다.
1. Ansible 설치
- repository 추가
# yum -y install epel-release
- ansible 패키지 설치
# yum -y install ansible
- 버전 확인
# ansible --version
2. keygen 설치 및 key copy
- keygen 설치
# ssh-keygen
> 전체 엔터해주시면 됩니다.
- key copy
: 중앙서버에서 관리 서버의 key-copy 해주면, 중앙 서버에서 관리 서버로 password 없이 접속이 가능합니다.
# ssh-copy-id -p [ssh접속 port] [admin/root]@[접속서버IP]
ex) ssh-copy-id -p 22 [email protected]
- 접속 테스트
: 제 pc는 중앙서버가 '192.168.2.10' 이며, '192.168.2.11' 로 접속 확인해보겠습니다.
# ssh [email protected]
password 없이 정상 로그인 확인
3. git, python 패키지 설치, clone
- 설치시 경로 : /root/
- git 설치
# yum -y install git
# git --version
- clone
# git clone https://github.com/kubernetes-sigs/kubespray
> github 페이지 접속하지 않고 위 명령어 복붙하셔도 상관없으나, 참고만 하시면 될 것 같습니다.
- python 설치
# yum -y install python3
# python3 --version
- 위와 같이 kubespray 설치가 완료되었으면, 생성된 디렉터리 확인해주세요.
4. pip3 기반의 필요한 lib 설치
- 아래의 requirements.txt 파일은 외부 라이브러리이며, 파이썬 패키지 등과 의존성 관련 설정 파일이므로
절대 삭제해서는 안됩니다. 이거 삭제했다가 오류나서 몇 시간 애먹다가 재설치하면서 깨달았네요....
# pip3 install -r /root/kubespray/requirements.txt
5. inventory 파일 설정
- kubespray 아래에 inventory 디렉터리와 yaml 파일들이 존재하므로, 해당 경로에서 진행하겠습니다.
# cd /root/kubespray
- cluster 해 줄 파일을 복사해옵니다.
# cp -rf inventory/sample inventory/mycluster
- inventory 파일을 설정하도록 하겠습니다.
# vi inventory/mycluster/inventory.ini
# <변경 전> # ## Configure 'ip' variable to bind kubernetes services on a # ## different ip than the default iface # ## We should set etcd_member_name for etcd cluster. The node that is not a etcd member do not need to set the value, or can set the empty string value. [all] # node1 ansible_host=95.54.0.12 # ip=10.3.0.1 etcd_member_name=etcd1 # node2 ansible_host=95.54.0.13 # ip=10.3.0.2 etcd_member_name=etcd2 # node3 ansible_host=95.54.0.14 # ip=10.3.0.3 etcd_member_name=etcd3 # node4 ansible_host=95.54.0.15 # ip=10.3.0.4 etcd_member_name=etcd4 # node5 ansible_host=95.54.0.16 # ip=10.3.0.5 etcd_member_name=etcd5 # node6 ansible_host=95.54.0.17 # ip=10.3.0.6 etcd_member_name=etcd6 # ## configure a bastion host if your nodes are not directly reachable # [bastion] # bastion ansible_host=x.x.x.x ansible_user=some_user [kube_control_plane] # node1 # node2 # node3 [etcd] # node1 # node2 # node3 [kube_node] # node2 # node3 # node4 # node5 # node6 [calico_rr] [k8s_cluster:children] kube_control_plane kube_node calico_rr
hostname ansible_host=IP ansible_port=22 etcd_member_name=etcd1
# hostname = kubespray 설치시 hostname
# ansible_host = ssh 접속 IP
# ansible_port = ssh 접속 port
kube_control_plane / etcd / kube_node -> 사용할 노드 주석 삭제
# <변경 후> # ## Configure 'ip' variable to bind kubernetes services on a # ## different ip than the default iface # ## We should set etcd_member_name for etcd cluster. The node that is not a etcd member do not need to set the value, or can set the empty string value. [all] node1 ansible_host=192.168.2.10 ansible_port=22 etcd_member_name=etcd1 node2 ansible_host=192.168.2.11 ansible_port=22 etcd_member_name=etcd2 node3 ansible_host=192.168.2.12 ansible_port=22 etcd_member_name=etcd3 # node4 ansible_host=95.54.0.15 # ip=10.3.0.4 etcd_member_name=etcd4 # node5 ansible_host=95.54.0.16 # ip=10.3.0.5 etcd_member_name=etcd5 # node6 ansible_host=95.54.0.17 # ip=10.3.0.6 etcd_member_name=etcd6 # ## configure a bastion host if your nodes are not directly reachable # [bastion] # bastion ansible_host=x.x.x.x ansible_user=some_user [kube_control_plane] node1 node2 node3 [etcd] node1 node2 node3 [kube_node] node1 node2 node3 # node4 # node5 [calico_rr] [k8s_cluster:children] kube_control_plane kube_node calico_rr
6. Kubernetes Cluster 설치
- 사전 준비는 완료되었고 이제 python 모듈 확인 후 playbook 을 이용하여 실행해주겠습니다.
- python 모듈 정상 확인
# ansible all -i inventory/mycluster/inventory.ini -m ping -v
# ansible-playbook -i inventory/mycluster/inventory.ini --become --become-user=root cluster.yml -vvv
> -i = inventory 경로
> --become --become-user=root 축약하여 -b = Become User 사용 (Default : Root)
회사 노트북으로 했을 땐 정상적으로 설치가 완료되었는데, 집에서 에러가 발생해서 해결 후 포스팅 완료하겠습니다 ㅠ..
완료되신 분들은 kubectl get node 쳐보시면 될 것 같습니다 ㅜ_ㅜ...
from http://juujuu-it.tistory.com/22 by ccl(A) rewrite - 2021-08-17 01:26:15