kubespray로 kubernetes 설치하기

SJH·2022년 10월 11일
0

TIL

목록 보기
4/11

ubuntu 20.04 LTS 사용
vm instance는 5개 생성
vCPU 2개, 4GB 메모리로 했는데 엄청 쾌적했다. vCPU 1~2개, 2GB 메모리로 해도 될듯?...

0. 생성한 instance들에 ssh public key 복사

1. kubespray clone

$ git clone https://github.com/kubernetes-sigs/kubespray.git
$ cd kubespray

2. kubespray 사용을 위한 python3, pip3 설치

$ sudo apt update
$ sudo apt install python3
$ python3 --version
Python 3.8.10

$ sudo apt install python3-pip
$ pip3 --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

3. 쿠버네티스가 요구하는 라이브러리가 적혀있는 requirements.txt에 있는 목록 설치

$ sudo pip3 install -r requirements.txt

4. ansible 실행을 위한 설정

  1. 샘플 파일 복사하기
$ cp -rfp inventory/sample inventory/mycluster
  1. 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]
instance-1 ansible_host=172.16.0.1 ip=172.16.0.1 etcd_member_name=etcd1
instance-2 ansible_host=172.16.0.2 ip=172.16.0.2
instance-3 ansible_host=172.16.0.3 ip=172.16.0.3

[kube_control_plane]
instance-1

[etcd]
instance-1

[kube_node]
instance-2
instance-3

[calico_rr]

[k8s_cluster:children]
kube_control_plane
kube_node
calico_rr

5. 쿠버네티스 클러스터 구성 명령 실행

$ ansible-playbook -i inventory/mycluster/inventory.ini -v --become --become-user=root cluster.yml

20분 이상 소요

6. root 계정으로 변경 후 kubernetes node 확인

~/kuberspray$ sudo -i
root@instance-1:~#

root@instance-1:~# kubectl get node
profile
일단 하자

0개의 댓글